@Before public void setUp() throws Exception { init = new ConstantInitializer<>(VALUE); }
/** * Tests equals() if the expected result is true. */ @Test public void testEqualsTrue() { checkEquals(init, true); ConstantInitializer<Integer> init2 = new ConstantInitializer<>( Integer.valueOf(VALUE.intValue())); checkEquals(init2, true); init = new ConstantInitializer<>(null); init2 = new ConstantInitializer<>(null); checkEquals(init2, true); }
/** * Tests equals() if the expected result is false. */ @Test public void testEqualsFalse() { ConstantInitializer<Integer> init2 = new ConstantInitializer<>( null); checkEquals(init2, false); init2 = new ConstantInitializer<>(VALUE + 1); checkEquals(init2, false); }
/** * Tests the string representation if the managed object is null. */ @Test public void testToStringNull() { final String s = new ConstantInitializer<>(null).toString(); assertTrue("Object not found: " + s, s.indexOf("object = null") > 0); } }
/** * Tests createIfAbsentUnchecked() if no exception is thrown. */ @Test public void testCreateIfAbsentUncheckedSuccess() { final String key = "testKey"; final Integer value = 42; final ConcurrentMap<String, Integer> map = new ConcurrentHashMap<>(); assertEquals("Wrong result", value, ConcurrentUtils.createIfAbsentUnchecked(map, key, new ConstantInitializer<>(value))); assertEquals("Wrong value in map", value, map.get(key)); }
/** * Tests equals() with objects of other classes. */ @Test public void testEqualsWithOtherObjects() { checkEquals(null, false); checkEquals(this, false); checkEquals(new ConstantInitializer<>("Test"), false); }