public class MyProperties {
private Map<String, Object> properties = new HashMap<String, Object>();
public void setProperty(String name, Object value) {
properties.put(name, value);
}
@SuppressWarnings("unchecked")
public <T> T getProperty(String name) {
return (T) properties.get(name);
}
}
@Test
public void test() {
MyProperties props1 = new MyProperties();
props1.setProperty("name", "John Smith");
MyProperties props2 = new MyProperties();
props2.setProperty("name", "John Smith");
assertEquals(props2.getProperty("name"), props1.getProperty("name"));
}
The above unit tests passes on my machine but fails in our jenkins environment with the following error:
java.lang.String cannot be cast to [Ljava.lang.Object;
The unit test passes on my machine when run via Eclipse and ant (eclipse 4.4 luna, ant 1.9.6, jdk_8_u60, Windows 7 64bit) but fails in our jenkins environment (ant 1.9.6 jdk_8_u60, Ubuntu 12.04.4). It's also failing in several other environments, and working in several other -- with no apparent rhyme or reason.
So I have two questions:
1)Why is Java choosing the overload
org.junit.Assert.assertEquals(Object[],Object[])
instead oforg.junit.Assert.assertEquals(String,String)
ororg.junit.Assert.assertEquals(Object,Object)
?2) and why is the unit test passing in some environments, and failing in others with the same versions of java, ant, and junit?