Skip to content

Commit c192a7d

Browse files
committed
GH-42 - Upgrade to ArchUnit 1.0.
1 parent bea7617 commit c192a7d

File tree

8 files changed

+49
-41
lines changed

8 files changed

+49
-41
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
<properties>
2828

29-
<archunit.version>0.23.1</archunit.version>
29+
<archunit.version>1.0.0</archunit.version>
3030
<artifactory-maven-plugin.version>3.4.0</artifactory-maven-plugin.version>
3131
<jmolecules-bom.version>2021.2.4</jmolecules-bom.version>
3232
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

spring-modulith-core/src/main/java/org/springframework/modulith/model/ApplicationModule.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ public InjectionModuleDependency(JavaClass origin, JavaClass target, JavaMember
772772
DependencyType.USES_COMPONENT);
773773

774774
this.member = member;
775-
this.isConfigurationClass = isConfiguration().apply(origin);
775+
this.isConfigurationClass = isConfiguration().test(origin);
776776
}
777777

778778
/*
@@ -887,8 +887,8 @@ public static DependencyType forParameter(JavaClass type) {
887887
}
888888

889889
public static DependencyType forCodeUnit(JavaCodeUnit codeUnit) {
890-
return Types.isAnnotatedWith(SpringTypes.AT_EVENT_LISTENER).apply(codeUnit) //
891-
|| Types.isAnnotatedWith(JMoleculesTypes.AT_DOMAIN_EVENT_HANDLER).apply(codeUnit) //
890+
return Types.isAnnotatedWith(SpringTypes.AT_EVENT_LISTENER).test(codeUnit) //
891+
|| Types.isAnnotatedWith(JMoleculesTypes.AT_DOMAIN_EVENT_HANDLER).test(codeUnit) //
892892
? EVENT_LISTENER
893893
: DEFAULT;
894894
}

spring-modulith-core/src/main/java/org/springframework/modulith/model/ApplicationModules.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ public class ApplicationModules implements Iterable<ApplicationModule> {
5959

6060
static {
6161

62-
List<ApplicationModuleDetectionStrategy> loadFactories = SpringFactoriesLoader.loadFactories(ApplicationModuleDetectionStrategy.class,
62+
List<ApplicationModuleDetectionStrategy> loadFactories = SpringFactoriesLoader.loadFactories(
63+
ApplicationModuleDetectionStrategy.class,
6364
ApplicationModules.class.getClassLoader());
6465

6566
if (loadFactories.size() > 1) {
@@ -69,7 +70,8 @@ public class ApplicationModules implements Iterable<ApplicationModule> {
6970
loadFactories));
7071
}
7172

72-
DETECTION_STRATEGY = loadFactories.isEmpty() ? ApplicationModuleDetectionStrategies.DIRECT_SUB_PACKAGES : loadFactories.get(0);
73+
DETECTION_STRATEGY = loadFactories.isEmpty() ? ApplicationModuleDetectionStrategies.DIRECT_SUB_PACKAGES
74+
: loadFactories.get(0);
7375
}
7476

7577
private final ModulithMetadata metadata;
@@ -80,7 +82,8 @@ public class ApplicationModules implements Iterable<ApplicationModule> {
8082

8183
private boolean verified;
8284

83-
private ApplicationModules(ModulithMetadata metadata, Collection<String> packages, DescribedPredicate<JavaClass> ignored,
85+
private ApplicationModules(ModulithMetadata metadata, Collection<String> packages,
86+
DescribedPredicate<JavaClass> ignored,
8487
boolean useFullyQualifiedModuleNames) {
8588

8689
this.metadata = metadata;
@@ -105,8 +108,8 @@ private ApplicationModules(ModulithMetadata metadata, Collection<String> package
105108
}
106109

107110
/**
108-
* Creates a new {@link ApplicationModules} relative to the given modulith type. Will inspect the {@link Modulith} annotation on
109-
* the class given for advanced customizations of the module setup.
111+
* Creates a new {@link ApplicationModules} relative to the given modulith type. Will inspect the {@link Modulith}
112+
* annotation on the class given for advanced customizations of the module setup.
110113
*
111114
* @param modulithType must not be {@literal null}.
112115
* @return
@@ -116,9 +119,10 @@ public static ApplicationModules of(Class<?> modulithType) {
116119
}
117120

118121
/**
119-
* Creates a new {@link ApplicationModules} relative to the given modulith type, a {@link ApplicationModuleDetectionStrategy} and a
120-
* {@link DescribedPredicate} which types and packages to ignore. Will inspect the {@link Modulith} and
121-
* {@link Modulithic} annotations on the class given for advanced customizations of the module setup.
122+
* Creates a new {@link ApplicationModules} relative to the given modulith type, a
123+
* {@link ApplicationModuleDetectionStrategy} and a {@link DescribedPredicate} which types and packages to ignore.
124+
* Will inspect the {@link Modulith} and {@link Modulithic} annotations on the class given for advanced
125+
* customizations of the module setup.
122126
*
123127
* @param modulithType must not be {@literal null}.
124128
* @param detection must not be {@literal null}.
@@ -371,7 +375,7 @@ public static DescribedPredicate<JavaClass> withoutModules(String... names) {
371375

372376
return Arrays.stream(names) //
373377
.map(it -> withoutModule(it)) //
374-
.reduce(DescribedPredicate.alwaysFalse(), DescribedPredicate::or, (__, right) -> right);
378+
.reduce(DescribedPredicate.alwaysFalse(), (left, right) -> left.or(right), (__, right) -> right);
375379
}
376380

377381
public static DescribedPredicate<JavaClass> withoutModule(String name) {

spring-modulith-core/src/main/java/org/springframework/modulith/model/ArchitecturallyEvidentType.java

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ public abstract class ArchitecturallyEvidentType {
6060
private final @Getter JavaClass type;
6161

6262
/**
63-
* Creates a new {@link ArchitecturallyEvidentType} for the given {@link JavaType} and {@link Classes} of
64-
* Spring components.
63+
* Creates a new {@link ArchitecturallyEvidentType} for the given {@link JavaType} and {@link Classes} of Spring
64+
* components.
6565
*
6666
* @param type must not be {@literal null}.
6767
* @param beanTypes must not be {@literal null}.
@@ -102,7 +102,7 @@ String getAbbreviatedFullName() {
102102
* @return
103103
*/
104104
boolean isEntity() {
105-
return isJpaEntity().apply(getType());
105+
return isJpaEntity().test(getType());
106106
}
107107

