Skip to content

Commit 8fa5e88

Browse files
sam0r040timonback
andauthored
chore: replace all junit assertions with assertj assertions (#1469)
* chore: replace all junit assertions with assertj assertions Co-authored-by: Timon Back <timonback@users.noreply.github.com> * chore: configure linting with spotless to disallow Junit assertions Co-authored-by: Timon Back <timonback@users.noreply.github.com> --------- Co-authored-by: Timon Back <timonback@users.noreply.github.com>
1 parent 00e80bf commit 8fa5e88

File tree

136 files changed

+762
-849
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+762
-849
lines changed

build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ allprojects {
8181
licenseHeader("// SPDX-License-Identifier: Apache-2.0", "package|import|public")
8282

8383
importOrder('', 'javax', 'java', '\\#')
84-
replaceRegex("Remove wildcard imports", "import( static)?\\s+[^*\\s]+\\*;(\\r\\n|\\r|\\n)", "\$2")
84+
8585
removeUnusedImports()
86+
forbidWildcardImports()
87+
forbidRegex("ForbidJunitAssertions", ".*org.junit.jupiter.api.Assertions.*", "Replace Junit assertions with AssertJ assertThat()")
8688

8789
trimTrailingWhitespace()
8890
endWithNewline()

springwolf-add-ons/springwolf-common-model-converters/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ dependencies {
2222

2323
implementation libs.money.api
2424

25+
testImplementation libs.assertj.core
2526
testImplementation libs.junit.jupiter.api
2627
testRuntimeOnly libs.junit.jupiter
2728
testRuntimeOnly libs.junit.plattform.launcher

springwolf-add-ons/springwolf-common-model-converters/src/test/java/io/github/springwolf/addons/common_model_converters/converters/enums/NameInReffedSchemaModelConverterTest.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88
import java.util.Map;
99

10-
import static org.junit.jupiter.api.Assertions.assertEquals;
11-
import static org.junit.jupiter.api.Assertions.assertNotNull;
10+
import static org.assertj.core.api.Assertions.assertThat;
1211

1312
class NameInReffedSchemaModelConverterTest {
1413

@@ -17,26 +16,26 @@ class NameInReffedSchemaModelConverterTest {
1716
private final ModelConverters converters = new ModelConverters();
1817

1918
@Test
20-
void testNameIsAddedToReffedSchema() {
19+
void nameIsAddedToReffedSchema() {
2120
// given
2221
converters.addConverter(modelsConverter);
2322

2423
// when
2524
final Map<String, Schema> models = converters.readAll(MyRootObject.class);
2625

2726
// then
28-
assertNotNull(models);
29-
assertEquals(2, models.size());
27+
assertThat(models).isNotNull();
28+
assertThat(models.size()).isEqualTo(2);
3029
Schema myRootObject = models.get("MyRootObject");
31-
assertNotNull(myRootObject);
32-
assertEquals("MyRootObject", myRootObject.getName());
30+
assertThat(myRootObject).isNotNull();
31+
assertThat(myRootObject.getName()).isEqualTo("MyRootObject");
3332
Schema myEnumObjectField = (Schema) myRootObject.getProperties().get("myEnumObjectField");
34-
assertEquals("myEnumObjectField", myEnumObjectField.getName());
35-
assertEquals("#/components/schemas/MyEnumObject", myEnumObjectField.get$ref());
33+
assertThat(myEnumObjectField.getName()).isEqualTo("myEnumObjectField");
34+
assertThat(myEnumObjectField.get$ref()).isEqualTo("#/components/schemas/MyEnumObject");
3635

3736
Schema myEnumObject = models.get("MyEnumObject");
38-
assertNotNull(myEnumObject);
39-
assertEquals("MyEnumObject", myEnumObject.getName());
37+
assertThat(myEnumObject).isNotNull();
38+
assertThat(myEnumObject.getName()).isEqualTo("MyEnumObject");
4039
}
4140

4241
@io.swagger.v3.oas.annotations.media.Schema(enumAsRef = true)

springwolf-add-ons/springwolf-common-model-converters/src/test/java/io/github/springwolf/addons/common_model_converters/converters/monetaryamount/MonetaryAmountConverterTest.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88

99
import java.util.Map;
1010

11-
import static org.junit.jupiter.api.Assertions.assertEquals;
12-
import static org.junit.jupiter.api.Assertions.assertNotNull;
13-
import static org.junit.jupiter.api.Assertions.assertNull;
11+
import static org.assertj.core.api.Assertions.assertThat;
1412

1513
class MonetaryAmountConverterTest {
1614

@@ -19,7 +17,7 @@ class MonetaryAmountConverterTest {
1917
private final ModelConverters converters = new ModelConverters();
2018

2119
@Test
22-
void testMonetaryAmountConverter() {
20+
void monetaryAmountConverter() {
2321
// given
2422
converters.addConverter(modelsConverter);
2523

@@ -28,24 +26,24 @@ void testMonetaryAmountConverter() {
2826

2927
// then
3028
final Schema model = models.get("MonetaryAmount");
31-
assertNotNull(model);
29+
assertThat(model).isNotNull();
3230

33-
assertEquals(2, model.getProperties().size());
31+
assertThat(model.getProperties().size()).isEqualTo(2);
3432

3533
final Schema amountProperty = (Schema) model.getProperties().get("amount");
36-
assertNotNull(amountProperty);
34+
assertThat(amountProperty).isNotNull();
3735

3836
final Schema currencyProperty = (Schema) model.getProperties().get("currency");
39-
assertNotNull(currencyProperty);
37+
assertThat(currencyProperty).isNotNull();
4038

4139
final Schema missingProperty = (Schema) model.getProperties().get("missing");
42-
assertNull(missingProperty);
40+
assertThat(missingProperty).isNull();
4341

4442
// then
4543
final Schema originalModel = models.get("javax.money.MonetaryAmount");
46-
assertNotNull(originalModel);
44+
assertThat(originalModel).isNotNull();
4745

48-
assertNull(originalModel.getType());
49-
assertEquals("#/components/schemas/MonetaryAmount", originalModel.get$ref());
46+
assertThat(originalModel.getType()).isNull();
47+
assertThat(originalModel.get$ref()).isEqualTo("#/components/schemas/MonetaryAmount");
5048
}
5149
}

springwolf-add-ons/springwolf-generic-binding/src/test/java/io/github/springwolf/addons/generic_binding/annotation/processor/AsyncGenericOperationBindingProcessorTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import org.junit.jupiter.api.Nested;
77
import org.junit.jupiter.api.Test;
88
import org.junit.jupiter.params.ParameterizedTest;
9-
import org.junit.jupiter.params.provider.CsvSource;
9+
import org.junit.jupiter.params.provider.ValueSource;
1010
import org.springframework.util.StringValueResolver;
1111

1212
import java.util.Arrays;
@@ -23,7 +23,7 @@ class AsyncGenericOperationBindingProcessorTest {
2323
new AsyncGenericOperationBindingProcessor(stringValueResolver);
2424

2525
@Test
26-
void testClassWithoutAnnotation() {
26+
void classWithoutAnnotation() {
2727
// when
2828
List<ProcessedOperationBinding> result = getProcessedOperationBindings(ClassWithoutAnnotation.class);
2929

@@ -32,7 +32,7 @@ void testClassWithoutAnnotation() {
3232
}
3333

3434
@Test
35-
void testClassWithAnnotationHasABinding() {
35+
void classWithAnnotationHasABinding() {
3636
// when
3737
List<ProcessedOperationBinding> result = getProcessedOperationBindings(ClassWithAnnotation.class);
3838

@@ -130,7 +130,7 @@ void arrayPropertyTest() {
130130
assertThat(result).isEqualTo(Map.of("key", List.of("value1", "value2", "value3 is long")));
131131
}
132132

133-
@CsvSource(value = {"asdf[sdf]", "[sdf][sdf]", "[sd[sdf]]", "[kdkd]dkkd", "[kdkd"})
133+
@ValueSource(strings = {"asdf[sdf]", "[sdf][sdf]", "[sd[sdf]]", "[kdkd]dkkd", "[kdkd"})
134134
@ParameterizedTest
135135
void arrayParsingShouldBeIgnored(String value) {
136136
// given

springwolf-add-ons/springwolf-json-schema/src/test/java/io/github/springwolf/addons/json_schema/JsonSchemaCustomizerTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// SPDX-License-Identifier: Apache-2.0
22
package io.github.springwolf.addons.json_schema;
33

4-
import com.fasterxml.jackson.core.JsonProcessingException;
54
import io.github.springwolf.asyncapi.v3.model.AsyncAPI;
65
import io.github.springwolf.asyncapi.v3.model.components.ComponentSchema;
76
import io.github.springwolf.asyncapi.v3.model.components.Components;
@@ -29,7 +28,7 @@ void setUp() {
2928
}
3029

3130
@Test
32-
public void handleEmptySchemaTest() {
31+
void handleEmptySchemaTest() {
3332
// given
3433
AsyncAPI asyncAPI = createAsyncApi();
3534

@@ -41,7 +40,7 @@ public void handleEmptySchemaTest() {
4140
}
4241

4342
@Test
44-
public void shouldAddJsonSchemaExtensionTest() throws JsonProcessingException {
43+
void shouldAddJsonSchemaExtensionTest() throws Exception {
4544
// given
4645
AsyncAPI asyncAPI = createAsyncApi();
4746
SchemaObject schemaObject = new SchemaObject();

springwolf-add-ons/springwolf-json-schema/src/test/java/io/github/springwolf/addons/json_schema/JsonSchemaGeneratorTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.junit.jupiter.params.provider.Arguments;
2525
import org.junit.jupiter.params.provider.MethodSource;
2626

27-
import java.io.IOException;
2827
import java.math.BigDecimal;
2928
import java.util.List;
3029
import java.util.Map;
@@ -41,8 +40,7 @@ class JsonSchemaGeneratorTest {
4140

4241
@ParameterizedTest
4342
@MethodSource
44-
public void validateJsonSchemaTest(String expectedJsonSchema, Supplier<Schema<?>> asyncApiSchema)
45-
throws IOException {
43+
void validateJsonSchemaTest(String expectedJsonSchema, Supplier<Schema<?>> asyncApiSchema) throws Exception {
4644
// given
4745
SchemaObject actualSchema = swaggerSchemaUtil.mapSchema(asyncApiSchema.get());
4846

springwolf-add-ons/springwolf-kotlinx-serialization-model-converter/src/test/java/io/github/springwolf/addons/kotlinx_serialization_model_converter/converter/KotlinxSerializationTypeConverterTest.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
import org.junit.jupiter.api.Nested;
1313
import org.junit.jupiter.api.Test;
1414

15-
import java.io.IOException;
16-
1715
import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
1816
import static org.assertj.core.api.Assertions.assertThat;
1917

@@ -31,7 +29,7 @@ void setUp() {
3129
}
3230

3331
@Test
34-
void validateGeneratedJson() throws IOException {
32+
void validateGeneratedJson() throws Exception {
3533
final KotlinxSerializationModelConverter modelConverter = new KotlinxSerializationModelConverter();
3634
final ModelConverters converters = new ModelConverters();
3735
converters.addConverter(modelConverter);
@@ -43,7 +41,7 @@ void validateGeneratedJson() throws IOException {
4341
}
4442

4543
@Test
46-
void validateGeneratedFqnJson() throws IOException {
44+
void validateGeneratedFqnJson() throws Exception {
4745
final KotlinxSerializationModelConverter modelConverter = new KotlinxSerializationModelConverter(true);
4846
final ModelConverters converters = new ModelConverters();
4947
converters.addConverter(modelConverter);
@@ -57,7 +55,7 @@ void validateGeneratedFqnJson() throws IOException {
5755
@Nested
5856
class TestListProperty {
5957
@Test
60-
void testClassWithListProperty() {
58+
void classWithListProperty() {
6159
var result = modelConverters.readAll(new AnnotatedType(ClassWithListProperty.class));
6260
Schema<?> schema = result.get(ClassWithListProperty.class.getSimpleName());
6361

@@ -70,7 +68,7 @@ void testClassWithListProperty() {
7068
}
7169

7270
@Test
73-
void testClassWithCollectionProperty() {
71+
void classWithCollectionProperty() {
7472
var result = modelConverters.readAll(new AnnotatedType(ClassWithCollectionProperty.class));
7573
Schema<?> schema = result.get(ClassWithCollectionProperty.class.getSimpleName());
7674

@@ -86,7 +84,7 @@ void testClassWithCollectionProperty() {
8684
@Nested
8785
class TestSetProperty {
8886
@Test
89-
void testClassWithSetProperty() {
87+
void classWithSetProperty() {
9088
var result = modelConverters.readAll(new AnnotatedType(ClassWithSetProperty.class));
9189
Schema<?> schema = result.get(ClassWithSetProperty.class.getSimpleName());
9290

@@ -103,7 +101,7 @@ void testClassWithSetProperty() {
103101
@Nested
104102
class TestEnumProperty {
105103
@Test
106-
void testClassWithEnumProperty() {
104+
void classWithEnumProperty() {
107105
var result = modelConverters.readAll(new AnnotatedType(ClassWithEnumProperty.class));
108106
Schema<?> schema = result.get(ClassWithEnumProperty.class.getSimpleName());
109107

@@ -120,7 +118,7 @@ void testClassWithEnumProperty() {
120118
@Nested
121119
class TestNestedClass {
122120
@Test
123-
void testClassWithNestedProperty() {
121+
void classWithNestedProperty() {
124122
var result = modelConverters.readAll(new AnnotatedType(ClassWithNestedProperty.class));
125123
Schema<?> schema = result.get(ClassWithNestedProperty.class.getSimpleName());
126124

@@ -140,7 +138,7 @@ void testClassWithNestedProperty() {
140138
@Nested
141139
class TestSealedClass {
142140
@Test
143-
void testSealedClassSerialization() {
141+
void sealedClassSerialization() {
144142
var result = modelConverters.readAll(new AnnotatedType(ClassWithPolymorphism.class));
145143
assertThat(result).hasSize(3);
146144
assertThat(result.get(Dog.class.getSimpleName())).isNotNull();

springwolf-asyncapi/src/test/java/io/github/springwolf/asyncapi/v3/bindings/amqp/AMQPBindingTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import io.github.springwolf.asyncapi.v3.model.operation.Operation;
1111
import org.junit.jupiter.api.Test;
1212

13-
import java.io.IOException;
1413
import java.util.List;
1514
import java.util.Map;
1615

@@ -20,7 +19,7 @@ class AMQPBindingTest {
2019
private static final DefaultAsyncApiSerializerService serializer = new DefaultAsyncApiSerializerService();
2120

2221
@Test
23-
void shouldSerializeAMQPChannelBindingQueue() throws IOException {
22+
void shouldSerializeAMQPChannelBindingQueue() throws Exception {
2423

2524
var asyncapi = AsyncAPI.builder()
2625
.channels(Map.of(
@@ -49,7 +48,7 @@ void shouldSerializeAMQPChannelBindingQueue() throws IOException {
4948
}
5049

5150
@Test
52-
void shouldSerializeAMQPChannelBindingRouting() throws IOException {
51+
void shouldSerializeAMQPChannelBindingRouting() throws Exception {
5352

5453
var asyncapi = AsyncAPI.builder()
5554
.channels(Map.of(
@@ -78,7 +77,7 @@ void shouldSerializeAMQPChannelBindingRouting() throws IOException {
7877
}
7978

8079
@Test
81-
void shouldSerializeAMQPOperationBinding() throws IOException {
80+
void shouldSerializeAMQPOperationBinding() throws Exception {
8281

8382
var asyncapi = AsyncAPI.builder()
8483
.operations(Map.of(
@@ -111,7 +110,7 @@ void shouldSerializeAMQPOperationBinding() throws IOException {
111110
}
112111

113112
@Test
114-
void shouldSerializeAMQPMessageBinding() throws IOException {
113+
void shouldSerializeAMQPMessageBinding() throws Exception {
115114
var asyncapi = AsyncAPI.builder()
116115
.channels(Map.of(
117116
"userSignup",

springwolf-asyncapi/src/test/java/io/github/springwolf/asyncapi/v3/bindings/googlepubsub/GooglePubSubBindingTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import io.github.springwolf.asyncapi.v3.model.schema.MultiFormatSchema;
1212
import org.junit.jupiter.api.Test;
1313

14-
import java.io.IOException;
1514
import java.util.List;
1615
import java.util.Map;
1716

@@ -21,7 +20,7 @@ class GooglePubSubBindingTest {
2120
private static final DefaultAsyncApiSerializerService serializer = new DefaultAsyncApiSerializerService();
2221

2322
@Test
24-
void shouldSerializeGooglePubSubMessage() throws IOException {
23+
void shouldSerializeGooglePubSubMessage() throws Exception {
2524
var asyncapi = AsyncAPI.builder()
2625
.components(Components.builder()
2726
.messages(Map.of(
@@ -84,7 +83,7 @@ void shouldSerializeGooglePubSubMessage() throws IOException {
8483
}
8584

8685
@Test
87-
void shouldSerializeGooglePubSubChannel() throws IOException {
86+
void shouldSerializeGooglePubSubChannel() throws Exception {
8887
var asyncapi = AsyncAPI.builder()
8988
.channels(Map.of(
9089
"topic-avro-schema",

0 commit comments

Comments
 (0)