better tests style

This commit is contained in:
2025-07-20 07:45:43 +02:00
parent ee88dc9ff5
commit d694822761

View File

@@ -2,7 +2,6 @@ package click.kamil.springstatemachineexporter.ast.in;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@@ -98,7 +97,7 @@ class AstFileFinderTest {
@Test @Test
void shouldReturnTrue_whenClassHasMatchingAnnotation() { void shouldReturnTrue_whenClassHasMatchingAnnotation() {
AstFileFinder finder = new AstFileFinder(CLASS_WITH_ANNOTATION); AstFileFinder finder = new AstFileFinder(CLASS_WITH_ANNOTATION);
List<String> annotationNames = Arrays.asList("Service"); List<String> annotationNames = List.of("Service");
boolean result = finder.hasClassWithAnnotation(CLASS_WITH_ANNOTATION, annotationNames); boolean result = finder.hasClassWithAnnotation(CLASS_WITH_ANNOTATION, annotationNames);
@@ -108,7 +107,7 @@ class AstFileFinderTest {
@Test @Test
void shouldReturnTrue_whenClassHasMultipleMatchingAnnotations() { void shouldReturnTrue_whenClassHasMultipleMatchingAnnotations() {
AstFileFinder finder = new AstFileFinder(CLASS_WITH_MULTIPLE_ANNOTATIONS); AstFileFinder finder = new AstFileFinder(CLASS_WITH_MULTIPLE_ANNOTATIONS);
List<String> annotationNames = Arrays.asList("Service", "Component"); List<String> annotationNames = List.of("Service", "Component");
boolean result = finder.hasClassWithAnnotation(CLASS_WITH_MULTIPLE_ANNOTATIONS, annotationNames); boolean result = finder.hasClassWithAnnotation(CLASS_WITH_MULTIPLE_ANNOTATIONS, annotationNames);
@@ -118,7 +117,7 @@ class AstFileFinderTest {
@Test @Test
void shouldReturnFalse_whenClassHasNoAnnotation() { void shouldReturnFalse_whenClassHasNoAnnotation() {
AstFileFinder finder = new AstFileFinder(CLASS_WITHOUT_ANNOTATION); AstFileFinder finder = new AstFileFinder(CLASS_WITHOUT_ANNOTATION);
List<String> annotationNames = Arrays.asList("Service"); List<String> annotationNames = List.of("Service");
boolean result = finder.hasClassWithAnnotation(CLASS_WITHOUT_ANNOTATION, annotationNames); boolean result = finder.hasClassWithAnnotation(CLASS_WITHOUT_ANNOTATION, annotationNames);
@@ -128,7 +127,7 @@ class AstFileFinderTest {
@Test @Test
void shouldReturnFalse_whenClassHasDifferentAnnotation() { void shouldReturnFalse_whenClassHasDifferentAnnotation() {
AstFileFinder finder = new AstFileFinder(CLASS_WITH_DIFFERENT_ANNOTATION); AstFileFinder finder = new AstFileFinder(CLASS_WITH_DIFFERENT_ANNOTATION);
List<String> annotationNames = Arrays.asList("Service"); List<String> annotationNames = List.of("Service");
boolean result = finder.hasClassWithAnnotation(CLASS_WITH_DIFFERENT_ANNOTATION, annotationNames); boolean result = finder.hasClassWithAnnotation(CLASS_WITH_DIFFERENT_ANNOTATION, annotationNames);
@@ -138,7 +137,7 @@ class AstFileFinderTest {
@Test @Test
void shouldReturnTrue_whenClassHasFullyQualifiedAnnotation() { void shouldReturnTrue_whenClassHasFullyQualifiedAnnotation() {
AstFileFinder finder = new AstFileFinder(CLASS_WITH_FULLY_QUALIFIED_ANNOTATION); AstFileFinder finder = new AstFileFinder(CLASS_WITH_FULLY_QUALIFIED_ANNOTATION);
List<String> annotationNames = Arrays.asList("org.springframework.stereotype.Service"); List<String> annotationNames = List.of("org.springframework.stereotype.Service");
boolean result = finder.hasClassWithAnnotation(CLASS_WITH_FULLY_QUALIFIED_ANNOTATION, annotationNames); boolean result = finder.hasClassWithAnnotation(CLASS_WITH_FULLY_QUALIFIED_ANNOTATION, annotationNames);
@@ -148,7 +147,7 @@ class AstFileFinderTest {
@Test @Test
void shouldReturnTrue_whenMultipleClassesAndOneHasAnnotation() { void shouldReturnTrue_whenMultipleClassesAndOneHasAnnotation() {
AstFileFinder finder = new AstFileFinder(MULTIPLE_CLASSES); AstFileFinder finder = new AstFileFinder(MULTIPLE_CLASSES);
List<String> annotationNames = Arrays.asList("Service"); List<String> annotationNames = List.of("Service");
boolean result = finder.hasClassWithAnnotation(MULTIPLE_CLASSES, annotationNames); boolean result = finder.hasClassWithAnnotation(MULTIPLE_CLASSES, annotationNames);
@@ -158,7 +157,7 @@ class AstFileFinderTest {
@Test @Test
void shouldReturnFalse_whenInterfaceHasAnnotation() { void shouldReturnFalse_whenInterfaceHasAnnotation() {
AstFileFinder finder = new AstFileFinder(INTERFACE_WITH_ANNOTATION); AstFileFinder finder = new AstFileFinder(INTERFACE_WITH_ANNOTATION);
List<String> annotationNames = Arrays.asList("FunctionalInterface"); List<String> annotationNames = List.of("FunctionalInterface");
boolean result = finder.hasClassWithAnnotation(INTERFACE_WITH_ANNOTATION, annotationNames); boolean result = finder.hasClassWithAnnotation(INTERFACE_WITH_ANNOTATION, annotationNames);
@@ -178,7 +177,7 @@ class AstFileFinderTest {
@Test @Test
void shouldReturnFalse_whenEmptySource() { void shouldReturnFalse_whenEmptySource() {
AstFileFinder finder = new AstFileFinder(EMPTY_SOURCE); AstFileFinder finder = new AstFileFinder(EMPTY_SOURCE);
List<String> annotationNames = Arrays.asList("Service"); List<String> annotationNames = List.of("Service");
boolean result = finder.hasClassWithAnnotation(EMPTY_SOURCE, annotationNames); boolean result = finder.hasClassWithAnnotation(EMPTY_SOURCE, annotationNames);
@@ -198,7 +197,7 @@ class AstFileFinderTest {
@Test @Test
void shouldReturnTrue_whenClassHasAnnotationAndFields() { void shouldReturnTrue_whenClassHasAnnotationAndFields() {
AstFileFinder finder = new AstFileFinder(CLASS_WITH_ANNOTATION_AND_FIELDS); AstFileFinder finder = new AstFileFinder(CLASS_WITH_ANNOTATION_AND_FIELDS);
List<String> annotationNames = Arrays.asList("Service"); List<String> annotationNames = List.of("Service");
boolean result = finder.hasClassWithAnnotation(CLASS_WITH_ANNOTATION_AND_FIELDS, annotationNames); boolean result = finder.hasClassWithAnnotation(CLASS_WITH_ANNOTATION_AND_FIELDS, annotationNames);
@@ -208,7 +207,7 @@ class AstFileFinderTest {
@Test @Test
void shouldHandleInvalidJavaSyntax() { void shouldHandleInvalidJavaSyntax() {
AstFileFinder finder = new AstFileFinder(INVALID_JAVA_SYNTAX); AstFileFinder finder = new AstFileFinder(INVALID_JAVA_SYNTAX);
List<String> annotationNames = Arrays.asList("Service"); List<String> annotationNames = List.of("Service");
boolean result = finder.hasClassWithAnnotation(INVALID_JAVA_SYNTAX, annotationNames); boolean result = finder.hasClassWithAnnotation(INVALID_JAVA_SYNTAX, annotationNames);
@@ -220,7 +219,7 @@ class AstFileFinderTest {
@Test @Test
void shouldReturnTrue_whenAnnotationNameMatchesCaseInsensitive() { void shouldReturnTrue_whenAnnotationNameMatchesCaseInsensitive() {
AstFileFinder finder = new AstFileFinder(CLASS_WITH_ANNOTATION); AstFileFinder finder = new AstFileFinder(CLASS_WITH_ANNOTATION);
List<String> annotationNames = Arrays.asList("service"); // lowercase List<String> annotationNames = List.of("service"); // lowercase
boolean result = finder.hasClassWithAnnotation(CLASS_WITH_ANNOTATION, annotationNames); boolean result = finder.hasClassWithAnnotation(CLASS_WITH_ANNOTATION, annotationNames);
@@ -230,7 +229,7 @@ class AstFileFinderTest {
@Test @Test
void shouldReturnTrue_whenMultipleAnnotationNamesProvided() { void shouldReturnTrue_whenMultipleAnnotationNamesProvided() {
AstFileFinder finder = new AstFileFinder(CLASS_WITH_ANNOTATION); AstFileFinder finder = new AstFileFinder(CLASS_WITH_ANNOTATION);
List<String> annotationNames = Arrays.asList("Component", "Service", "Repository"); List<String> annotationNames = List.of("Component", "Service", "Repository");
boolean result = finder.hasClassWithAnnotation(CLASS_WITH_ANNOTATION, annotationNames); boolean result = finder.hasClassWithAnnotation(CLASS_WITH_ANNOTATION, annotationNames);
@@ -240,7 +239,7 @@ class AstFileFinderTest {
@Test @Test
void shouldReturnFalse_whenNoMatchingAnnotationNames() { void shouldReturnFalse_whenNoMatchingAnnotationNames() {
AstFileFinder finder = new AstFileFinder(CLASS_WITH_ANNOTATION); AstFileFinder finder = new AstFileFinder(CLASS_WITH_ANNOTATION);
List<String> annotationNames = Arrays.asList("Component", "Repository", "Controller"); List<String> annotationNames = List.of("Component", "Repository", "Controller");
boolean result = finder.hasClassWithAnnotation(CLASS_WITH_ANNOTATION, annotationNames); boolean result = finder.hasClassWithAnnotation(CLASS_WITH_ANNOTATION, annotationNames);
@@ -255,7 +254,7 @@ class AstFileFinderTest {
/** JavaDoc comment */ /** JavaDoc comment */
"""; """;
AstFileFinder finder = new AstFileFinder(sourceWithComments); AstFileFinder finder = new AstFileFinder(sourceWithComments);
List<String> annotationNames = Arrays.asList("Service"); List<String> annotationNames = List.of("Service");
boolean result = finder.hasClassWithAnnotation(sourceWithComments, annotationNames); boolean result = finder.hasClassWithAnnotation(sourceWithComments, annotationNames);
@@ -266,7 +265,7 @@ class AstFileFinderTest {
void shouldReturnFalse_whenSourceContainsOnlyPackageDeclaration() { void shouldReturnFalse_whenSourceContainsOnlyPackageDeclaration() {
String sourceWithPackage = "package com.example;"; String sourceWithPackage = "package com.example;";
AstFileFinder finder = new AstFileFinder(sourceWithPackage); AstFileFinder finder = new AstFileFinder(sourceWithPackage);
List<String> annotationNames = Arrays.asList("Service"); List<String> annotationNames = List.of("Service");
boolean result = finder.hasClassWithAnnotation(sourceWithPackage, annotationNames); boolean result = finder.hasClassWithAnnotation(sourceWithPackage, annotationNames);
@@ -284,7 +283,7 @@ class AstFileFinderTest {
} }
"""; """;
AstFileFinder finder = new AstFileFinder(classWithAnnotatedParams); AstFileFinder finder = new AstFileFinder(classWithAnnotatedParams);
List<String> annotationNames = Arrays.asList("Service"); List<String> annotationNames = List.of("Service");
boolean result = finder.hasClassWithAnnotation(classWithAnnotatedParams, annotationNames); boolean result = finder.hasClassWithAnnotation(classWithAnnotatedParams, annotationNames);
@@ -294,7 +293,7 @@ class AstFileFinderTest {
@Test @Test
void shouldReturnFalse_whenAnnotationListContainsNull() { void shouldReturnFalse_whenAnnotationListContainsNull() {
AstFileFinder finder = new AstFileFinder(CLASS_WITH_ANNOTATION); AstFileFinder finder = new AstFileFinder(CLASS_WITH_ANNOTATION);
List<String> annotationNames = Arrays.asList("Service", null, "Component"); List<String> annotationNames = List.of("Service", null, "Component");
boolean result = finder.hasClassWithAnnotation(CLASS_WITH_ANNOTATION, annotationNames); boolean result = finder.hasClassWithAnnotation(CLASS_WITH_ANNOTATION, annotationNames);