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);  }
@Test public void testNoArgConstructor() { Object obj = ConstructHelper.construct(NoArgConstructorClass.class, new FixtureMap(), fixtureConverter); assertTrue(obj instanceof NoArgConstructorClass); }
@Test public void testSingleArgConstructor() { FixtureMap fixtureMap = store.reproduce("single-arg-constructor"); Object obj = ConstructHelper.construct(SingleArgsConstuctorClass.class, fixtureMap, fixtureConverter); assertTrue(obj instanceof SingleArgsConstuctorClass); }
@Test public void testMultipleArgsConstructor() { FixtureMap fixtureMap = store.reproduce("multiple-args-constructor"); Object obj = ConstructHelper.construct(MultipleArgConstructorClass.class, fixtureMap, fixtureConverter); assertTrue(obj instanceof MultipleArgConstructorClass); }
@Test public void testBeanArgConstructor() { FixtureMap fixtureMap = store.reproduce("bean-constructor"); Object obj = ConstructHelper.construct(BeanArgConstructorClass.class, fixtureMap, fixtureConverter); assertTrue(obj instanceof BeanArgConstructorClass); }