Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

package name of the generated asserts is always the same as for the source classes #13

Open
MikeShysh opened this issue Sep 9, 2017 · 6 comments

Comments

@MikeShysh
Copy link

MikeShysh commented Sep 9, 2017

Hello,

I have the following configs

assertjGen {
    classOrPackageNames = ['com.mycompany.api.jsonModels']
    outputDir = 'src/main/java/com/mycompany/api/asserts'
    assertjGenerator = 'org.assertj:assertj-assertions-generator:2.0.0'
    cleanOnlyFiles = true
}

As a result, generated asserts are placed to 'src/main/java/com/mycompany/api/asserts' but with package name com.mycompany.api.jsonModels.

Here is the part of log:

14:11:49.433 INFO  o.a.a.g.c.AssertionGeneratorLauncher - Generating assertions for classes [class com.mycompany.api.jsonModels.CustomerInfo, class com.mycompany.api.jsonModels.AuxFieldsInfoItem, class com.mycompany.api.jsonModels.ServiceFeaturesInfoItem]
14:11:49.453 INFO  o.a.a.g.c.AssertionGeneratorLauncher - Generating assertions for class : com.mycompany.api.jsonModels.CustomerInfo
14:11:49.490 INFO  o.a.a.g.c.AssertionGeneratorLauncher - Generated CustomerInfo assertions file -> /home/mike-ua/api/src/main/java/com/mycompany/api/asserts/./com/mycompany/api/jsonModels/CustomerInfoAssert.java  <<<<

Please check what could be done to have generated asserts with the corresponding package name

@MikeShysh MikeShysh changed the title package name of the generated asserts is always the same as the source classes package name of the generated asserts is always the same as for the source classes Sep 9, 2017
@opengl-8080
Copy link
Owner

I guess that AssertJ Assertions Generator does not support it.

Package name is generated at BaseAssertionGenerator.java.

BaseAssertionGenerator.java#L282

    template = replace(template, PACKAGE, classDescription.getPackageName());

ClassDescription.getPackageName() method is implemented like following.

ClassDescription#L70

  private TypeToken<?> type;

  ....

  public String getPackageName() {
    return type.getRawType().getPackage().getName();
  }

type represents source class type that is target of generator.
Therefor, assertion classes has same package name to source target classes.

ClassDescription instance is created at AssertionGeneratorLauncher.java.

AssertionGeneratorLauncher#91

  private static void generateFlatAssertions(Set<TypeToken<?>> types) throws IOException {
    logger.info("Generating assertions for types {}", types);
    BaseAssertionGenerator customAssertionGenerator = new BaseAssertionGenerator();
    
    for (TypeToken<?> type : types) {
      logger.info("Generating assertions for class : {}", type);
      File customAssertionFile = customAssertionGenerator.generateCustomAssertionFor(toClassDescription(type)); // here!!
      logger.info("Generated {} assertions file -> {}", type,
                  customAssertionFile.getAbsolutePath());
    }
  }

There are no options to configure package name.

@MikeShysh
Copy link
Author

Thank you. If I understand you correctly it should be fixed on "AssertJ Assertions Generator" side? Am I right?

@opengl-8080
Copy link
Owner

Yes.
Would you please consult AssertJ Assertion Generator?

@MikeShysh
Copy link
Author

Hi,
Additional parameter was added on AssertJ Assertion Generator: assertj/assertj-assertions-generator#112

@opengl-8080
Copy link
Owner

Thank you.
I confirm the issue.

@opengl-8080
Copy link
Owner

I made version2.
You can use generateAssertionsInPackage option in this plugin.

However I found a bug of generateAssertionsInPackage.
If you want to generate assertions entry point classes, please wait to fix issue #122.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants