1

I am generating both the class and enums, and the generated code looks fine. The generated enums is in sub-package of the generated class.

Generated class package - com.pkg1.pkg2
Generated enum package  - com.pkg1.pkg2.enums

I have a java test case where the class has to compile. So for this I compiles the enums first. This works fine. Now the test case fails where the setter methods of the class has enum as input parameters.

1) sample code for Enum-Weather:

package com.pkg1.pkg2.enums;

public enum Weather{

SUMMER("summer"),
WINTER("winter");

public final String value;

public Weather(String value) {
    this.value = value;
}

public String getValue() {
return value;
}

}

2) sample code of a class-Weather:

package com.pkg1.pkg2;

import com.pkg1.pkg2.enums.Weather;

public interface Weather extends CityWeather{

public void setWeather(Weather weather);

}

3) Sample code of the test case:

@BeforeClass
public static void beforeAllTestMethods() throws Exception {

       /* First 3 lines runs without any error */
       String enumsPath = Paths.get("").toAbsolutePath().toString()+ "com/pkg1/pkg2/enums/"
       JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
       compiler.run(null,null,null,enumsPath + "Weather.java");

       /* The below code fails.
           error: package com.pkg1.pkg2.enums does not exist
           import com.pkg1.pkg2.enums.Weather;
                                      ^ 
       */
       String classPath = Paths.get("").toAbsolutePath().toString()+ "com/pkg1/pkg2/"
       JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
       compiler.run(null,null,null,classPath + "Weather.java");

Any suggestion please.

Aavik
  • 967
  • 19
  • 48
  • Is there any updates that can be made in pom to access the enums during class compile. This test case runs if manually run from Intellij IDE(might be tool is supporting) – Aavik Apr 07 '20 at 11:26

0 Answers0