public <T> boolean setOrUnSet(Class<T> type, String key, Object value, Object defaultValue) { if (key == null || key.isEmpty()) { throw new IllegalArgumentException("key can be neither null nor empty!"); } if (value == null) { value = defaultValue; } if (value == null) { setInternal(key, value); } else { setInternal(key, parse(type, value)); } return true; }
newValue.add((T) parse(type, item));
@Test(expected = IllegalArgumentException.class) public void testParseForListFails() { optRepo.parse(Set.class, new HashSet<String>()); Assert.fail(); }
@Test(expected = IllegalArgumentException.class) public void testParseForCollectionFails() { optRepo.parse(Set.class, new HashSet<String>()); Assert.fail(); }
@Test(expected = IllegalArgumentException.class) public void testParseForSetFails() { optRepo.parse(Set.class, new HashSet<String>()); Assert.fail(); }
@Test public void testParse() { Assert.assertEquals("", optRepo.parse(String.class, "")); Assert.assertEquals(100, optRepo.parse(Integer.class, 100)); Assert.assertEquals(100L, optRepo.parse(Long.class, 100L)); Assert.assertEquals(true, optRepo.parse(Boolean.class, "true")); Assert.assertTrue(optRepo.parse(MessageFormattingStrategy.class, SingleLineFormat.class.getName()) instanceof MessageFormattingStrategy); Assert.assertTrue(optRepo.parse(MessageFormattingStrategy.class, MultiLineFormat.class.getName()) instanceof MessageFormattingStrategy); Assert.assertTrue(optRepo.parse(MessageFormattingStrategy.class, CustomLineFormat.class.getName()) instanceof MessageFormattingStrategy); Assert.assertTrue(optRepo.parse(Pattern.class, "somepattern") instanceof Pattern); // existing categories work Assert.assertTrue(optRepo.parse(Category.class, "info") instanceof Category); // new categories can be added without restriction Assert.assertTrue(optRepo.parse(Category.class, "new_category") instanceof Category); }
public <T> boolean setOrUnSet(Class<T> type, String key, Object value, Object defaultValue) { if (key == null || key.isEmpty()) { throw new IllegalArgumentException("key can be neither null nor empty!"); } if (value == null) { value = defaultValue; } if (value == null) { setInternal(key, value); } else { setInternal(key, parse(type, value)); } return true; }
newValue.add((T) parse(type, item));