Skip to content

Commit 92273f7

Browse files
committed
fix review issues
1 parent 2090064 commit 92273f7

5 files changed

Lines changed: 32 additions & 50 deletions

File tree

src/main/java/it/aboutbits/springboot/testing/validation/core/RuleValidator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
* Then we check if an exception is raised.
2828
* We repeat this for each defined rule.
2929
* <p>
30-
* Additionally, we also check of @Valid or @Nullable is present where required according to the rules.
30+
* Additionally, we also check if @Valid or @Nullable is present where required according to the rules.
3131
* Also, we enforce that all properties must have at least one rule (with a rule existing that says "no-rule").
3232
* </p>
3333
*
34-
* @parameterUnderTest A valid parameter we can use as the basis for our mutations. Validation for the unmodified parameter MUST succeed.
34+
* @parameterUnderTest A valid parameter that we can use as the basis for our mutations. Validation for the unmodified parameter MUST succeed.
3535
* @functionToCallWithParameter Optional. Instead of directly using bean validation, we can also validate a real function call. This makes sure the parameter is actually annotated with @Valid as well and that the class is using @Validated.
3636
* @rules The list of rules to validate.
3737
* @nonBeanTypes This is a whitelist that holds classes that don't implicitly require @Valid. We assume that @Valid is required

src/main/java/it/aboutbits/springboot/testing/validation/source/BiggerThanValueSource.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ private static Stream<Integer> getIntegerStream(Object[] args) {
5454

5555
return Stream.concat(
5656
Stream.of(minValue, maxValue),
57-
RANDOM.ints(minValue, maxValue).limit(5).boxed()
57+
RANDOM.ints(minValue, maxValue).limit(1).boxed()
5858
);
5959
}
6060

@@ -65,7 +65,7 @@ private static Stream<Long> getLongStream(Object[] args) {
6565

6666
return Stream.concat(
6767
Stream.of(minValue, maxValue),
68-
RANDOM.longs(minValue, maxValue).limit(5).boxed()
68+
RANDOM.longs(minValue, maxValue).limit(1).boxed()
6969
);
7070
}
7171

@@ -76,7 +76,7 @@ private static Stream<Float> getFloatStream(Object[] args) {
7676

7777
return Stream.concat(
7878
Stream.of(minValue, maxValue),
79-
RANDOM.doubles(minValue, maxValue).limit(5).boxed().map(
79+
RANDOM.doubles(minValue, maxValue).limit(1).boxed().map(
8080
Double::floatValue
8181
)
8282
);
@@ -89,7 +89,7 @@ private static Stream<Double> getDoubleStream(Object[] args) {
8989

9090
return Stream.concat(
9191
Stream.of(minValue, maxValue),
92-
RANDOM.doubles(minValue, maxValue).limit(5).boxed()
92+
RANDOM.doubles(minValue, maxValue).limit(1).boxed()
9393
);
9494
}
9595

@@ -100,7 +100,7 @@ private static Stream<ScaledBigDecimal> getScaledBigDecimalStream(Object[] args)
100100

101101
return Stream.concat(
102102
Stream.of(ScaledBigDecimal.valueOf(minValue), ScaledBigDecimal.valueOf(maxValue)),
103-
RANDOM.doubles(minValue, maxValue).limit(5).boxed().map(ScaledBigDecimal::valueOf)
103+
RANDOM.doubles(minValue, maxValue).limit(1).boxed().map(ScaledBigDecimal::valueOf)
104104
);
105105
}
106106

@@ -111,7 +111,7 @@ private static Stream<BigDecimal> getBigDecimalStream(Object[] args) {
111111

112112
return Stream.concat(
113113
Stream.of(BigDecimal.valueOf(minValue), BigDecimal.valueOf(maxValue)),
114-
RANDOM.doubles(minValue, maxValue).limit(5).boxed().map(BigDecimal::valueOf)
114+
RANDOM.doubles(minValue, maxValue).limit(1).boxed().map(BigDecimal::valueOf)
115115
);
116116
}
117117
}

src/main/java/it/aboutbits/springboot/testing/validation/source/FutureValueSource.java

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,32 +36,23 @@ public <T> Stream<T> values(Class<T> propertyClass, Object... args) {
3636
}
3737

3838
private static Stream<LocalDate> getLocalDateStream(Object[] args) {
39-
var currentDate = LocalDate.now().plusDays(1);
39+
var currentDate = LocalDate.now();
4040
var largestDate = LocalDate.MAX;
41-
return Stream.concat(
42-
Stream.of(largestDate),
43-
Stream.iterate(currentDate, date -> date.plusDays(1))
44-
.limit(4)
45-
);
41+
42+
return Stream.of(currentDate.plusDays(1), largestDate);
4643
}
4744

4845
private static Stream<LocalDateTime> getLocalDatetimeStream(Object[] args) {
49-
var currentDateTime = LocalDateTime.now().plusDays(1);
46+
var currentDateTime = LocalDateTime.now();
5047
var largestDateTime = LocalDateTime.MAX;
51-
return Stream.concat(
52-
Stream.of(largestDateTime, currentDateTime.plusSeconds(1)),
53-
Stream.iterate(currentDateTime, dateTime -> dateTime.plusHours(1))
54-
.limit(4)
55-
);
48+
49+
return Stream.of(currentDateTime.plusSeconds(1), largestDateTime);
5650
}
5751

