addFieldAssignment(test, (GenericField) call, position, 0); } else { addFieldFor(test, callee, (GenericField) call.copyWithNewOwner(callee.getGenericClass()),
@Test(expected=ConstructionFailedException.class) public void testFieldForWrongPosition() throws ConstructionFailedException, NoSuchMethodException, SecurityException, ClassNotFoundException, NoSuchFieldException { TestFactory testFactory = TestFactory.getInstance(); Class<?> sut = TestGenerationContext.getInstance().getClassLoaderForSUT().loadClass(FactoryExample.class.getCanonicalName()); GenericConstructor constructor = new GenericConstructor(sut.getConstructor(), sut); GenericField field = new GenericField(sut.getField("setMe"), sut); DefaultTestCase test = new DefaultTestCase(); Properties.PRIMITIVE_REUSE_PROBABILITY = 0.0; Properties.OBJECT_REUSE_PROBABILITY = 0.0; VariableReference var1 = testFactory.addConstructor(test, constructor, 0, 0); testFactory.reset(); testFactory.addFieldFor(test, var1, field, 0); }
@Test public void testFieldFor() throws ConstructionFailedException, NoSuchMethodException, SecurityException, ClassNotFoundException, NoSuchFieldException { TestFactory testFactory = TestFactory.getInstance(); Class<?> sut = TestGenerationContext.getInstance().getClassLoaderForSUT().loadClass(FactoryExample.class.getCanonicalName()); GenericConstructor constructor = new GenericConstructor(sut.getConstructor(), sut); GenericField field = new GenericField(sut.getField("setMe"), sut); DefaultTestCase test = new DefaultTestCase(); Properties.PRIMITIVE_REUSE_PROBABILITY = 0.0; Properties.OBJECT_REUSE_PROBABILITY = 0.0; VariableReference var1 = testFactory.addConstructor(test, constructor, 0, 0); testFactory.reset(); VariableReference var2 = testFactory.addConstructor(test, constructor, 1, 0); testFactory.addFieldFor(test, var1, field, 2); testFactory.reset(); testFactory.addFieldFor(test, var2, field, 3); String code = test.toCode(); System.out.println(code); assertEquals(6, test.size()); assertTrue(code.contains("factoryExample0.setMe")); // byte2 is the first return value assertTrue(code.contains("factoryExample1.setMe")); }