1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.validator;
18
19 import static org.junit.jupiter.api.Assertions.assertNotNull;
20 import static org.junit.jupiter.api.Assertions.assertTrue;
21
22 import java.io.IOException;
23
24 import org.junit.jupiter.api.AfterEach;
25 import org.junit.jupiter.api.BeforeEach;
26 import org.junit.jupiter.api.Test;
27 import org.xml.sax.SAXException;
28
29
30
31
32 public abstract class AbstractNumberTest extends AbstractCommonTest {
33
34
35
36
37 protected String formKey;
38
39
40
41
42 protected String action;
43
44
45
46
47 @BeforeEach
48 protected void setUp() throws IOException, SAXException {
49
50 loadResources("TestNumber-config.xml");
51 }
52
53 @AfterEach
54 protected void tearDown() {
55 }
56
57
58
59
60 @Test
61 public void testNumber() throws ValidatorException {
62
63 final ValueBean info = new ValueBean();
64 info.setValue("0");
65 valueTest(info, true);
66 }
67
68
69
70
71 @Test
72 public void testNumberFailure() throws ValidatorException {
73
74 final ValueBean info = new ValueBean();
75 valueTest(info, false);
76 }
77
78
79
80
81
82
83
84 protected void valueTest(final Object info, final boolean passed) throws ValidatorException {
85
86
87 final Validator validator = new Validator(resources, formKey);
88
89
90 validator.setParameter(Validator.BEAN_PARAM, info);
91
92
93
94
95
96
97 final ValidatorResults results = validator.validate();
98
99 assertNotNull(results, "Results are null.");
100
101 final ValidatorResult result = results.getValidatorResult("value");
102
103 assertNotNull(result, () -> action + " value ValidatorResult should not be null.");
104 assertTrue(result.containsAction(action), () -> action + " value ValidatorResult should contain the '" + action + "' action.");
105 assertTrue(passed ? result.isValid(action) : !result.isValid(action),
106 () -> action + " value ValidatorResult for the '" + action + "' action should have " + (passed ? "passed" : "failed") + ".");
107 }
108
109 }