public static String getMethodIdentifier(ExecutionResult result, int exceptionPosition){ if (result.test.getStatement(exceptionPosition) instanceof MethodStatement) { MethodStatement ms = (MethodStatement) result.test.getStatement(exceptionPosition); Method method = ms.getMethod().getMethod(); return method.getName() + Type.getMethodDescriptor(method); } else if (result.test.getStatement(exceptionPosition) instanceof ConstructorStatement) { ConstructorStatement cs = (ConstructorStatement) result.test.getStatement(exceptionPosition); Constructor<?> constructor = cs.getConstructor().getConstructor(); return "<init>" + Type.getConstructorDescriptor(constructor); } return ""; }
public static boolean isDeclared(ExecutionResult result, int exceptionPosition){ Throwable t = result.getExceptionThrownAtPosition(exceptionPosition); // Check if thrown exception is declared, or subclass of a declared exception for(Class<?> declaredExceptionClass : result.test.getStatement(exceptionPosition).getDeclaredExceptions()) { if(declaredExceptionClass.isAssignableFrom(t.getClass())) { return true; } } return false; }
/** * {@inheritDoc} * * Create a copy of the current variable */ @Override public VariableReference clone(TestCase newTestCase) { return newTestCase.getStatement(getStPosition()).getReturnValue(); }
public void inferTypes(TestCase test) { this.test = test; logger.debug("Inferring generic types"); // calculateExactTypes(); for (int i = test.size() - 1; i >= 0; i--) { Statement statement = test.getStatement(i); if (statement instanceof ConstructorStatement) { determineExactType((ConstructorStatement) statement); } } logger.debug("Resulting test: "+test.toCode()); }
/** {@inheritDoc} */ @Override public VariableReference copy(TestCase newTestCase, int offset) { return newTestCase.getStatement(getStPosition() + offset).getReturnValue(); }
/** {@inheritDoc} */ @Override public VariableReference copy(TestCase newTest, int offset) { return newTest.getStatement(getStPosition() + offset).getReturnValue(); }
private void addUnchangedMapping(TestCase test, VariableReference var) { VariableReference copy = test.getStatement(var.getStPosition()).getReturnValue(); if (!variableMapping.containsKey(var.getStPosition())) { variableMapping.put(var.getStPosition(), new HashSet<VariableReference>()); variableMapping.get(var.getStPosition()).add(var); } variableMapping.get(var.getStPosition()).add(copy); }
public void changeClassLoader(ClassLoader classLoader) { ((DefaultTestCase) test).changeClassLoader(classLoader); contract.changeClassLoader(classLoader); this.statement = this.test.getStatement(statement.getPosition()); for (int i = 0; i < variables.size(); i++) { variables.set(i, variables.get(i).clone(test)); } }
/** {@inheritDoc} */ @Override public Assertion copy(TestCase newTestCase, int offset) { PrimitiveFieldAssertion s = new PrimitiveFieldAssertion(); s.source = newTestCase.getStatement(source.getStPosition() + offset).getReturnValue(); s.value = value; s.field = field; s.comment = comment; s.killedMutants.addAll(killedMutants); return s; }
@Override public VariableReference clone(TestCase newTestCase) { Statement st = newTestCase.getStatement(getStPosition()); for(VariableReference var : st.getVariableReferences()) { if(same(var)) { return var; } } throw new IllegalArgumentException("Constant value not defined in new test"); }
/** {@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; }
private VariableReference duplicateStatement(TestCase test, VariableReference owner) { Statement statement = test.getStatement(owner.getStPosition()); currentPosition++; VariableReference copy = test.addStatement(statement.clone(test), owner.getStPosition() + 1); if (!variableMapping.containsKey(owner.getStPosition())) { variableMapping.put(owner.getStPosition(), new HashSet<VariableReference>()); // variableMapping.get(owner.getStPosition()).add(owner); } variableMapping.get(owner.getStPosition()).add(copy); return copy; }
public TestMutationHistoryEntry clone(TestCase newTest) { if (statement == null) return new TestMutationHistoryEntry(mutationType); return new TestMutationHistoryEntry(mutationType, newTest.getStatement(statement.getPosition())); }
/** {@inheritDoc} */ @Override public Assertion copy(TestCase newTestCase, int offset) { NullAssertion s = new NullAssertion(); s.source = newTestCase.getStatement(source.getStPosition() + offset).getReturnValue(); s.value = value; s.comment = comment; s.killedMutants.addAll(killedMutants); assert (s.isValid()); return s; }
/** {@inheritDoc} */ @Override public Statement copy(TestCase newTestCase, int offset) { VariableReference newRetVal = new VariableReferenceImpl(newTestCase, retval.getType()); VariableReference newLeftOperand = newTestCase.getStatement(leftOperand.getStPosition()).getReturnValue(); VariableReference newRightOperand = newTestCase.getStatement(rightOperand.getStPosition()).getReturnValue(); return new PrimitiveExpression(newTestCase, newRetVal, newLeftOperand, operator, newRightOperand); // return new PrimitiveExpression(newTestCase, retval, leftOperand, operator, rightOperand); }
private String getMethodName(TestCase test, int position) { Statement statement = test.getStatement(position); if(statement instanceof MethodStatement) { return ((MethodStatement)statement).getMethod().getName(); } else if(statement instanceof ConstructorStatement) { return ((ConstructorStatement)statement).getConstructor().getName(); } else { return ""; } }
private void removeAssertionsAfterException(List<ExecutionResult> results) { for(ExecutionResult result : results) { if(result.noThrownExceptions()) continue; int exceptionPosition = result.getFirstPositionOfThrownException(); // TODO: Not clear how that can happen... if(result.test.size() > exceptionPosition) result.test.getStatement(exceptionPosition).removeAssertions(); } }
private static boolean testStatementCommentNotContains(RegressionTestChromosome test, int statementPos, String compareComment) { return (test.getTheTest().getTestCase().hasStatement(statementPos) && !test.getTheTest().getTestCase().getStatement(statementPos) .getComment().contains(compareComment)); }
/** {@inheritDoc} */ @Override public void addAssertions(TestCase other) { for (int i = 0; i < statements.size() && i < other.size(); i++) { for (Assertion a : other.getStatement(i).getAssertions()) { if (!statements.get(i).getAssertions().contains(a)) if (a != null) statements.get(i).getAssertions().add(a.clone(this)); } } }
/** {@inheritDoc} */ @Override public boolean isPrefix(TestCase t) { if (statements.size() > t.size()) return false; for (int i = 0; i < statements.size(); i++) { if (!statements.get(i).same(t.getStatement(i))) { return false; } } return true; }