-
Notifications
You must be signed in to change notification settings - Fork 306
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve Javadoc of predicates and functions #912
At the moment it is quite challenging to find a certain predicate or function, because users might need to know the domain model very well to find the necessary location (e.g. predicates like `nameMatching(..)` are defined within `HasName.Predicates` to be reused for everything that has a name, but at the same time users now need to know that `JavaClass` implements `HasName` to use these predicates). While in the long term it might make sense to implement a better entry point API to improve discoverability, for now we can at least improve the documentation to link from more specific predicates to more generic ones. I.e. that I have some chance to discover 1) Javadoc on some method `...That(DescribedPredicate<? super JavaClass>)` -> "you can find predefined predicates in `JavaClass.Predicates` 2) Javadoc on `JavaClass.Predicates` -> "due to inheritance you can find further applicable predicates in `HasName.Predicates`, `HasModifiers.Predicates`, ..."
- Loading branch information
Showing
49 changed files
with
949 additions
and
22 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
...est/java/com/tngtech/archunit/lang/syntax/elements/ClassesShouldNewerJavaVersionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.tngtech.archunit.lang.syntax.elements; | ||
|
||
import com.tngtech.archunit.lang.ArchRule; | ||
import com.tngtech.archunit.lang.EvaluationResult; | ||
import com.tngtech.archunit.lang.conditions.ArchConditions; | ||
import com.tngtech.archunit.lang.syntax.elements.testobjects.SomeRecord; | ||
import com.tngtech.java.junit.dataprovider.DataProvider; | ||
import com.tngtech.java.junit.dataprovider.DataProviderRunner; | ||
import com.tngtech.java.junit.dataprovider.UseDataProvider; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static com.tngtech.archunit.core.domain.TestUtils.importClasses; | ||
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes; | ||
import static com.tngtech.archunit.lang.syntax.elements.ClassesShouldTest.locationPattern; | ||
import static com.tngtech.archunit.lang.syntax.elements.ClassesShouldTest.singleLineFailureReportOf; | ||
import static com.tngtech.archunit.testutil.Assertions.assertThat; | ||
import static com.tngtech.java.junit.dataprovider.DataProviders.$; | ||
import static com.tngtech.java.junit.dataprovider.DataProviders.$$; | ||
import static java.util.regex.Pattern.quote; | ||
|
||
@RunWith(DataProviderRunner.class) | ||
public class ClassesShouldNewerJavaVersionTest { | ||
|
||
@DataProvider | ||
public static Object[][] data_beRecords() { | ||
return $$( | ||
$(classes().should().beRecords(), SomeRecord.class, String.class), | ||
$(classes().should(ArchConditions.beRecords()), SomeRecord.class, String.class)); | ||
} | ||
|
||
@Test | ||
@UseDataProvider | ||
public void test_beRecords(ArchRule rule, Class<?> satisfied, Class<?> violated) { | ||
EvaluationResult result = rule.evaluate(importClasses(satisfied, violated)); | ||
|
||
assertThat(singleLineFailureReportOf(result)) | ||
.contains("classes should be records") | ||
.containsPattern(String.format("Class <%s> is no record in %s", | ||
quote(violated.getName()), | ||
locationPattern(violated))) | ||
.doesNotMatch(String.format(".*%s.* record.*", quote(satisfied.getName()))); | ||
} | ||
|
||
@DataProvider | ||
public static Object[][] data_notBeRecords() { | ||
return $$( | ||
$(classes().should().notBeRecords(), String.class, SomeRecord.class), | ||
$(classes().should(ArchConditions.notBeRecords()), String.class, SomeRecord.class)); | ||
} | ||
|
||
@Test | ||
@UseDataProvider | ||
public void test_notBeRecords(ArchRule rule, Class<?> satisfied, Class<?> violated) { | ||
EvaluationResult result = rule.evaluate(importClasses(satisfied, violated)); | ||
|
||
assertThat(singleLineFailureReportOf(result)) | ||
.contains("classes should not be records") | ||
.containsPattern(String.format("Class <%s> is a record in %s", | ||
quote(violated.getName()), | ||
locationPattern(violated))) | ||
.doesNotMatch(String.format(".*%s.* record.*", quote(satisfied.getName()))); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
.../src/jdk16test/java/com/tngtech/archunit/lang/syntax/elements/testobjects/SomeRecord.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.tngtech.archunit.lang.syntax.elements.testobjects; | ||
|
||
public record SomeRecord(int attribute) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.