Skip to content

Commit b5b89ed

Browse files
committed
test: refactor ByteCombinableArbitraryTest to use direct assertions
1 parent e7a64f7 commit b5b89ed

File tree

1 file changed

+35
-71
lines changed

1 file changed

+35
-71
lines changed

fixture-monkey-api/src/test/java/com/navercorp/fixturemonkey/api/arbitrary/ByteCombinableArbitraryTest.java

Lines changed: 35 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020

2121
import static org.assertj.core.api.BDDAssertions.then;
2222

23-
import java.util.stream.IntStream;
24-
2523
import org.junit.jupiter.api.Test;
2624

2725
class ByteCombinableArbitraryTest {
@@ -50,56 +48,46 @@ void withRange() {
5048
@Test
5149
void positive() {
5250
// when
53-
boolean allPositive = IntStream.range(0, 100)
54-
.mapToObj(i -> CombinableArbitrary.bytes().positive().combined())
55-
.allMatch(b -> b > 0);
51+
Byte actual = CombinableArbitrary.bytes().positive().combined();
5652

5753
// then
58-
then(allPositive).isTrue();
54+
then(actual).isPositive();
5955
}
6056

6157
@Test
6258
void negative() {
6359
// when
64-
boolean allNegative = IntStream.range(0, 100)
65-
.mapToObj(i -> CombinableArbitrary.bytes().negative().combined())
66-
.allMatch(b -> b < 0);
60+
Byte actual = CombinableArbitrary.bytes().negative().combined();
6761

6862
// then
69-
then(allNegative).isTrue();
63+
then(actual).isNegative();
7064
}
7165

7266
@Test
7367
void even() {
7468
// when
75-
boolean allEven = IntStream.range(0, 100)
76-
.mapToObj(i -> CombinableArbitrary.bytes().even().combined())
77-
.allMatch(b -> b % 2 == 0);
69+
Byte actual = CombinableArbitrary.bytes().even().combined();
7870

7971
// then
80-
then(allEven).isTrue();
72+
then(actual % 2).isEqualTo(0);
8173
}
8274

8375
@Test
8476
void odd() {
8577
// when
86-
boolean allOdd = IntStream.range(0, 100)
87-
.mapToObj(i -> CombinableArbitrary.bytes().odd().combined())
88-
.allMatch(b -> b % 2 != 0);
78+
Byte actual = CombinableArbitrary.bytes().odd().combined();
8979

9080
// then
91-
then(allOdd).isTrue();
81+
then(actual % 2).isNotEqualTo(0);
9282
}
9383

9484
@Test
9585
void ascii() {
9686
// when
97-
boolean allAscii = IntStream.range(0, 100)
98-
.mapToObj(i -> CombinableArbitrary.bytes().ascii().combined())
99-
.allMatch(b -> b >= 0 && b <= 127);
87+
Byte actual = CombinableArbitrary.bytes().ascii().combined();
10088

10189
// then
102-
then(allAscii).isTrue();
90+
then(actual).isBetween((byte)0, (byte)127);
10391
}
10492

10593
@Test
@@ -220,136 +208,112 @@ void fixed() {
220208
@Test
221209
void lastMethodWinsRangeOverPositive() {
222210
// when - positive().withRange() => withRange()
223-
boolean allInRange = IntStream.range(0, 30)
224-
.mapToObj(i -> CombinableArbitrary.bytes().positive().withRange((byte)-10, (byte)-1).combined())
225-
.allMatch(b -> b >= -10 && b <= -1);
211+
Byte actual = CombinableArbitrary.bytes().positive().withRange((byte)-10, (byte)-1).combined();
226212

227213
// then
228-
then(allInRange).isTrue();
214+
then(actual).isBetween((byte)-10, (byte)-1);
229215
}
230216

231217
@Test
232218
void lastMethodWinsOddOverEven() {
233219
// when - even().odd() => odd()
234-
boolean allOdd = IntStream.range(0, 30)
235-
.mapToObj(i -> CombinableArbitrary.bytes().even().odd().combined())
236-
.allMatch(b -> b % 2 != 0);
220+
Byte actual = CombinableArbitrary.bytes().even().odd().combined();
237221

238222
// then
239-
then(allOdd).isTrue();
223+
then(actual % 2).isNotEqualTo(0);
240224
}
241225

242226
@Test
243227
void byteFilterWithMultipleOfFive() {
244228
// when - filter multiples of 5
245-
boolean allMultipleOfFive = IntStream.range(0, 30)
246-
.mapToObj(i -> CombinableArbitrary.bytes()
229+
Byte actual = CombinableArbitrary.bytes()
247230
.withRange((byte)0, (byte)100)
248-
.filter(b -> b % 5 == 0).combined())
249-
.allMatch(b -> b % 5 == 0);
231+
.filter(b -> b % 5 == 0).combined();
250232

251233
// then
252-
then(allMultipleOfFive).isTrue();
234+
then(actual % 5).isEqualTo(0);
253235
}
254236

255237
@Test
256238
void asciiWithOdd() {
257239
// when - ascii().odd() => odd()
258-
boolean allOdd = IntStream.range(0, 100)
259-
.mapToObj(i -> CombinableArbitrary.bytes().ascii().odd().combined())
260-
.allMatch(b -> b % 2 != 0);
240+
Byte actual = CombinableArbitrary.bytes().ascii().odd().combined();
261241

262242
// then
263-
then(allOdd).isTrue();
243+
then(actual % 2).isNotEqualTo(0);
264244
}
265245

266246
@Test
267247
void asciiWithEven() {
268248
// when - ascii().even() => even()
269-
boolean allEven = IntStream.range(0, 100)
270-
.mapToObj(i -> CombinableArbitrary.bytes().ascii().even().combined())
271-
.allMatch(b -> b % 2 == 0);
249+
Byte actual = CombinableArbitrary.bytes().ascii().even().combined();
272250

273251
// then
274-
then(allEven).isTrue();
252+
then(actual % 2).isEqualTo(0);
275253
}
276254

277255
@Test
278256
void asciiWithPositive() {
279257
// when
280-
boolean allAsciiAndPositive = IntStream.range(0, 100)
281-
.mapToObj(i -> CombinableArbitrary.bytes().ascii().positive().combined())
282-
.allMatch(b -> b >= 1 && b <= 127);
258+
Byte actual = CombinableArbitrary.bytes().ascii().positive().combined();
283259

284260
// then
285-
then(allAsciiAndPositive).isTrue();
261+
then(actual).isBetween((byte)1, (byte)127);
286262
}
287263

288264
@Test
289265
void asciiWithNegative() {
290266
// when - ascii().negative() => negative()
291-
boolean allNegative = IntStream.range(0, 100)
292-
.mapToObj(i -> CombinableArbitrary.bytes().ascii().negative().combined())
293-
.allMatch(b -> b < 0);
267+
Byte actual = CombinableArbitrary.bytes().ascii().negative().combined();
294268

295269
// then
296-
then(allNegative).isTrue();
270+
then(actual).isNegative();
297271
}
298272

299273
@Test
300274
void negativeWithAscii() {
301275
// when - negative().ascii() => ascii()
302-
boolean allAscii = IntStream.range(0, 100)
303-
.mapToObj(i -> CombinableArbitrary.bytes().negative().ascii().combined())
304-
.allMatch(b -> b >= 0 && b <= 127);
276+
Byte actual = CombinableArbitrary.bytes().negative().ascii().combined();
305277

306278
// then
307-
then(allAscii).isTrue();
279+
then(actual).isBetween((byte)0, (byte)127);
308280
}
309281

310282
@Test
311283
void oddWithEvenCombination() {
312284
// when - odd().even() => even()
313-
boolean allEven = IntStream.range(0, 100)
314-
.mapToObj(i -> CombinableArbitrary.bytes().odd().even().combined())
315-
.allMatch(b -> b % 2 == 0);
285+
Byte actual = CombinableArbitrary.bytes().odd().even().combined();
316286

317287
// then
318-
then(allEven).isTrue();
288+
then(actual % 2).isEqualTo(0);
319289
}
320290

321291
@Test
322292
void positiveWithNegativeCombination() {
323293
// when - positive().negative() => negative()
324-
boolean allNegative = IntStream.range(0, 100)
325-
.mapToObj(i -> CombinableArbitrary.bytes().positive().negative().combined())
326-
.allMatch(b -> b < 0);
294+
Byte actual = CombinableArbitrary.bytes().positive().negative().combined();
327295

328296
// then
329-
then(allNegative).isTrue();
297+
then(actual).isNegative();
330298
}
331299

332300
@Test
333301
void complexApiCombination() {
334302
// when - ascii().positive().odd() => odd()
335-
boolean allOdd = IntStream.range(0, 100)
336-
.mapToObj(i -> CombinableArbitrary.bytes().ascii().positive().odd().combined())
337-
.allMatch(b -> b % 2 != 0);
303+
Byte actual = CombinableArbitrary.bytes().ascii().positive().odd().combined();
338304

339305
// then
340-
then(allOdd).isTrue();
306+
then(actual % 2).isNotEqualTo(0);
341307
}
342308

343309
@Test
344310
void rangeOverridesOtherConstraints() {
345311
// when
346312
byte min = -50;
347313
byte max = -10;
348-
boolean allInRange = IntStream.range(0, 100)
349-
.mapToObj(i -> CombinableArbitrary.bytes().ascii().positive().odd().withRange(min, max).combined())
350-
.allMatch(b -> b >= min && b <= max);
314+
Byte actual = CombinableArbitrary.bytes().ascii().positive().odd().withRange(min, max).combined();
351315

352316
// then
353-
then(allInRange).isTrue();
317+
then(actual).isBetween(min, max);
354318
}
355319
}

0 commit comments

Comments
 (0)