108108
/**
@@ -181,8 +181,8 @@ static class SpringAwareArchitecturallyEvidentType extends ArchitecturallyEviden
181181
* Methods (meta-)annotated with @EventListener.
182182
*/
183183
private static final Predicate<JavaMethod> IS_ANNOTATED_EVENT_LISTENER = it -> //
184-
Types.isAnnotatedWith(SpringTypes.AT_EVENT_LISTENER).apply(it) //
185-
|| Types.isAnnotatedWith(SpringTypes.AT_TX_EVENT_LISTENER).apply(it);
184+
Types.isAnnotatedWith(SpringTypes.AT_EVENT_LISTENER).test(it) //
185+
|| Types.isAnnotatedWith(SpringTypes.AT_TX_EVENT_LISTENER).test(it);
186186

187187
/**
188188
* {@code ApplicationListener.onApplicationEvent(…)}
@@ -214,7 +214,7 @@ public boolean isAggregateRoot() {
214214
*/
215215
@Override
216216
public boolean isRepository() {
217-
return Types.isAnnotatedWith(SpringTypes.AT_REPOSITORY).apply(getType());
217+
return Types.isAnnotatedWith(SpringTypes.AT_REPOSITORY).test(getType());
218218
}
219219

220220
/*
@@ -223,7 +223,7 @@ public boolean isRepository() {
223223
*/
224224
@Override
225225
public boolean isService() {
226-
return Types.isAnnotatedWith(SpringTypes.AT_SERVICE).apply(getType());
226+
return Types.isAnnotatedWith(SpringTypes.AT_SERVICE).test(getType());
227227
}
228228

229229
/*
@@ -232,7 +232,7 @@ public boolean isService() {
232232
*/
233233
@Override
234234
public boolean isController() {
235-
return Types.isAnnotatedWith(SpringTypes.AT_CONTROLLER).apply(getType());
235+
return Types.isAnnotatedWith(SpringTypes.AT_CONTROLLER).test(getType());
236236
}
237237

