Skip to content

Commit 97b508e

Browse files
Vincent Potucekfmbenhassine
Vincent Potucek
authored andcommitted
improve test
1 parent 58c962d commit 97b508e

File tree

1 file changed

+19
-29
lines changed

1 file changed

+19
-29
lines changed

easy-random-randomizers/src/test/java/org/jeasy/random/randomizers/PasswordRandomizerTest.java

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,62 +23,52 @@
2323
*/
2424
package org.jeasy.random.randomizers;
2525

26-
import static org.junit.jupiter.api.Assertions.assertFalse;
27-
import static org.junit.jupiter.api.Assertions.assertTrue;
26+
import org.junit.jupiter.api.Test;
2827

2928
import java.util.regex.Pattern;
30-
import java.util.regex.Matcher;
3129

32-
import org.junit.jupiter.api.Test;
30+
import static org.assertj.core.api.Assertions.assertThat;
31+
3332

3433
class PasswordRandomizerTest {
3534

3635
Pattern SpecialChar = Pattern.compile("[^A-Za-z0-9]");
36+
3737
Pattern UpperChar = Pattern.compile("[A-Z]");
3838

39+
PasswordRandomizer sut;
40+
3941
@Test
4042
void testPassword_NotContainsUppercaseSpecial() {
4143
// given
42-
PasswordRandomizer passwordRandomizer = new PasswordRandomizer(123L, 8, 20);
43-
44+
sut = new PasswordRandomizer(123L, 8, 20);
4445
// when
45-
String randomValue = passwordRandomizer.getRandomValue();
46-
Matcher m1 = UpperChar.matcher(randomValue);
47-
Matcher m2 = SpecialChar.matcher(randomValue);
48-
46+
String randomValue = sut.getRandomValue();
4947
// then
50-
assertFalse(m1.find());
51-
assertFalse(m2.find());
48+
assertThat(UpperChar.matcher(randomValue).find()).isFalse();
49+
assertThat(SpecialChar.matcher(randomValue).find()).isFalse();
5250
}
5351

5452
@Test
5553
void testPassword_ContainsUppercase() {
56-
// given
57-
PasswordRandomizer passwordRandomizer = new PasswordRandomizer(123L, 8, 20, true);
58-
54+
// given
55+
sut = new PasswordRandomizer(123L, 8, 20, true);
5956
// when
60-
String randomValue = passwordRandomizer.getRandomValue();
61-
Matcher m1 = UpperChar.matcher(randomValue);
62-
Matcher m2 = SpecialChar.matcher(randomValue);
63-
57+
String randomValue = sut.getRandomValue();
6458
// then
65-
assertTrue(m1.find());
66-
assertFalse(m2.find());
59+
assertThat(UpperChar.matcher(randomValue).find()).isTrue();
60+
assertThat(SpecialChar.matcher(randomValue).find()).isFalse();
6761
}
6862

6963
@Test
7064
void testPassword_ContainsUppercaseSpecial() {
7165
// given
72-
PasswordRandomizer passwordRandomizer = new PasswordRandomizer(123L, 8, 20, true, true);
73-
66+
sut = new PasswordRandomizer(123L, 8, 20, true, true);
7467
// when
75-
String randomValue = passwordRandomizer.getRandomValue();
76-
Matcher m1 = UpperChar.matcher(randomValue);
77-
Matcher m2 = SpecialChar.matcher(randomValue);
78-
68+
String randomValue = sut.getRandomValue();
7969
// then
80-
assertTrue(m1.find());
81-
assertTrue(m2.find());
70+
assertThat(UpperChar.matcher(randomValue).find()).isTrue();
71+
assertThat(SpecialChar.matcher(randomValue).find()).isTrue();
8272
}
8373

8474
}

0 commit comments

Comments
 (0)