Skip to content

Commit

Permalink
assertj#194: cleaned up the autoformatting mess.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zegveld committed Jan 26, 2022
1 parent e592a13 commit 4a9b2c1
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static org.apache.commons.lang3.StringUtils.remove;
import static org.apache.commons.lang3.StringUtils.replace;
import static org.assertj.assertions.generator.GeneratedAnnotationSource.JAKARTA;
import static org.assertj.assertions.generator.GeneratedAnnotationSource.JAVAX;
import static org.assertj.assertions.generator.Template.Type.ABSTRACT_ASSERT_CLASS;
import static org.assertj.assertions.generator.Template.Type.ASSERT_CLASS;
import static org.assertj.assertions.generator.Template.Type.HIERARCHICAL_ASSERT_CLASS;
Expand Down Expand Up @@ -54,6 +56,7 @@
public class BaseAssertionGenerator implements AssertionGenerator, AssertionsEntryPointGenerator {

static final String TEMPLATES_DIR = "templates" + File.separator;
private static final String GENERATED = "${generatedAnnotation}";
private static final String IMPORT_LINE = "import %s;%s";
private static final String PREDICATE = "${predicate}";
private static final String PREDICATE_NEG = "${neg_predicate}";
Expand Down Expand Up @@ -178,6 +181,7 @@ public class BaseAssertionGenerator implements AssertionGenerator, AssertionsEnt
private TemplateRegistry templateRegistry;// the pattern to search for
private boolean generateAssertionsForAllFields = false;
private String generatedAssertionsPackage = null;
private GeneratedAnnotationSource generatedAnnotationSource = JAVAX;

/**
* Creates a new <code>{@link BaseAssertionGenerator}</code> with default templates directory.
Expand Down Expand Up @@ -326,6 +330,7 @@ private String fillAssertClassTemplate(String template, ClassDescription classDe
final String selfType = concrete ? customAssertionClass : ABSTRACT_ASSERT_SELF_TYPE;
final String myself = concrete ? "this" : "myself";

template = replace(template, GENERATED, determineGeneratedSignature());
template = replace(template, PACKAGE, determinePackageName(classDescription));
template = replace(template, CUSTOM_ASSERTION_CLASS, customAssertionClass);
// use a simple parent class name as we have already imported it
Expand All @@ -345,6 +350,16 @@ private String fillAssertClassTemplate(String template, ClassDescription classDe
return template;
}

private String determineGeneratedSignature() {
if (generatedAnnotationSource == JAVAX) {
return "@javax.annotation.Generated(value=\"assertj-assertions-generator\")";
}
if (generatedAnnotationSource == JAKARTA) {
return "@jakarta.annotation.Generated(value=\"assertj-assertions-generator\")";
}
return "";
}

private String determinePackageName(ClassDescription classDescription) {
return generatedAssertionsPackage == null ? classDescription.getPackageName() : generatedAssertionsPackage;
}
Expand Down Expand Up @@ -451,6 +466,7 @@ private String generateAssertionsEntryPointClassContent(final Set<ClassDescripti
String classPackage = isEmpty(entryPointClassPackage)
? determineBestEntryPointsAssertionsClassPackage(classDescriptionSet)
: entryPointClassPackage;
entryPointAssertionsClassContent = replace(entryPointAssertionsClassContent, GENERATED, determineGeneratedSignature());
entryPointAssertionsClassContent = replace(entryPointAssertionsClassContent, PACKAGE, classPackage);

String allEntryPointsAssertionContent = generateAssertionEntryPointMethodsFor(classDescriptionSet,
Expand Down Expand Up @@ -827,4 +843,8 @@ private static void buildDirectory(String directoryName) {
public void register(Template template) {
templateRegistry.register(template);
}

public void setGeneratedAnnotationSource(GeneratedAnnotationSource generatedAnnotationSource) {
this.generatedAnnotationSource = generatedAnnotationSource;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* Copyright 2012-2021 the original author or authors.
*/
package org.assertj.assertions.generator;

public enum GeneratedAnnotationSource {
JAKARTA,
JAVAX,
NONE;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package ${package};
* }
* </pre>
*/
@javax.annotation.Generated(value="assertj-assertions-generator")
${generatedAnnotation}
public class AutoCloseableSoftAssertions extends org.assertj.core.api.SoftAssertions implements AutoCloseable {
${all_assertions_entry_points}
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package ${package};
/**
* Entry point for BDD assertions of different data types.
*/
@javax.annotation.Generated(value="assertj-assertions-generator")
${generatedAnnotation}
public class BddAssertions {
${all_assertions_entry_points}
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package ${package};
/**
* Entry point for BDD soft assertions of different data types.
*/
@javax.annotation.Generated(value="assertj-assertions-generator")
${generatedAnnotation}
public class BDDSoftAssertions extends org.assertj.core.api.BDDSoftAssertions {
${all_assertions_entry_points}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ${imports}
/**
* Abstract base class for {@link ${class_to_assert}} specific assertions - Generated by CustomAssertionGenerator.
*/
@javax.annotation.Generated(value="assertj-assertions-generator")
${generatedAnnotation}
public abstract class ${custom_assertion_class}<S extends ${custom_assertion_class}<S, A>, A extends ${class_to_assert}> extends ${super_assertion_class}<S, A> {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ${imports}
/**
* {@link ${class_to_assert}} specific assertions - Generated by CustomAssertionGenerator.
*/
@javax.annotation.Generated(value="assertj-assertions-generator")
${generatedAnnotation}
public class ${custom_assertion_class} extends AbstractObjectAssert<${custom_assertion_class}, ${class_to_assert}> {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ${imports}
* Although this class is not final to allow Soft assertions proxy, if you wish to extend it,
* extend {@link Abstract${custom_assertion_class}} instead.
*/
@javax.annotation.Generated(value="assertj-assertions-generator")
${generatedAnnotation}
public class ${custom_assertion_class} extends Abstract${custom_assertion_class}<${custom_assertion_class}, ${class_to_assert}> {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package ${package};
* }
* }</code></pre>
*/
@javax.annotation.Generated(value="assertj-assertions-generator")
${generatedAnnotation}
public class JUnitBDDSoftAssertions extends org.assertj.core.api.JUnitBDDSoftAssertions {
${all_assertions_entry_points}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package ${package};
* }
* }</code></pre>
*/
@javax.annotation.Generated(value="assertj-assertions-generator")
${generatedAnnotation}
public class JUnitSoftAssertions extends org.assertj.core.api.JUnitSoftAssertions {
${all_assertions_entry_points}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package ${package};
/**
* Entry point for soft assertions of different data types.
*/
@javax.annotation.Generated(value="assertj-assertions-generator")
${generatedAnnotation}
public class SoftAssertions extends org.assertj.core.api.SoftAssertions {
${all_assertions_entry_points}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package ${package};
* Entry point for assertions of different data types. Each method in this class is a static factory for the
* type-specific assertion objects.
*/
@javax.annotation.Generated(value="assertj-assertions-generator")
${generatedAnnotation}
public class Assertions {
${all_assertions_entry_points}
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void should_generate_correctly_standard_assertions_entry_point_class_for_
STANDARD, "org");
// THEN
String expectedContent = readExpectedContentFromFile("AssertionsForClassesWithSameName.expected.txt");
assertThat(assertionsEntryPointContent).isEqualTo(expectedContent);
assertThat(assertionsEntryPointContent).isEqualToIgnoringNewLines(expectedContent);
}

@Test
Expand Down

0 comments on commit 4a9b2c1

Please sign in to comment.