Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions spring-boot-project/spring-boot-autoconfigure/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ dependencies {
testImplementation("com.querydsl:querydsl-core")
testImplementation("com.squareup.okhttp3:mockwebserver")
testImplementation("com.sun.xml.messaging.saaj:saaj-impl")
testImplementation("com.tngtech.archunit:archunit-junit5:0.22.0")
testImplementation("io.projectreactor:reactor-test")
testImplementation("io.r2dbc:r2dbc-h2")
testImplementation("jakarta.json:jakarta.json-api")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
* @author Brian Clozel
*/
@ControllerAdvice
final class ProblemDetailsExceptionHandler extends ResponseEntityExceptionHandler {
class ProblemDetailsExceptionHandler extends ResponseEntityExceptionHandler {

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
* @author Brian Clozel
*/
@ControllerAdvice
final class ProblemDetailsExceptionHandler extends ResponseEntityExceptionHandler {
class ProblemDetailsExceptionHandler extends ResponseEntityExceptionHandler {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.boot.autoconfigure;

import com.tngtech.archunit.core.importer.ImportOption;
import com.tngtech.archunit.core.importer.Location;

import java.util.regex.Pattern;

/**
* @author Volkan Yazıcı
*/
public final class SpringArchUnitTests {

public static final class ExcludeTestsOption implements ImportOption {

@Override
public boolean includes(Location location) {
return !location.matches(Pattern.compile(".*Tests\\.class"));
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.boot.autoconfigure.web.reactive;

import com.tngtech.archunit.core.domain.JavaClasses;
import com.tngtech.archunit.core.domain.JavaModifier;
import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.lang.syntax.ArchRuleDefinition;
import org.springframework.boot.autoconfigure.SpringArchUnitTests;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.web.reactive.result.method.annotation.ResponseEntityExceptionHandler;

import java.util.List;

import static com.tngtech.archunit.base.DescribedPredicate.greaterThanOrEqualTo;

/**
* Tests for {@link ProblemDetailsExceptionHandler} using {@link SpringBootTest}.
*
* @author Volkan Yazıcı
*/
@AnalyzeClasses(packages = "org.springframework.boot.autoconfigure.web.reactive",
importOptions = SpringArchUnitTests.ExcludeTestsOption.class)
class ResponseEntityExceptionHandlerTests {

@ArchTest
void exceptionHandlerShouldNotBeFinal(JavaClasses classes) { // gh-34426
int minMatchingClassCount = List.of(ProblemDetailsExceptionHandler.class).size();
ArchRuleDefinition.classes()
.that()
.areAssignableTo(ResponseEntityExceptionHandler.class)
.should()
// Ensure we are not working against an empty set:
.containNumberOfElements(greaterThanOrEqualTo(minMatchingClassCount))
// Avoid `final` modifiers:
.andShould()
.notHaveModifier(JavaModifier.FINAL)
.check(classes);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.boot.autoconfigure.web.servlet;

import com.tngtech.archunit.core.domain.JavaClasses;
import com.tngtech.archunit.core.domain.JavaModifier;
import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.lang.syntax.ArchRuleDefinition;
import org.springframework.boot.autoconfigure.SpringArchUnitTests;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.web.reactive.result.method.annotation.ResponseEntityExceptionHandler;

import java.util.List;

import static com.tngtech.archunit.base.DescribedPredicate.greaterThanOrEqualTo;

/**
* Tests for {@link ProblemDetailsExceptionHandler} using {@link SpringBootTest}.
*
* @author Volkan Yazıcı
*/
@AnalyzeClasses(packages = "org.springframework.boot.autoconfigure.web.servlet",
importOptions = SpringArchUnitTests.ExcludeTestsOption.class)
class ResponseEntityExceptionHandlerTests {

@ArchTest
void exceptionHandlerShouldNotBeFinal(JavaClasses classes) { // gh-34426
int minMatchingClassCount = List.of(ProblemDetailsExceptionHandler.class).size();
ArchRuleDefinition.classes()
.that()
.areAssignableTo(ResponseEntityExceptionHandler.class)
.should()
// Ensure we are not working against an empty set:
.containNumberOfElements(greaterThanOrEqualTo(minMatchingClassCount))
// Avoid `final` modifiers:
.andShould()
.notHaveModifier(JavaModifier.FINAL)
.check(classes);
}

}