238238
/*
@@ -250,7 +250,7 @@ public boolean isEventListener() {
250250
*/
251251
@Override
252252
public boolean isConfigurationProperties() {
253-
return Types.isAnnotatedWith(SpringTypes.AT_CONFIGURATION_PROPERTIES).apply(getType());
253+
return Types.isAnnotatedWith(SpringTypes.AT_CONFIGURATION_PROPERTIES).test(getType());
254254
}
255255

256256
/*
@@ -329,7 +329,7 @@ public boolean isAggregateRoot() {
329329
*/
330330
@Override
331331
public boolean isRepository() {
332-
return SpringDataTypes.isSpringDataRepository().apply(getType());
332+
return SpringDataTypes.isSpringDataRepository().test(getType());
333333
}
334334

335335
/*
@@ -338,14 +338,15 @@ public boolean isRepository() {
338338
*/
339339
@Override
340340
public boolean isController() {
341-
return Types.isAnnotatedWith("org.springframework.data.rest.webmvc.BasePathAwareController").apply(getType());
341+
return Types.isAnnotatedWith("org.springframework.data.rest.webmvc.BasePathAwareController")
342+
.test(getType());
342343
}
343344
}
344345

345346
static class JMoleculesArchitecturallyEvidentType extends ArchitecturallyEvidentType {
346347

347348
private static final Predicate<JavaMethod> IS_ANNOTATED_EVENT_LISTENER = Types
348-
.isAnnotatedWith(JMoleculesTypes.AT_DOMAIN_EVENT_HANDLER)::apply;
349+
.isAnnotatedWith(JMoleculesTypes.AT_DOMAIN_EVENT_HANDLER)::test;
349350

350351
JMoleculesArchitecturallyEvidentType(JavaClass type) {
351352
super(type);
@@ -360,7 +361,7 @@ public boolean isEntity() {
360361

361362
JavaClass type = getType();
362363

363-
return Types.isAnnotatedWith(org.jmolecules.ddd.annotation.Entity.class).apply(type) || //
364+
return Types.isAnnotatedWith(org.jmolecules.ddd.annotation.Entity.class).test(type) || //
364365
type.isAssignableTo(org.jmolecules.ddd.types.Entity.class);
365366
}
366367

@@ -373,7 +374,7 @@ public boolean isAggregateRoot() {
373374

374375
JavaClass type = getType();
375376

376-
return Types.isAnnotatedWith(org.jmolecules.ddd.annotation.AggregateRoot.class).apply(type) //
377+
return Types.isAnnotatedWith(org.jmolecules.ddd.annotation.AggregateRoot.class).test(type) //
377378
|| type.isAssignableTo(org.jmolecules.ddd.types.AggregateRoot.class);
378379
}
379380

@@ -386,7 +387,7 @@ public boolean isRepository() {
386387

387388
JavaClass type = getType();
388389

389-
return Types.isAnnotatedWith(org.jmolecules.ddd.annotation.Repository.class).apply(type)
390+
return Types.isAnnotatedWith(org.jmolecules.ddd.annotation.Repository.class).test(type)
390391
|| type.isAssignableTo(org.jmolecules.ddd.types.Repository.class);
391392
}
392393

@@ -399,7 +400,7 @@ public boolean isService() {
399400

400401
JavaClass type = getType();
401402

402-
return Types.isAnnotatedWith(org.jmolecules.ddd.annotation.Service.class).apply(type);
403+
return Types.isAnnotatedWith(org.jmolecules.ddd.annotation.Service.class).test(type);
403404
}
404405

405406
/*
@@ -414,15 +415,18 @@ public boolean isEventListener() {
414415

415416
static class DelegatingType extends ArchitecturallyEvidentType {
416417

417-
private final Supplier<Boolean> isAggregateRoot, isRepository, isEntity, isService, isController, isEventListener,
418+
private final Supplier<Boolean> isAggregateRoot, isRepository, isEntity, isService, isController,
419+
isEventListener,
418420
isConfigurationProperties;
419421
private final Supplier<Collection<JavaClass>> referenceTypes;
420422
private final Supplier<Collection<ReferenceMethod>> referenceMethods;
421423

422424
DelegatingType(JavaClass type, Supplier<Boolean> isAggregateRoot,
423425
Supplier<Boolean> isRepository, Supplier<Boolean> isEntity, Supplier<Boolean> isService,
424-
Supplier<Boolean> isController, Supplier<Boolean> isEventListener, Supplier<Boolean> isConfigurationProperties,
425-
Supplier<Collection<JavaClass>> referenceTypes, Supplier<Collection<ReferenceMethod>> referenceMethods) {
426+
Supplier<Boolean> isController, Supplier<Boolean> isEventListener,
427+
Supplier<Boolean> isConfigurationProperties,
428+
Supplier<Collection<JavaClass>> referenceTypes,
429+
Supplier<Collection<ReferenceMethod>> referenceMethods) {
426430

427431
super(type);
428432

spring-modulith-core/src/main/java/org/springframework/modulith/model/Classes.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ Classes that(DescribedPredicate<? super JavaClass> predicate) {
108108
Assert.notNull(predicate, "Predicate must not be null!");
109109

110110
return classes.stream() //
111-
.filter((Predicate<JavaClass>) it -> predicate.apply(it)) //
111+
.filter((Predicate<JavaClass>) it -> predicate.test(it)) //
112112
.collect(Collectors.collectingAndThen(Collectors.toList(), Classes::new));
113113
}
114114

@@ -166,7 +166,8 @@ JavaClass getRequiredClass(Class<?> type) {
166166
return classes.stream() //
167167
.filter(it -> it.isEquivalentTo(type)) //
168168
.findFirst() //
169-
.orElseThrow(() -> new IllegalArgumentException(String.format("No JavaClass found for type %s!", type)));
169+
.orElseThrow(
170+
() -> new IllegalArgumentException(String.format("No JavaClass found for type %s!", type)));
170171
}
171172

172173
/*
@@ -227,10 +228,10 @@ public SameClass(JavaClass reference) {
227228

228229
/*
229230
* (non-Javadoc)
230-
* @see com.tngtech.archunit.base.DescribedPredicate#apply(java.lang.Object)
231+
* @see java.util.function.Predicate#test(java.lang.Object)
231232
*/
232233
@Override
233-
public boolean apply(@Nullable JavaClass input) {
234+
public boolean test(@Nullable JavaClass input) {
234235
return input != null && reference.getName().equals(input.getName());
235236
}
236237
}

spring-modulith-core/src/main/java/org/springframework/modulith/model/SpringBean.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public List<JavaClass> getInterfacesWithinModule() {
6969
}
7070

7171
public boolean isAnnotatedWith(Class<?> type) {
72-
return Types.isAnnotatedWith(type).apply(this.type);
72+
return Types.isAnnotatedWith(type).test(this.type);
7373
}
7474

7575
public ArchitecturallyEvidentType toArchitecturallyEvidentType() {

spring-modulith-core/src/main/java/org/springframework/modulith/model/Types.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ static DescribedPredicate<? super JavaClass> isConfigurationProperties() {
125125
}
126126

127127
static boolean isAtBeanMethod(JavaMethod method) {
128-
return isAnnotatedWith(SpringTypes.AT_BEAN).apply(method);
128+
return isAnnotatedWith(SpringTypes.AT_BEAN).test(method);
129129
}
130130
}
131131

spring-modulith-integration-test/src/test/java/org/springframework/modulith/model/JavaPackageUnitTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,14 @@
2222
import com.tngtech.archunit.core.domain.JavaClasses;
2323
import com.tngtech.archunit.core.importer.ClassFileImporter;
2424
import com.tngtech.archunit.core.importer.ImportOption;
25-
import com.tngtech.archunit.core.importer.ImportOptions;
2625

2726
/**
2827
* @author Oliver Drotbohm
2928
*/
3029
class JavaPackageUnitTests {
3130

32-
static final ImportOptions NO_TESTS = new ImportOptions().with(new ImportOption.DoNotIncludeTests());
33-
static final JavaClasses ALL_CLASSES = new ClassFileImporter(NO_TESTS) //
31+
static final JavaClasses ALL_CLASSES = new ClassFileImporter() //
32+
.withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS)
3433
.importPackages("com.acme.myproject");
3534

3635
@Test

0 commit comments

Comments
 (0)