Search code examples
javaclassabstractcitrus-framework

Trying to use Citrus - Compilation error: return type required


I'm getting an error trying to follow citrus exemple in chapter "5.3. Java DSL test designer"(https://citrusframework.org/citrus/reference/2.7.8/html/index.html#java-dsl-test-designer), here is the code in LoggingTestDesignerRightOrder.java

package com.consol.citrus.samples;

import org.testng.annotations.Test;
import com.consol.citrus.annotations.CitrusTest;
import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;
import com.consol.citrus.TestAction;
import com.consol.citrus.context.TestContext;
import com.consol.citrus.actions.AbstractTestAction;
import com.consol.citrus.samples.LoggingService;

@Test
public class LoggingTestDesignerRightOrder extends     TestNGCitrusTestDesigner {
private LoggingService loggingService = new LoggingService();

@CitrusTest(name = "LoggingTestRightOrder")
public void loggingTest() {
    echo("Before loggingService call");

   action(new AbstractTestAction() {
        doExecute(TestContext context) {
           loggingService.log("Now called custom logging service");
        }
    });

    echo("After loggingService call");
    }
}

When running mvn clean verify -Dit.test=LoggingTestDesignerRightOrder

I got the following error:

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.1:testCompile (default-testCompile) on project citrus-sample: Compilation failure [ERROR] /Users/fb/dev/citrus/citrus-sample/src/test/java/com/consol/citrus/samples/LoggingTestDesignerRightOrder.java:[20,13] invalid method declaration; return type required

I can see that this is the doExecute invocation that creates pb but can't find what's needed to make it compile.

Full output of the mvn command:

Scanning for projects...
[INFO] 
[INFO] --------------< com.consol.citrus.samples:citrus-sample >---------------
[INFO] Building Citrus Integration Test 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ citrus-sample ---
[INFO] Deleting /Users/fb/dev/citrus/citrus-sample/target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ citrus-sample ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.6.1:compile (default-compile) @ citrus-sample ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ citrus-sample ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 4 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.6.1:testCompile (default-testCompile) @ citrus-sample ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 7 source files to /Users/fb/dev/citrus/citrus-sample/target/test-classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /Users/fb/dev/citrus/citrus-sample/src/test/java/com/consol/citrus/samples/LoggingTestDesignerRightOrder.java:[20,13] invalid method declaration; return type required
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.150 s
[INFO] Finished at: 2018-12-22T21:54:19+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.1:testCompile (default-testCompile) on project citrus-sample: Compilation failure
[ERROR] /Users/fb/dev/citrus/citrus-    sample/src/test/java/com/consol/citrus/samples/LoggingTestDesignerRightOrder.java:[20,13] invalid method declaration; return type required
[ERROR] 
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1]   http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

Thx for your help.


Solution

  • Listen to the compiler :)

    ...LoggingTestDesignerRightOrder.java:[20,13] invalid method declaration; return type required

    is caused by your anonymous AbstractTestAction implementation in line 20. It's missing at least a proper return type.

    Your implementation needs to properly override the doExecute method, like so:

    action(new AbstractTestAction() {
        @Override
        public void doExecute(TestContext context) {
            loggingService.log("Now called custom logging service");
        }
    });