Skip to content

Commit 865987c

Browse files
committed
chore: Improve unit test coverage
1 parent 3a4a81d commit 865987c

2 files changed

Lines changed: 8 additions & 34 deletions

File tree

src/test/java/dev/dochia/cli/core/generator/format/impl/LatLongGeneratorTest.java

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package dev.dochia.cli.core.generator.format.impl;
22

3+
import dev.dochia.cli.core.util.DochiaRandom;
34
import io.quarkus.test.junit.QuarkusTest;
45
import io.swagger.v3.oas.models.media.Schema;
56
import org.junit.jupiter.api.BeforeEach;
@@ -16,6 +17,7 @@ class LatLongGeneratorTest {
1617

1718
@BeforeEach
1819
void setup() {
20+
DochiaRandom.initRandom(0);
1921
latLongGenerator = new LatLongGenerator();
2022
}
2123

@@ -58,50 +60,22 @@ void shouldReturnMatchingFormats() {
5860
.containsExactly("latlong", "latlng", "coordinate", "coordinates", "latitude", "longitude");
5961
}
6062

61-
@Test
62-
void shouldGenerateLatitudeWhenSchemaNameContainsLat() {
63-
Schema<String> schema = new Schema<>();
64-
schema.setName("latitude");
65-
66-
String generated = (String) latLongGenerator.generate(schema);
67-
68-
assertThat(generated).isNotNull()
69-
.matches("-?\\d+\\.\\d{6}")
70-
.satisfies(s -> {
71-
double val = Double.parseDouble(s);
72-
assertThat(val).isBetween(-90.0, 90.0);
73-
});
74-
}
75-
76-
@Test
77-
void shouldGenerateLongitudeWhenSchemaNameContainsLon() {
63+
@ParameterizedTest
64+
@CsvSource({"latitude,-90.0,90.0", "longitude,-180.0,180.0", "lng,-180.0,180.0"})
65+
void shouldGenerateLatitudeWhenSchemaNameContainsLat(String schemaName, Double min, Double max) {
7866
Schema<String> schema = new Schema<>();
79-
schema.setName("longitude");
67+
schema.setName(schemaName);
8068

8169
String generated = (String) latLongGenerator.generate(schema);
8270

8371
assertThat(generated).isNotNull()
8472
.matches("-?\\d+\\.\\d{6}")
8573
.satisfies(s -> {
8674
double val = Double.parseDouble(s);
87-
assertThat(val).isBetween(-180.0, 180.0);
75+
assertThat(val).isBetween(min, max);
8876
});
8977
}
9078

91-
@Test
92-
void shouldGenerateLongitudeWhenSchemaNameContainsLng() {
93-
Schema<String> schema = new Schema<>();
94-
schema.setName("lng");
95-
96-
String generated = (String) latLongGenerator.generate(schema);
97-
98-
assertThat(generated).isNotNull()
99-
.matches("-?\\d+\\.\\d{6}")
100-
.satisfies(s -> {
101-
double val = Double.parseDouble(s);
102-
assertThat(val).isBetween(-180.0, 180.0);
103-
});
104-
}
10579

10680
@Test
10781
void shouldGenerateCoordinatePairWhenSchemaIsNull() {

src/test/java/dev/dochia/cli/core/http/ResponseCodeFamilyDynamicTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void shouldBeEqualToItself() {
9696
void shouldHaveConsistentHashCode() {
9797
ResponseCodeFamilyDynamic family = new ResponseCodeFamilyDynamic(List.of("200", "201"));
9898

99-
assertThat(family.hashCode()).isEqualTo(family.hashCode());
99+
assertThat(family).hasSameHashCodeAs(family);
100100
}
101101

102102
@Test

0 commit comments

Comments
 (0)