|
15 | 15 | */
|
16 | 16 | package org.everit.json.schema;
|
17 | 17 |
|
18 |
| -import org.everit.json.schema.StringSchema; |
19 |
| -import org.everit.json.schema.ValidationException; |
20 | 18 | import org.junit.Test;
|
21 | 19 |
|
22 | 20 | public class StringSchemaTest {
|
23 | 21 |
|
24 |
| - @Test(expected = ValidationException.class) |
| 22 | + @Test |
25 | 23 | public void maxLength() {
|
26 |
| - StringSchema.builder().maxLength(3).build().validate("foobar"); |
| 24 | + StringSchema subject = StringSchema.builder().maxLength(3).build(); |
| 25 | + TestSupport.exceptFailure(subject, "foobar"); |
27 | 26 | }
|
28 | 27 |
|
29 |
| - @Test(expected = ValidationException.class) |
| 28 | + @Test |
30 | 29 | public void minLength() {
|
31 |
| - StringSchema.builder().minLength(2).build().validate("a"); |
| 30 | + StringSchema subject = StringSchema.builder().minLength(2).build(); |
| 31 | + TestSupport.exceptFailure(subject, "a"); |
32 | 32 | }
|
33 | 33 |
|
34 | 34 | @Test
|
35 |
| - public void success() { |
36 |
| - StringSchema.builder().build().validate("foo"); |
| 35 | + public void notRequiresString() { |
| 36 | + StringSchema.builder().requiresString(false).build().validate(2); |
37 | 37 | }
|
38 | 38 |
|
39 |
| - @Test(expected = ValidationException.class) |
40 |
| - public void typeFailure() { |
41 |
| - StringSchema.builder().build().validate(null); |
| 39 | + @Test |
| 40 | + public void patternFailure() { |
| 41 | + StringSchema subject = StringSchema.builder().pattern("^a*$").build(); |
| 42 | + TestSupport.exceptFailure(subject, "abc"); |
42 | 43 | }
|
43 | 44 |
|
44 | 45 | @Test
|
45 | 46 | public void patternSuccess() {
|
46 | 47 | StringSchema.builder().pattern("^a*$").build().validate("aaaa");
|
47 | 48 | }
|
48 | 49 |
|
49 |
| - @Test(expected = ValidationException.class) |
50 |
| - public void patternFailure() { |
51 |
| - StringSchema.builder().pattern("^a*$").build().validate("abc"); |
| 50 | + @Test |
| 51 | + public void success() { |
| 52 | + StringSchema.builder().build().validate("foo"); |
52 | 53 | }
|
53 | 54 |
|
54 | 55 | @Test
|
55 |
| - public void notRequiresString() { |
56 |
| - StringSchema.builder().requiresString(false).build().validate(2); |
| 56 | + public void typeFailure() { |
| 57 | + TestSupport.exceptFailure(StringSchema.builder().build(), null); |
57 | 58 | }
|
58 | 59 | }
|
0 commit comments