|
11 | 11 | import org.hibernate.validator.constraints.pl.NIP;
|
12 | 12 | import org.hibernate.validator.test.constraints.annotations.AbstractConstrainedTest;
|
13 | 13 |
|
| 14 | +import org.testng.annotations.DataProvider; |
14 | 15 | import org.testng.annotations.Test;
|
15 | 16 |
|
16 | 17 | /**
|
@@ -40,62 +41,51 @@ public void testIncorrectLength() {
|
40 | 41 | );
|
41 | 42 | }
|
42 | 43 |
|
43 |
| - @Test |
44 |
| - public void testCorrectNipNumber() { |
45 |
| - assertNoViolations( validator.validate( new Person( "5931423811" ) ) ); |
46 |
| - assertNoViolations( validator.validate( new Person( "2596048500" ) ) ); |
47 |
| - assertNoViolations( validator.validate( new Person( "4163450312" ) ) ); |
48 |
| - assertNoViolations( validator.validate( new Person( "1786052059" ) ) ); |
49 |
| - assertNoViolations( validator.validate( new Person( "6660057854" ) ) ); |
50 |
| - assertNoViolations( validator.validate( new Person( "4219220786" ) ) ); |
51 |
| - assertNoViolations( validator.validate( new Person( "3497264632" ) ) ); |
52 |
| - |
| 44 | + @Test(dataProvider = "validNips") |
| 45 | + public void testCorrectNipNumber(String nip) { |
| 46 | + assertNoViolations( validator.validate( new Person( nip ) ) ); |
53 | 47 | }
|
54 | 48 |
|
55 |
| - @Test |
56 |
| - public void testIncorrectNipNumber() { |
57 |
| - assertThat( validator.validate( new Person( "123-456-78-14" ) ) ) |
58 |
| - .containsOnlyViolations( |
59 |
| - violationOf( NIP.class ).withProperty( "nip" ) |
60 |
| - ); |
61 |
| - assertThat( validator.validate( new Person( "123-45-67-812" ) ) ) |
62 |
| - .containsOnlyViolations( |
63 |
| - violationOf( NIP.class ).withProperty( "nip" ) |
64 |
| - ); |
65 |
| - assertThat( validator.validate( new Person( "123-456-32-12" ) ) ) |
66 |
| - .containsOnlyViolations( |
67 |
| - violationOf( NIP.class ).withProperty( "nip" ) |
68 |
| - ); |
69 |
| - assertThat( validator.validate( new Person( "5931423812" ) ) ) |
70 |
| - .containsOnlyViolations( |
71 |
| - violationOf( NIP.class ).withProperty( "nip" ) |
72 |
| - ); |
73 |
| - assertThat( validator.validate( new Person( "2596048505" ) ) ) |
74 |
| - .containsOnlyViolations( |
75 |
| - violationOf( NIP.class ).withProperty( "nip" ) |
76 |
| - ); |
77 |
| - assertThat( validator.validate( new Person( "4163450311" ) ) ) |
78 |
| - .containsOnlyViolations( |
79 |
| - violationOf( NIP.class ).withProperty( "nip" ) |
80 |
| - ); |
81 |
| - assertThat( validator.validate( new Person( "1786052053" ) ) ) |
82 |
| - .containsOnlyViolations( |
83 |
| - violationOf( NIP.class ).withProperty( "nip" ) |
84 |
| - ); |
85 |
| - assertThat( validator.validate( new Person( "6660057852" ) ) ) |
86 |
| - .containsOnlyViolations( |
87 |
| - violationOf( NIP.class ).withProperty( "nip" ) |
88 |
| - ); |
89 |
| - assertThat( validator.validate( new Person( "4219220785" ) ) ) |
90 |
| - .containsOnlyViolations( |
91 |
| - violationOf( NIP.class ).withProperty( "nip" ) |
92 |
| - ); |
93 |
| - assertThat( validator.validate( new Person( "3497264639" ) ) ) |
| 49 | + @Test(dataProvider = "invalidNips") |
| 50 | + public void testIncorrectNipNumber(String nip) { |
| 51 | + assertThat( validator.validate( new Person( nip ) ) ) |
94 | 52 | .containsOnlyViolations(
|
95 | 53 | violationOf( NIP.class ).withProperty( "nip" )
|
96 | 54 | );
|
97 | 55 | }
|
98 | 56 |
|
| 57 | + @DataProvider(name = "validNips") |
| 58 | + private static Object[][] validNips() { |
| 59 | + return new Object[][] { |
| 60 | + { "5931423811" }, |
| 61 | + { "2596048500" }, |
| 62 | + { "4163450312" }, |
| 63 | + { "1786052059" }, |
| 64 | + { "6660057854" }, |
| 65 | + { "4219220786" }, |
| 66 | + { "3497264632" } |
| 67 | + }; |
| 68 | + } |
| 69 | + |
| 70 | + @DataProvider(name = "invalidNips") |
| 71 | + private static Object[][] invalidNips() { |
| 72 | + return new Object[][] { |
| 73 | + { "123-456-78-14" }, |
| 74 | + { "123-45-67-812" }, |
| 75 | + { "123-456-32-12" }, |
| 76 | + { "5931423812" }, |
| 77 | + { "2596048505" }, |
| 78 | + { "4163450311" }, |
| 79 | + { "1786052053" }, |
| 80 | + { "6660057852" }, |
| 81 | + { "4219220785" }, |
| 82 | + { "3497264639" }, |
| 83 | + { "4062321040" }, |
| 84 | + { "7985097620" }, |
| 85 | + { "8808817210" } |
| 86 | + }; |
| 87 | + } |
| 88 | + |
99 | 89 | public static class Person {
|
100 | 90 |
|
101 | 91 | @NIP
|
|
0 commit comments