5852
private static Stream<OffsetDateTime> getOffsetDateTimeStream(Object[] args) {
59-
var currentOffsetDateTime = OffsetDateTime.now(ZoneOffset.UTC).plusDays(1);
53+
var currentOffsetDateTime = OffsetDateTime.now(ZoneOffset.UTC);
6054
var largestOffsetDateTime = OffsetDateTime.MAX;
61-
return Stream.concat(
62-
Stream.of(largestOffsetDateTime, currentOffsetDateTime.plusSeconds(1)),
63-
Stream.iterate(currentOffsetDateTime, offsetDateTime -> offsetDateTime.plusHours(1))
64-
.limit(2)
65-
);
55+
56+
return Stream.of(currentOffsetDateTime.plusSeconds(1), largestOffsetDateTime);
6657
}
6758
}

src/main/java/it/aboutbits/springboot/testing/validation/source/LessThanValueSource.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private static Stream<Integer> getIntegerStream(Object[] args) {
5555

5656
return Stream.concat(
5757
Stream.of(minValue, maxValue),
58-
RANDOM.ints(minValue, maxValue).limit(5).boxed()
58+
RANDOM.ints(minValue, maxValue).limit(1).boxed()
5959
);
6060
}
6161

@@ -66,7 +66,7 @@ private static Stream<Long> getLongStream(Object[] args) {
6666

6767
return Stream.concat(
6868
Stream.of(minValue, maxValue),
69-
RANDOM.longs(minValue, maxValue).limit(5).boxed()
69+
RANDOM.longs(minValue, maxValue).limit(1).boxed()
7070
);
7171
}
7272

@@ -77,7 +77,7 @@ private static Stream<Float> getFloatStream(Object[] args) {
7777

7878
return Stream.concat(
7979
Stream.of(minValue, maxValue),
80-
RANDOM.doubles(5).map(d -> minValue + (maxValue - minValue) * d).boxed().map(
80+
RANDOM.doubles(1).map(d -> minValue + (maxValue - minValue) * d).boxed().map(
8181
Double::floatValue
8282
)
8383
);
@@ -90,7 +90,7 @@ private static Stream<Double> getDoubleStream(Object[] args) {
9090

9191
return Stream.concat(
9292
Stream.of(minValue, maxValue),
93-
RANDOM.doubles(5).map(d -> minValue + (maxValue - minValue) * d).boxed()
93+
RANDOM.doubles(1).map(d -> minValue + (maxValue - minValue) * d).boxed()
9494
);
9595
}
9696

@@ -101,7 +101,7 @@ private static Stream<BigDecimal> getBigDecimalStream(Object[] args) {
101101

102102
return Stream.concat(
103103
Stream.of(BigDecimal.valueOf(minValue), BigDecimal.valueOf(maxValue)),
104-
RANDOM.doubles(5).map(d -> minValue + (maxValue - minValue) * d).boxed().map(BigDecimal::valueOf)
104+
RANDOM.doubles(1).map(d -> minValue + (maxValue - minValue) * d).boxed().map(BigDecimal::valueOf)
105105
);
106106
}
107107

@@ -112,7 +112,7 @@ private static Stream<ScaledBigDecimal> getScaledBigDecimalStream(Object[] args)
112112

113113
return Stream.concat(
114114
Stream.of(ScaledBigDecimal.valueOf(minValue), ScaledBigDecimal.valueOf(maxValue)),
115-
RANDOM.doubles(5).map(d -> minValue + (maxValue - minValue) * d).boxed().map(ScaledBigDecimal::valueOf)
115+
RANDOM.doubles(1).map(d -> minValue + (maxValue - minValue) * d).boxed().map(ScaledBigDecimal::valueOf)
116116
);
117117
}
118118
}

src/main/java/it/aboutbits/springboot/testing/validation/source/PastValueSource.java

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,32 +37,23 @@ public <T> Stream<T> values(Class<T> propertyClass, Object... args) {
3737

3838

3939
private static Stream<LocalDate> getLocalDateStream(Object[] args) {
40-
var currentDate = LocalDate.now().minusDays(1);
40+
var currentDate = LocalDate.now();
4141
var smallestDate = LocalDate.MIN;
42-
return Stream.concat(
43-
Stream.of(smallestDate),
44-
Stream.iterate(currentDate, date -> date.minusDays(1))
45-
.limit(4)
46-
);
42+
43+
return Stream.of(smallestDate, currentDate.minusDays(1));
4744
}
4845

4946
private static Stream<LocalDateTime> getLocalDatetimeStream(Object[] args) {
50-
var currentDateTime = LocalDateTime.now().minusDays(1);
47+
var currentDateTime = LocalDateTime.now();
5148
var smallestDateTime = LocalDateTime.MIN;
52-
return Stream.concat(
53-
Stream.of(smallestDateTime, currentDateTime.minusSeconds(1)),
54-
Stream.iterate(currentDateTime, dateTime -> dateTime.minusHours(1))
55-
.limit(4)
56-
);
49+
50+
return Stream.of(smallestDateTime, currentDateTime.minusSeconds(1));
5751
}
5852

5953
private static Stream<OffsetDateTime> getOffsetDateTimeStream(Object[] args) {
60-
var currentOffsetDateTime = OffsetDateTime.now(ZoneOffset.UTC).minusDays(1);
54+
var currentOffsetDateTime = OffsetDateTime.now(ZoneOffset.UTC);
6155
var smallestOffsetDateTime = OffsetDateTime.MIN;
62-
return Stream.concat(
63-
Stream.of(smallestOffsetDateTime, currentOffsetDateTime.minusSeconds(1)),
64-
Stream.iterate(currentOffsetDateTime, offsetDateTime -> offsetDateTime.minusHours(1))
65-
.limit(4)
66-
);
56+
57+
return Stream.of(smallestOffsetDateTime, currentOffsetDateTime.minusSeconds(1));
6758
}
6859
}

0 commit comments

Comments
 (0)