private void determineInspectors(Class<?> clazz) { if (!TestUsageChecker.canUse(clazz)) { inspectors.put(clazz, Collections.emptyList()); } if (!TestUsageChecker.canUse(clazz)) return; List<Inspector> inspectorList = new ArrayList<Inspector>(); for (Method method : clazz.getMethods()) { if (isInspectorMethod(method)) { // FIXXME logger.debug("Inspector for class " + clazz.getSimpleName() + ": " + method.getName() + " defined in " + method.getDeclaringClass().getCanonicalName()); inspectorList.add(new Inspector(clazz, method)); } else { logger.debug("Not an inspector: "+method.getName()); } } inspectors.put(clazz, inspectorList); }
@Test public void testLoaderOfEnumsAreChanged() throws NoSuchMethodException, SecurityException { InspectorAssertion assertion = new InspectorAssertion(); assertion.inspector = new Inspector(ExampleEnum.class, ExampleEnum.class.getMethod("testMe", new Class<?>[] {})); assertion.value = ExampleEnum.VALUE1; Assert.assertEquals(ExampleEnum.VALUE1, assertion.value); ClassLoader loader = TestGenerationContext.getInstance().getClassLoaderForSUT(); assertion.changeClassLoader(loader); Assert.assertNotEquals(ExampleEnum.VALUE1, assertion.value); } }
@Test public void testDownCastNecessaryForInspectorAssertion() throws NoSuchMethodException { TestCaseBuilder builder = new TestCaseBuilder(); VariableReference var = builder.appendConstructor(DowncastExample.class.getConstructor()); VariableReference num0 = builder.appendMethod(var, DowncastExample.class.getMethod("getAbstractFoo")); num0.setType(ConcreteSubclass.class); // This would be set during execution DefaultTestCase test = builder.getDefaultTestCase(); Inspector inspector = new Inspector(ConcreteSubclass.class, ConcreteSubclass.class.getMethod("getBar")); InspectorAssertion assertion = new InspectorAssertion(inspector, test.getStatement(num0.getStPosition()), num0, true); test.getStatement(num0.getStPosition()).addAssertion(assertion); test.removeDownCasts(); System.out.println(test); assertEquals(ConcreteSubclass.class, test.getStatement(1).getReturnClass()); }
@Test public void testDownCastUnnecessaryForInspectorAssertion() throws NoSuchMethodException { TestCaseBuilder builder = new TestCaseBuilder(); VariableReference var = builder.appendConstructor(DowncastExample.class.getConstructor()); VariableReference num0 = builder.appendMethod(var, DowncastExample.class.getMethod("getAbstractFoo")); num0.setType(ConcreteSubclass.class); // This would be set during execution DefaultTestCase test = builder.getDefaultTestCase(); Inspector inspector = new Inspector(ConcreteSubclass.class, ConcreteSubclass.class.getMethod("getFoo")); InspectorAssertion assertion = new InspectorAssertion(inspector, test.getStatement(num0.getStPosition()), num0, true); test.getStatement(num0.getStPosition()).addAssertion(assertion); test.removeDownCasts(); System.out.println(test); assertEquals(AbstractSuperclass.class, test.getStatement(1).getReturnClass()); }
test.addStatement(ms2); Inspector inspector = new Inspector(targetClass, inspectorMethod); Assertion assertion = new InspectorAssertion(inspector, ms2, ms1.getReturnValue(), 0);