/** * {@inheritDoc} */ @Override public Set<Assertion> getAssertions() { Set<Assertion> assertions = new HashSet<Assertion>(); for (Inspector inspector : inspectorMap.keySet()) { InspectorAssertion assertion = new InspectorAssertion(); assertion.value = inspectorMap.get(inspector); assertion.inspector = inspector; assertion.source = var; assertions.add(assertion); assert (assertion.isValid()); } return assertions; }
/** {@inheritDoc} */ @Override public Assertion copy(TestCase newTestCase, int offset) { InspectorAssertion s = new InspectorAssertion(); s.source = newTestCase.getStatement(source.getStPosition() + offset).getReturnValue(); s.inspector = inspector; s.value = value; s.comment = comment; s.killedMutants.addAll(killedMutants); return s; }
continue; InspectorAssertion assertion = new InspectorAssertion(); assertion.value = inspectorMap.get(methodInspectorMap.get(inspector)); assertion.inspector = methodInspectorMap.get(inspector);
@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 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 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()); }
Assertion assertion = new InspectorAssertion(inspector, ms2, ms1.getReturnValue(), 0); ms2.addAssertion(assertion);