archrule to disallow JUnit 4, dependency exclude not possible as it's still needed for testcontainers

This commit is contained in:
Michael Hoennig 2022-08-23 14:31:54 +02:00
parent 3de8b00672
commit 661f23e1e2
2 changed files with 10 additions and 2 deletions

View File

@ -81,6 +81,14 @@ public class ArchUnitTest {
org.springframework.transaction.annotation.Transactional.class.getName(),
javax.transaction.Transactional.class.getName()));
@ArchTest
@SuppressWarnings("unused")
public static final ArchRule doNotUseOrgJUnitTestAnnotation = noMethods()
.should().beAnnotatedWith(org.junit.Test.class)
.as("Use @%s instead of @%s." .formatted(
org.junit.jupiter.api.Test.class.getName(),
org.junit.Test.class.getName()));
@Test
public void everythingShouldBeFreeOfCycles() {
slices().matching("net.hostsharing.hsadminng.(*)..").should().beFreeOfCycles();

View File

@ -1,6 +1,5 @@
package net.hostsharing.test;
import junit.framework.AssertionFailedError;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.NestedExceptionUtils;
import org.springframework.stereotype.Service;
@ -115,7 +114,8 @@ public class JpaAttempt {
if (expectedExceptionClass.isAssignableFrom(exception.getClass())) {
return (E) exception;
}
throw new AssertionFailedError("expected " + expectedExceptionClass + " but got " + exception);
fail("");
throw new AssertionError("expected " + expectedExceptionClass + " but got " + exception);
}
public Throwable caughtExceptionsRootCause() {