5151
5252import com .google .common .reflect .TypeToken ;
5353
54- @ SuppressWarnings ("WeakerAccess" )
5554public class BaseAssertionGenerator implements AssertionGenerator , AssertionsEntryPointGenerator {
5655
5756 static final String TEMPLATES_DIR = "templates" + File .separator ;
@@ -165,7 +164,7 @@ public class BaseAssertionGenerator implements AssertionGenerator, AssertionsEnt
165164 * @see Character#isJavaIdentifierPart
166165 */
167166 private static final Pattern CLASS_NAME_PATTERN = Pattern
168- .compile ("(?m)^public class[\\ s]+(?<CLASSNAME>\\ p{javaJavaIdentifierStart}\\ p{javaJavaIdentifierPart}*)\\ b" );
167+ .compile ("(?m)^public class[\\ s]+(?<CLASSNAME>\\ p{javaJavaIdentifierStart}\\ p{javaJavaIdentifierPart}*)\\ b" );
169168
170169 private static final Set <TypeToken <?>> EMPTY_HIERARCHY = new HashSet <>();
171170
@@ -213,7 +212,8 @@ public void setGeneratedAssertionsPackage(String generatedAssertionsPackage) {
213212 }
214213
215214 private void checkGivenPackageIsValid (String generatedAssertionsPackage ) {
216- Validate .isTrue (isNotBlank (generatedAssertionsPackage ), "The given package '%s' must not be blank" , generatedAssertionsPackage );
215+ Validate .isTrue (isNotBlank (generatedAssertionsPackage ), "The given package '%s' must not be blank" ,
216+ generatedAssertionsPackage );
217217 Validate .isTrue (!containsWhitespace (generatedAssertionsPackage ), "The given package '%s' must not contain blank character" ,
218218 generatedAssertionsPackage );
219219 }
@@ -233,7 +233,8 @@ private String getDirectoryWhereToCreateAssertFilesFor(ClassDescription classDes
233233 }
234234
235235 @ Override
236- public File [] generateHierarchicalCustomAssertionFor (ClassDescription classDescription , Set <TypeToken <?>> allClasses ) throws IOException {
236+ public File [] generateHierarchicalCustomAssertionFor (ClassDescription classDescription ,
237+ Set <TypeToken <?>> allClasses ) throws IOException {
237238 // Assertion content
238239 String [] assertionFileContent = generateHierarchicalCustomAssertionContentFor (classDescription , allClasses );
239240 // Create the assertion file in targetBaseDirectory + either the given package or in the class to assert package
@@ -267,7 +268,8 @@ public String[] generateHierarchicalCustomAssertionContentFor(ClassDescription c
267268
268269 // return a String array with the actual generated content of the assertion class hierarchy
269270 String [] assertionClassesContent = new String [2 ];
270- assertionClassesContent [0 ] = fillAbstractAssertClassTemplate (abstractAssertClassContentBuilder .toString (), classDescription , classes );
271+ assertionClassesContent [0 ] = fillAbstractAssertClassTemplate (abstractAssertClassContentBuilder .toString (), classDescription ,
272+ classes );
271273 assertionClassesContent [1 ] = fillConcreteAssertClassTemplate (concreteAssertClassContent , classDescription );
272274 return assertionClassesContent ;
273275 }
@@ -294,19 +296,19 @@ private String fillAssertClassTemplate(String template, ClassDescription classDe
294296 classesToImport .add (classDescription .getFullyQualifiedOuterClassName ());
295297 if (template .contains ("Assertions." )) classesToImport .add ("org.assertj.core.api.Assertions" );
296298 if (template .contains ("Objects." )) {
297- int totalObjects = StringUtils .countMatches ( template , "Objects." );
298- int areEqualObjects = StringUtils .countMatches ( template , "Objects.deepEquals" );
299- int areEqualArraysObjects = StringUtils .countMatches ( template , "Objects.deepEqualsArrays" );
300-
301- int totalDeprecated = areEqualObjects + areEqualArraysObjects ;
302-
303- if ( totalDeprecated > 0 ) {
304- classesToImport .add ("java.util.Objects" );
305- }
306-
307- if ( totalObjects > totalDeprecated ) {
308- classesToImport .add ( "org.assertj.core.util.Objects" );
309- }
299+ int totalObjects = StringUtils .countMatches (template , "Objects." );
300+ int areEqualObjects = StringUtils .countMatches (template , "Objects.deepEquals" );
301+ int areEqualArraysObjects = StringUtils .countMatches (template , "Objects.deepEqualsArrays" );
302+
303+ int totalDeprecated = areEqualObjects + areEqualArraysObjects ;
304+
305+ if ( totalDeprecated > 0 ) {
306+ classesToImport .add ("java.util.Objects" );
307+ }
308+
309+ if (totalObjects > totalDeprecated ) {
310+ classesToImport .add ("org.assertj.core.util.Objects" );
311+ }
310312 }
311313 if (template .contains ("Iterables." )) classesToImport .add ("org.assertj.core.internal.Iterables" );
312314
@@ -319,7 +321,8 @@ private String fillAssertClassTemplate(String template, ClassDescription classDe
319321 classesToImport .add (parentAssertClassName );
320322 }
321323
322- final String customAssertionClass = concrete ? classDescription .getAssertClassName () : classDescription .getAbstractAssertClassName ();
324+ final String customAssertionClass = concrete ? classDescription .getAssertClassName ()
325+ : classDescription .getAbstractAssertClassName ();
323326 final String selfType = concrete ? customAssertionClass : ABSTRACT_ASSERT_SELF_TYPE ;
324327 final String myself = concrete ? "this" : "myself" ;
325328
@@ -474,7 +477,8 @@ private String generateAssertionsEntryPointClassContent(final Set<ClassDescripti
474477 private File createAssertionsFileFor (final Set <ClassDescription > classDescriptionSet , final String fileContent ,
475478 final String fileName , final String assertionsClassPackage ) throws IOException {
476479 String classPackage = isEmpty (assertionsClassPackage )
477- ? determineBestEntryPointsAssertionsClassPackage (classDescriptionSet ) : assertionsClassPackage ;
480+ ? determineBestEntryPointsAssertionsClassPackage (classDescriptionSet )
481+ : assertionsClassPackage ;
478482 String assertionsDirectory = getDirectoryPathCorrespondingToPackage (classPackage );
479483 // build any needed directories
480484 buildDirectory (assertionsDirectory );
@@ -521,7 +525,7 @@ private String determineBestEntryPointsAssertionsClassPackage(final Set<ClassDes
521525 /**
522526 * Returns the target directory path where the assertions file for given classDescription will be created.
523527 *
524- * @param packageName package name
528+ * @param packageName package name
525529 * @return the target directory path corresponding to the given package.
526530 */
527531 private String getDirectoryPathCorrespondingToPackage (final String packageName ) {
@@ -631,11 +635,12 @@ private String assertionContentForField(FieldDescription field, ClassDescription
631635
632636 private String getTypeName (DataDescription fieldOrGetter ) {
633637 if (generatedAssertionsPackage != null ) {
634- // if the user has chosen to generate assertions in a given package we assume that
638+ // if the user has chosen to generate assertions in a given package we assume that
635639 return fieldOrGetter .getFullyQualifiedTypeName ();
636640 }
637- // returns a simple class name if the field or getter type is in the same package as its owning type which is the package where the
638- // Assert class is generated.
641+ // returns a simple class name if the field or getter type is in the same package as its owning type which is the package
642+ // where the
643+ // Assert class is generated.
639644 return fieldOrGetter .getTypeName ();
640645 }
641646
0 commit comments