|
15 | 15 | */
|
16 | 16 | package org.everit.json.schema;
|
17 | 17 |
|
18 |
| -import org.everit.json.schema.NumberSchema; |
19 |
| -import org.everit.json.schema.ValidationException; |
20 | 18 | import org.junit.Test;
|
21 | 19 |
|
22 | 20 | public class NumberSchemaTest {
|
23 | 21 |
|
24 |
| - @Test(expected = ValidationException.class) |
| 22 | + @Test |
25 | 23 | public void exclusiveMinimum() {
|
26 |
| - NumberSchema.builder().minimum(10.0).exclusiveMinimum(true).build().validate(10); |
| 24 | + NumberSchema subject = NumberSchema.builder().minimum(10.0).exclusiveMinimum(true).build(); |
| 25 | + TestSupport.exceptFailure(subject, 10); |
27 | 26 | }
|
28 | 27 |
|
29 |
| - @Test(expected = ValidationException.class) |
| 28 | + @Test |
30 | 29 | public void maximum() {
|
31 |
| - NumberSchema.builder().maximum(20.0).build().validate(21); |
| 30 | + NumberSchema subject = NumberSchema.builder().maximum(20.0).build(); |
| 31 | + TestSupport.exceptFailure(subject, 21); |
32 | 32 | }
|
33 | 33 |
|
34 |
| - @Test(expected = ValidationException.class) |
| 34 | + @Test |
35 | 35 | public void maximumExclusive() {
|
36 |
| - NumberSchema.builder().maximum(20.0).exclusiveMaximum(true).build().validate(20); |
| 36 | + NumberSchema subject = NumberSchema.builder().maximum(20.0).exclusiveMaximum(true).build(); |
| 37 | + TestSupport.exceptFailure(subject, 20); |
37 | 38 | }
|
38 | 39 |
|
39 |
| - @Test(expected = ValidationException.class) |
| 40 | + @Test |
40 | 41 | public void minimumFailure() {
|
41 |
| - NumberSchema.builder().minimum(10.0).build().validate(9); |
| 42 | + NumberSchema subject = NumberSchema.builder().minimum(10.0).build(); |
| 43 | + TestSupport.exceptFailure(subject, 9); |
42 | 44 | }
|
43 | 45 |
|
44 |
| - @Test(expected = ValidationException.class) |
| 46 | + @Test |
45 | 47 | public void multipleOfFailure() {
|
46 |
| - NumberSchema.builder().multipleOf(10).build().validate(15); |
| 48 | + NumberSchema subject = NumberSchema.builder().multipleOf(10).build(); |
| 49 | + TestSupport.exceptFailure(subject, 15); |
47 | 50 | }
|
48 | 51 |
|
49 | 52 | @Test
|
50 | 53 | public void notRequiresNumber() {
|
51 | 54 | NumberSchema.builder().requiresNumber(false).build().validate("foo");
|
52 | 55 | }
|
53 | 56 |
|
54 |
| - @Test(expected = ValidationException.class) |
| 57 | + @Test |
55 | 58 | public void requiresIntegerFailure() {
|
56 |
| - NumberSchema.builder().requiresInteger(true).build().validate(new Float(10.2)); |
| 59 | + NumberSchema subject = NumberSchema.builder().requiresInteger(true).build(); |
| 60 | + TestSupport.exceptFailure(subject, 10.2f); |
57 | 61 | }
|
58 | 62 |
|
59 | 63 | @Test
|
60 | 64 | public void requiresIntegerSuccess() {
|
61 | 65 | NumberSchema.builder().requiresInteger(true).build().validate(10);
|
62 | 66 | }
|
63 | 67 |
|
| 68 | + @Test |
| 69 | + public void smallMultipleOf() { |
| 70 | + NumberSchema.builder() |
| 71 | + .multipleOf(0.0001) |
| 72 | + .build().validate(0.0075); |
| 73 | + } |
| 74 | + |
64 | 75 | @Test
|
65 | 76 | public void success() {
|
66 | 77 | NumberSchema.builder()
|
67 |
| - .minimum(10.0) |
68 |
| - .maximum(11.0) |
69 |
| - .exclusiveMaximum(true) |
70 |
| - .multipleOf(10) |
71 |
| - .build().validate(10.0); |
| 78 | + .minimum(10.0) |
| 79 | + .maximum(11.0) |
| 80 | + .exclusiveMaximum(true) |
| 81 | + .multipleOf(10) |
| 82 | + .build().validate(10.0); |
72 | 83 | }
|
73 | 84 |
|
74 | 85 | @Test(expected = ValidationException.class)
|
75 | 86 | public void typeFailure() {
|
76 | 87 | NumberSchema.builder().build().validate(null);
|
77 | 88 | }
|
78 | 89 |
|
79 |
| - @Test |
80 |
| - public void smallMultipleOf() { |
81 |
| - NumberSchema.builder() |
82 |
| - .multipleOf(0.0001) |
83 |
| - .build().validate(0.0075); |
84 |
| - } |
85 |
| - |
86 | 90 | }
|
0 commit comments