Skip to content

Commit e1faf25

Browse files
committed
Added tests for IpAddressRule
1 parent 876e04d commit e1faf25

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package dev.ditsche.validator.rule.ruleset;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import java.util.LinkedList;
6+
import java.util.stream.Stream;
7+
8+
import static org.assertj.core.api.Assertions.assertThat;
9+
10+
public class IpAddressRuleTest {
11+
12+
private final IpAddressRule ipAddressRule = new IpAddressRule();
13+
14+
@Test
15+
public void shouldFailIfNoStringIsProvided() {
16+
Stream.of(null, 1, new LinkedList<>(), 2.00f).forEach(value -> {
17+
assertThat(ipAddressRule.passes(value).isPassed()).isFalse();
18+
});
19+
}
20+
21+
@Test
22+
public void shouldFailIfStringIsInvalid() {
23+
Stream.of("", "212.35.234.256", "127.0.0").forEach(value -> {
24+
assertThat(ipAddressRule.passes(value).isPassed()).isFalse();
25+
});
26+
}
27+
28+
@Test
29+
public void shouldPassWithValidCreditCardNumber() {
30+
Stream.of("0.0.0.0", "127.0.0.1", "46.234.18.191").forEach(value -> {
31+
assertThat(ipAddressRule.passes(value).isPassed()).isTrue();
32+
});
33+
}
34+
35+
@Test
36+
public void shouldReturnValidErrorMessage() {
37+
assertThat(ipAddressRule.message("test")).isEqualTo("The field \"test\" needs to be a valid ip address");
38+
}
39+
40+
}

0 commit comments

Comments
 (0)