NewInstanceObjectFinder implements ObjectFinder { @Override public <T> T getObject(Class<T> domainClass, Object to, String... tags) throws JTransfoException { try { if (Arrays.stream(tags).noneMatch(JTransfo.TAG_WHEN_READ_ONLY_DOMAIN::equals)) { return reflectionHelper.newInstance(domainClass); } else { return null; } } catch (InstantiationException | IllegalAccessException ie) { throw new JTransfoException("Cannot create instance for domain class " + domainClass.getName() + ".", ie); } }  @Override T getObject(Class<T> domainClass, Object to, String... tags);  }
@Test public void testInstantiationException() throws Exception { when(reflectionHelper.newInstance(SimpleClassDomain.class)).thenThrow(new InstantiationException()); exception.expect(JTransfoException.class); exception.expectMessage("Cannot create instance for domain class org.jtransfo.object.SimpleClassDomain."); newInstanceObjectFinder.getObject(SimpleClassDomain.class, new SimpleClassNameTo()); }
@Test public void testIllegalAccessException() throws Exception { when(reflectionHelper.newInstance(SimpleClassDomain.class)).thenThrow(new IllegalAccessException()); exception.expect(JTransfoException.class); exception.expectMessage("Cannot create instance for domain class org.jtransfo.object.SimpleClassDomain."); newInstanceObjectFinder.getObject(SimpleClassDomain.class, new SimpleClassNameTo()); }