Skip to content

Commit 787b713

Browse files
authored
Merge branch 'master' into recover-and-try
2 parents 107a0cb + 82bd4ed commit 787b713

File tree

3 files changed

+43
-7
lines changed

3 files changed

+43
-7
lines changed

build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ plugins {
4343
ext.ammoniteScalaVersion = '3.5'
4444
ext.ammoniteVersion = '3.0.0'
4545
ext.ammoniteVersionQualifier = '2-6342755f'
46-
ext.assertjVersion = '3.27.0'
46+
ext.archUnitVersion = '1.3.0'
47+
ext.assertjVersion = '3.27.1'
4748
ext.junitVersion = '5.11.4'
4849

4950
// JAVA_VERSION used for CI build matrix, may be provided as env variable
@@ -60,6 +61,7 @@ repositories {
6061
dependencies {
6162
testImplementation "org.junit.jupiter:junit-jupiter:$junitVersion"
6263
testImplementation "org.assertj:assertj-core:$assertjVersion"
64+
testImplementation "com.tngtech.archunit:archunit-junit5:$archUnitVersion"
6365
}
6466

6567
tasks.withType(Test).configureEach {

src/test/java/io/vavr/CheckedRunnableTest.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,6 @@ public void shouldApplyAnUncheckedFunctionThatDoesNotThrow() {
6565
@Test
6666
public void shouldApplyAnUncheckedFunctionThatThrows() {
6767
final Runnable runnable = CheckedRunnable.of(() -> { throw new Error(); }).unchecked();
68-
try {
69-
runnable.run();
70-
Assertions.fail("Did expect an exception.");
71-
} catch(Error x) {
72-
// ok!
73-
}
68+
Assertions.assertThrows(Error.class, () -> runnable.run());
7469
}
7570
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package linter;
2+
3+
import com.tngtech.archunit.core.domain.JavaClass;
4+
import com.tngtech.archunit.core.importer.ClassFileImporter;
5+
import com.tngtech.archunit.core.importer.ImportOption;
6+
import com.tngtech.archunit.lang.ArchCondition;
7+
import com.tngtech.archunit.lang.ArchRule;
8+
import com.tngtech.archunit.lang.ConditionEvents;
9+
import com.tngtech.archunit.lang.SimpleConditionEvent;
10+
import org.junit.jupiter.api.Test;
11+
12+
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
13+
14+
public class PackageDepthTest {
15+
@Test
16+
void maxTwo() {
17+
classes()
18+
.should(havePackageDepthLessThanOrEqualTo(1 + 2))
19+
.check(new ClassFileImporter()
20+
.withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS)
21+
.importPackages("io.vavr"));
22+
}
23+
24+
private static ArchCondition<JavaClass> havePackageDepthLessThanOrEqualTo(int maxDepth) {
25+
return new ArchCondition<JavaClass>("have a package depth of " + maxDepth + " or less") {
26+
@Override
27+
public void check(JavaClass item, ConditionEvents events) {
28+
int depth = item.getPackageName().split("\\.").length;
29+
if (depth > maxDepth) {
30+
String message = String.format(
31+
"Class %s has a package depth of %d, which exceeds the allowed maximum of %d",
32+
item.getName(), depth, maxDepth
33+
);
34+
events.add(SimpleConditionEvent.violated(item, message));
35+
}
36+
}
37+
};
38+
}
39+
}

0 commit comments

Comments
 (0)