@Override public CtInvocation<?> buildInvocationToAssertion(CtMethod<?> testMethod, AssertEnum assertion, List<CtExpression> arguments) { final Factory factory = InputConfiguration.get().getFactory(); //assertThat(actual) final CtInvocation<?> assertThat = createAssertThat(arguments.get(arguments.size() - 1)); //isXXX(expected) final CtInvocation invocation = factory.createInvocation(); final CtExecutableReference<?> executableReference = factory.Core().createExecutableReference(); executableReference.setSimpleName(assertion.toStringAccordingToClass(this.getClass())); executableReference.setDeclaringType(factory.Type().createReference(assertion.toStringAccordingToClass(this.getClass()))); invocation.setExecutable(executableReference); if (arguments.size() > 1) { invocation.setArguments(Collections.singletonList(arguments.get(0))); } invocation.setType(factory.Type().voidPrimitiveType()); invocation.setTarget(assertThat); invocation.putMetadata(METADATA_ASSERT_AMPLIFICATION, true); return invocation; }
@SuppressWarnings("unchecked") private CtInvocation<?> createAssertThat(CtExpression<?> actual) { final Factory factory = InputConfiguration.get().getFactory(); final CtInvocation invocation = factory.createInvocation(); final CtExecutableReference executableReference = factory.Core().createExecutableReference(); executableReference.setStatic(true); executableReference.setSimpleName(ASSERT_THAT); executableReference.setDeclaringType(factory.Type().createReference(this.qualifiedNameOfAssertClass)); invocation.setExecutable(executableReference); invocation.setArguments(Collections.singletonList(actual)); invocation.setType(factory.Type().voidPrimitiveType()); invocation.setTarget(factory.createTypeAccess(factory.Type().createReference(this.qualifiedNameOfAssertClass))); invocation.putMetadata(METADATA_ASSERT_AMPLIFICATION, true); return invocation; }
/** * Builds an invocation to <code>methodName</code> of {@link org.junit.Assert}. * This should be a correct method name such as assertEquals, assertTrue... * * @param assertion the type of the assertion method * @param arguments the arguments of the assertion, <i>e.g.</i> the two element to be compared in {@link org.junit.Assert#assertEquals(Object, Object)} * @return a spoon node representing the invocation to the assertion, ready to be inserted in a test method */ @Override public CtInvocation<?> buildInvocationToAssertion(CtMethod<?> testMethod, AssertEnum assertion, List<CtExpression> arguments) { final Factory factory = InputConfiguration.get().getFactory(); final CtInvocation invocation = factory.createInvocation(); final CtExecutableReference<?> executableReference = factory.Core().createExecutableReference(); executableReference.setStatic(true); executableReference.setSimpleName(assertion.toStringAccordingToClass(JUnitSupport.class)); executableReference.setDeclaringType(factory.Type().createReference(this.qualifiedNameOfAssertClass)); invocation.setExecutable(executableReference); invocation.setArguments(arguments); // TODO invocation.setType(factory.Type().voidPrimitiveType()); invocation.setTarget(factory.createTypeAccess(factory.Type().createReference(this.qualifiedNameOfAssertClass))); invocation.putMetadata(METADATA_ASSERT_AMPLIFICATION, true); return invocation; }