@Test public void testNoArgConstructor() { Object obj = ConstructHelper.construct(NoArgConstructorClass.class, new FixtureMap(), fixtureConverter); assertTrue(obj instanceof NoArgConstructorClass); }
@SuppressWarnings("unchecked") public static Object construct(Class<?> type, FixtureMap fixtureMap, FixtureConverter fixtureConverter) { final Constructor<?>[] constructs = type.getConstructors(); if (constructs.length == 0) throw new UnsupportedOperationException("can not create an instance. " + type + " does not have a constructor."); Object newInstance = null; if (fixtureMap.containsKey(CONSTRUCT_KEY)) { FixtureTemplate constructorFixture = fixtureMap.get(CONSTRUCT_KEY); if (constructorFixture instanceof FixtureValue) { newInstance = constructByFixtureValue(type, (FixtureValue) constructorFixture, fixtureConverter); } else if (constructorFixture instanceof FixtureList) { newInstance = constructByFixtureList(type, (FixtureList) constructorFixture, fixtureConverter); } } if (newInstance == null) { try { newInstance = type.newInstance(); } catch (Exception e) { throw new FixtureMappingException(type, fixtureMap, e); } } return newInstance; }
ConstructHelper { @SuppressWarnings("unchecked") public static Object construct(Class<?> type, FixtureMap fixtureMap, FixtureConverter fixtureConverter) { final Constructor<?>[] constructs = type.getConstructors(); if (constructs.length == 0) throw new UnsupportedOperationException("can not create an instance. " + type + " does not have a constructor."); Object newInstance = null; if (fixtureMap.containsKey(CONSTRUCT_KEY)) { FixtureTemplate constructorFixture = fixtureMap.get(CONSTRUCT_KEY); if (constructorFixture instanceof FixtureValue) { newInstance = constructByFixtureValue(type, (FixtureValue) constructorFixture, fixtureConverter); } else if (constructorFixture instanceof FixtureList) { newInstance = constructByFixtureList(type, (FixtureList) constructorFixture, fixtureConverter); } } if (newInstance == null) { try { newInstance = type.newInstance(); } catch (Exception e) { throw new FixtureMappingException(type, fixtureMap, e); } } return newInstance; } }
ConstructHelper { @SuppressWarnings("unchecked") public static Object construct(Class<?> type, FixtureMap fixtureMap, FixtureConverter fixtureConverter) { final Constructor<?>[] constructs = type.getConstructors(); if (constructs.length == 0) throw new UnsupportedOperationException("can not create an instance. " + type + " does not have a constructor."); Object newInstance = null; if (fixtureMap.containsKey(CONSTRUCT_KEY)) { FixtureTemplate constructorFixture = fixtureMap.get(CONSTRUCT_KEY); if (constructorFixture instanceof FixtureValue) { newInstance = constructByFixtureValue(type, (FixtureValue) constructorFixture, fixtureConverter); } else if (constructorFixture instanceof FixtureList) { newInstance = constructByFixtureList(type, (FixtureList) constructorFixture, fixtureConverter); } } if (newInstance == null) { try { newInstance = type.newInstance(); } catch (Exception e) { throw new FixtureMappingException(type, fixtureMap, e); } } return newInstance; }  }
ConstructHelper { @SuppressWarnings("unchecked") public static Object construct(Class<?> type, FixtureMap fixtureMap, FixtureConverter fixtureConverter) { final Constructor<?>[] constructs = type.getConstructors(); if (constructs.length == 0) throw new UnsupportedOperationException("can not create an instance. " + type + " does not have a constructor."); Object newInstance = null; if (fixtureMap.containsKey(CONSTRUCT_KEY)) { FixtureTemplate constructorFixture = fixtureMap.get(CONSTRUCT_KEY); if (constructorFixture instanceof FixtureValue) { newInstance = constructByFixtureValue(type, (FixtureValue) constructorFixture, fixtureConverter); } else if (constructorFixture instanceof FixtureList) { newInstance = constructByFixtureList(type, (FixtureList) constructorFixture, fixtureConverter); } } if (newInstance == null) { try { newInstance = type.newInstance(); } catch (Exception e) { throw new FixtureMappingException(type, fixtureMap, e); } } return newInstance; }  @SuppressWarnings("unchecked") static Object construct(Class<?> type, FixtureMap fixtureMap, FixtureConverter fixtureConverter); }
ConstructHelper { @SuppressWarnings("unchecked") public static Object construct(Class<?> type, FixtureMap fixtureMap, FixtureConverter fixtureConverter) { final Constructor<?>[] constructs = type.getConstructors(); if (constructs.length == 0) throw new UnsupportedOperationException("can not create an instance. " + type + " does not have a constructor."); Object newInstance = null; if (fixtureMap.containsKey(CONSTRUCT_KEY)) { FixtureTemplate constructorFixture = fixtureMap.get(CONSTRUCT_KEY); if (constructorFixture instanceof FixtureValue) { newInstance = constructByFixtureValue(type, (FixtureValue) constructorFixture, fixtureConverter); } else if (constructorFixture instanceof FixtureList) { newInstance = constructByFixtureList(type, (FixtureList) constructorFixture, fixtureConverter); } } if (newInstance == null) { try { newInstance = type.newInstance(); } catch (Exception e) { throw new FixtureMappingException(type, fixtureMap, e); } } return newInstance; }  @SuppressWarnings("unchecked") static Object construct(Class<?> type, FixtureMap fixtureMap, FixtureConverter fixtureConverter);  }