### Question:
DefaultObjectFactory implements ObjectFactory, Serializable { @Override public <T> T create(Class<T> type) { return create(type, null, null); }  @Override T create(Class<T> type); @SuppressWarnings("unchecked") @Override T create(Class<T> type, List<Class<?>> constructorArgTypes, List<Object> constructorArgs); @Override boolean isCollection(Class<T> type);  }### Answer:
@Test void createClass() { DefaultObjectFactory defaultObjectFactory = new DefaultObjectFactory(); TestClass testClass = defaultObjectFactory.create(TestClass.class, Arrays.asList(String.class, Integer.class), Arrays.asList("foo", 0)); Assertions.assertEquals((Integer) 0, testClass.myInteger, "myInteger didn't match expected"); Assertions.assertEquals("foo", testClass.myString, "myString didn't match expected"); }
@Test void createClassThrowsProperErrorMsg() { DefaultObjectFactory defaultObjectFactory = new DefaultObjectFactory(); try { defaultObjectFactory.create(TestClass.class, Collections.singletonList(String.class), Collections.singletonList("foo")); Assertions.fail("Should have thrown ReflectionException"); } catch (Exception e) { Assertions.assertTrue(e instanceof ReflectionException, "Should be ReflectionException"); Assertions.assertTrue(e.getMessage().contains("(String)"), "Should not have trailing commas in types list"); Assertions.assertTrue(e.getMessage().contains("(foo)"), "Should not have trailing commas in values list"); } }
@Test void creatHashMap() { DefaultObjectFactory defaultObjectFactory = new DefaultObjectFactory(); Map map = defaultObjectFactory.create(Map.class, null, null); Assertions.assertTrue(map instanceof HashMap, "Should be HashMap"); }
@Test void createArrayList() { DefaultObjectFactory defaultObjectFactory = new DefaultObjectFactory(); List list = defaultObjectFactory.create(List.class); Assertions.assertTrue(list instanceof ArrayList, " list should be ArrayList"); Collection collection = defaultObjectFactory.create(Collection.class); Assertions.assertTrue(collection instanceof ArrayList, " collection should be ArrayList"); Iterable iterable = defaultObjectFactory.create(Iterable.class); Assertions.assertTrue(iterable instanceof ArrayList, " iterable should be ArrayList"); }
@Test void createTreeSet() { DefaultObjectFactory defaultObjectFactory = new DefaultObjectFactory(); SortedSet sortedSet = defaultObjectFactory.create(SortedSet.class); Assertions.assertTrue(sortedSet instanceof TreeSet, " sortedSet should be TreeSet"); }
@Test void createHashSet() { DefaultObjectFactory defaultObjectFactory = new DefaultObjectFactory(); Set set = defaultObjectFactory.create(Set.class); Assertions.assertTrue(set instanceof HashSet, " set should be HashSet"); }