1. Project Clover database Wed Jan 17 2024 23:40:18 CST
  2. Package org.europa.together.utils

File ValidatorTest.java

 

Code metrics

0
276
53
1
579
488
53
0.19
5.21
53
1

Classes

Class Line # Actions
ValidatorTest 19 276 0% 53 6
0.9817629598.2%
 

Contributing tests

This file is covered by 51 tests. .

Source view

1    package org.europa.together.utils;
2   
3    import java.lang.reflect.Constructor;
4    import java.time.ZoneId;
5    import org.europa.together.application.LogbackLogger;
6    import org.europa.together.business.Logger;
7    import static org.junit.jupiter.api.Assertions.*;
8    import org.junit.jupiter.api.Test;
9    import java.time.ZonedDateTime;
10    import org.europa.together.JUnit5Preperator;
11    import org.junit.jupiter.api.extension.ExtendWith;
12    import org.springframework.test.context.ContextConfiguration;
13    import org.springframework.test.context.junit.jupiter.SpringExtension;
14   
15    @SuppressWarnings("unchecked")
16    @ExtendWith({JUnit5Preperator.class})
17    @ExtendWith(SpringExtension.class)
18    @ContextConfiguration(locations = {"/applicationContext.xml"})
 
19    public class ValidatorTest {
20   
21    private static final Logger LOGGER = new LogbackLogger(ValidatorTest.class);
22   
 
23  1 toggle @Test
24    void privateConstructor() throws Exception {
25  1 Constructor<Validator> clazz
26    = Validator.class.getDeclaredConstructor();
27  1 clazz.setAccessible(true);
28  1 assertThrows(Exception.class, () -> {
29  1 Validator call = clazz.newInstance();
30    });
31    }
32   
 
33  1 toggle @Test
34    void isBooleanRegex() {
35  1 assertTrue(Validator.validate("true", Validator.BOOLEAN));
36  1 assertTrue(Validator.validate("false", Validator.BOOLEAN));
37  1 assertTrue(Validator.validate("TRUE", Validator.BOOLEAN));
38  1 assertTrue(Validator.validate("FALSE", Validator.BOOLEAN));
39  1 assertTrue(Validator.validate("TrUe", Validator.BOOLEAN));
40  1 assertTrue(Validator.validate("fAlSe", Validator.BOOLEAN));
41  1 assertTrue(Validator.validate("0", Validator.BOOLEAN));
42  1 assertTrue(Validator.validate("1", Validator.BOOLEAN));
43    }
44   
 
45  1 toggle @Test
46    void isNotBooleanRegex() {
47  1 assertFalse(Validator.validate("-1", Validator.BOOLEAN));
48  1 assertFalse(Validator.validate("5", Validator.BOOLEAN));
49    }
50   
 
51  1 toggle @Test
52    void isDigitRegex() {
53  1 assertTrue(Validator.validate("0000", Validator.DIGIT));
54  1 assertTrue(Validator.validate("1", Validator.DIGIT));
55  1 assertTrue(Validator.validate("1234567890", Validator.DIGIT));
56  1 assertTrue(Validator.validate("1 2 345 6 789 0", Validator.DIGIT));
57    }
58   
 
59  1 toggle @Test
60    void isNotDigitRegex() {
61  1 assertFalse(Validator.validate("ABC.01", Validator.DIGIT));
62    }
63   
 
64  1 toggle @Test
65    void isCharacterRegex() {
66  1 assertTrue(Validator.validate("abcdefghijklmnopqrstuvwxyz", Validator.ASCII_CHARACTER));
67  1 assertTrue(Validator.validate("ABCDEFGHIJKLMNOPQRSTUVWXYZ", Validator.ASCII_CHARACTER));
68  1 assertTrue(Validator.validate("abc XYZ", Validator.ASCII_CHARACTER));
69    }
70   
 
71  1 toggle @Test
72    void isNotCharacterRegex() {
73  1 assertFalse(Validator.validate("äöü ÄÖÜ ß", Validator.ASCII_CHARACTER));
74  1 assertFalse(Validator.validate("abc 123 XYZ", Validator.ASCII_CHARACTER));
75    }
76   
 
77  1 toggle @Test
78    void isTextRegex() {
79  1 assertTrue(Validator.validate("A fool with a tool is still a fool.", Validator.TEXT));
80  1 assertTrue(Validator.validate("Remember, remember the 1 st. of November!", Validator.TEXT));
81  1 assertTrue(Validator.validate("EN/00001.III-D", Validator.TEXT));
82  1 assertTrue(Validator.validate("Math: 1 + ~1 : 12 * 4/3 = -10%", Validator.TEXT));
83  1 assertTrue(Validator.validate("Brackets: <>(){}[]", Validator.TEXT));
84  1 assertTrue(Validator.validate("Symbols 01: ?!.,;_", Validator.TEXT));
85  1 assertTrue(Validator.validate("Symbols 02: ¬&§$@€#", Validator.TEXT));
86    }
87   
 
88  1 toggle @Test
89    void isNotTextRegex() {
90  1 assertFalse(Validator.validate("äöüÄÖÜß", Validator.TEXT));
91    }
92   
 
93  1 toggle @Test
94    void isRegexLetters() {
95  1 assertTrue(Validator.validate("abcdefXYZ", Validator.LETTERS));
96  1 assertTrue(Validator.validate("a", Validator.LETTERS));
97  1 assertTrue(Validator.validate("A", Validator.LETTERS));
98  1 assertTrue(Validator.validate("ABCxyz", Validator.LETTERS));
99    }
100   
 
101  1 toggle @Test
102    void isNotRegexLetters() {
103  1 assertFalse(Validator.validate("äöüÄÖÜß", Validator.LETTERS));
104  1 assertFalse(Validator.validate("12345678890", Validator.LETTERS));
105  1 assertFalse(Validator.validate("!§$%", Validator.LETTERS));
106    }
107   
 
108  1 toggle @Test
109    void isFloatingPointRegex() {
110  1 assertTrue(Validator.validate("0000", Validator.FLOATING_POINT));
111  1 assertTrue(Validator.validate("1", Validator.FLOATING_POINT));
112  1 assertTrue(Validator.validate("1234567890", Validator.FLOATING_POINT));
113  1 assertTrue(Validator.validate("1 2 345 6 789 0", Validator.FLOATING_POINT));
114   
115  1 assertTrue(Validator.validate("0.0", Validator.FLOATING_POINT));
116  1 assertTrue(Validator.validate("-0.0", Validator.FLOATING_POINT));
117  1 assertTrue(Validator.validate("0.123456789", Validator.FLOATING_POINT));
118  1 assertTrue(Validator.validate("-0.123456789", Validator.FLOATING_POINT));
119  1 assertTrue(Validator.validate("0123456789.0987654321", Validator.FLOATING_POINT));
120  1 assertTrue(Validator.validate("-0123456789.0987654321", Validator.FLOATING_POINT));
121    }
122   
 
123  1 toggle @Test
124    void isNotFloatingPointRegex() {
125  1 assertFalse(Validator.validate("0.", Validator.FLOATING_POINT));
126  1 assertFalse(Validator.validate("-0.", Validator.FLOATING_POINT));
127  1 assertFalse(Validator.validate(".0", Validator.FLOATING_POINT));
128  1 assertFalse(Validator.validate("-.0", Validator.FLOATING_POINT));
129  1 assertFalse(Validator.validate(".", Validator.FLOATING_POINT));
130  1 assertFalse(Validator.validate("-.", Validator.FLOATING_POINT));
131  1 assertFalse(Validator.validate("ABC.01", Validator.FLOATING_POINT));
132    }
133   
 
134  1 toggle @Test
135    void isTime24Regex() {
136  1 assertTrue(Validator.validate("00:00", Validator.TIME_24H));
137  1 assertTrue(Validator.validate("00:01", Validator.TIME_24H));
138  1 assertTrue(Validator.validate("00:09", Validator.TIME_24H));
139   
140  1 assertTrue(Validator.validate("00:10", Validator.TIME_24H));
141  1 assertTrue(Validator.validate("01:11", Validator.TIME_24H));
142  1 assertTrue(Validator.validate("01:19", Validator.TIME_24H));
143   
144  1 assertTrue(Validator.validate("02:20", Validator.TIME_24H));
145  1 assertTrue(Validator.validate("02:21", Validator.TIME_24H));
146  1 assertTrue(Validator.validate("02:29", Validator.TIME_24H));
147   
148  1 assertTrue(Validator.validate("03:30", Validator.TIME_24H));
149  1 assertTrue(Validator.validate("03:31", Validator.TIME_24H));
150  1 assertTrue(Validator.validate("03:39", Validator.TIME_24H));
151   
152  1 assertTrue(Validator.validate("04:40", Validator.TIME_24H));
153  1 assertTrue(Validator.validate("04:41", Validator.TIME_24H));
154  1 assertTrue(Validator.validate("04:49", Validator.TIME_24H));
155   
156  1 assertTrue(Validator.validate("05:50", Validator.TIME_24H));
157  1 assertTrue(Validator.validate("05:51", Validator.TIME_24H));
158  1 assertTrue(Validator.validate("05:59", Validator.TIME_24H));
159   
160  1 assertTrue(Validator.validate("06:00", Validator.TIME_24H));
161  1 assertTrue(Validator.validate("07:00", Validator.TIME_24H));
162  1 assertTrue(Validator.validate("08:00", Validator.TIME_24H));
163  1 assertTrue(Validator.validate("09:00", Validator.TIME_24H));
164  1 assertTrue(Validator.validate("10:00", Validator.TIME_24H));
165  1 assertTrue(Validator.validate("11:00", Validator.TIME_24H));
166  1 assertTrue(Validator.validate("12:00", Validator.TIME_24H));
167  1 assertTrue(Validator.validate("13:00", Validator.TIME_24H));
168  1 assertTrue(Validator.validate("14:00", Validator.TIME_24H));
169  1 assertTrue(Validator.validate("15:00", Validator.TIME_24H));
170  1 assertTrue(Validator.validate("16:00", Validator.TIME_24H));
171  1 assertTrue(Validator.validate("17:00", Validator.TIME_24H));
172  1 assertTrue(Validator.validate("18:00", Validator.TIME_24H));
173  1 assertTrue(Validator.validate("19:00", Validator.TIME_24H));
174  1 assertTrue(Validator.validate("20:00", Validator.TIME_24H));
175  1 assertTrue(Validator.validate("21:00", Validator.TIME_24H));
176  1 assertTrue(Validator.validate("22:00", Validator.TIME_24H));
177  1 assertTrue(Validator.validate("23:00", Validator.TIME_24H));
178  1 assertTrue(Validator.validate("23:59", Validator.TIME_24H));
179    }
180   
 
181  1 toggle @Test
182    void isNotTime24Regex() {
183  1 assertFalse(Validator.validate("24:00", Validator.TIME_24H));
184  1 assertFalse(Validator.validate("24:01", Validator.TIME_24H));
185  1 assertFalse(Validator.validate("25:00", Validator.TIME_24H));
186   
187  1 assertFalse(Validator.validate("0:0", Validator.TIME_24H));
188  1 assertFalse(Validator.validate("1:20", Validator.TIME_24H));
189  1 assertFalse(Validator.validate("01:2", Validator.TIME_24H));
190   
191  1 assertFalse(Validator.validate("10:60", Validator.TIME_24H));
192  1 assertFalse(Validator.validate("10:61", Validator.TIME_24H));
193  1 assertFalse(Validator.validate("10:69", Validator.TIME_24H));
194   
195    }
196   
 
197  1 toggle @Test
198    void isRGBColor() {
199  1 assertTrue(Validator.validate("#000", Validator.RGB_COLOR));
200  1 assertTrue(Validator.validate("#fff", Validator.RGB_COLOR));
201  1 assertTrue(Validator.validate("#f0A", Validator.RGB_COLOR));
202   
203  1 assertTrue(Validator.validate("#000000", Validator.RGB_COLOR));
204  1 assertTrue(Validator.validate("#012345", Validator.RGB_COLOR));
205  1 assertTrue(Validator.validate("#999999", Validator.RGB_COLOR));
206   
207  1 assertTrue(Validator.validate("#aAAAaa", Validator.RGB_COLOR));
208  1 assertTrue(Validator.validate("#BBbbbb", Validator.RGB_COLOR));
209  1 assertTrue(Validator.validate("#cCcccC", Validator.RGB_COLOR));
210  1 assertTrue(Validator.validate("#dDdDdd", Validator.RGB_COLOR));
211  1 assertTrue(Validator.validate("#eEeeEE", Validator.RGB_COLOR));
212  1 assertTrue(Validator.validate("#fFFfff", Validator.RGB_COLOR));
213   
214  1 assertTrue(Validator.validate("#996789", Validator.RGB_COLOR));
215  1 assertTrue(Validator.validate("#6789Af", Validator.RGB_COLOR));
216    }
217   
 
218  1 toggle @Test
219    void isNotRGBColor() {
220  1 assertFalse(Validator.validate("#0", Validator.RGB_COLOR));
221  1 assertFalse(Validator.validate("#11af990", Validator.RGB_COLOR));
222   
223  1 assertFalse(Validator.validate("#9999", Validator.RGB_COLOR));
224  1 assertFalse(Validator.validate("#09090", Validator.RGB_COLOR));
225  1 assertFalse(Validator.validate("#a", Validator.RGB_COLOR));
226  1 assertFalse(Validator.validate("#ffff", Validator.RGB_COLOR));
227  1 assertFalse(Validator.validate("#AFaFA", Validator.RGB_COLOR));
228   
229  1 assertFalse(Validator.validate("#ggg", Validator.RGB_COLOR));
230    }
231   
 
232  1 toggle @Test
233    void isValidIP4ForLocalhost() {
234  1 assertTrue(Validator.validate("localhost", Validator.IP4_ADDRESS));
235    }
236   
 
237  1 toggle @Test
238    void isValidIP4ForLocalhostWithPort() {
239  1 assertTrue(Validator.validate("localhost:80", Validator.IP4_ADDRESS));
240    }
241   
 
242  1 toggle @Test
243    void isValidIP4() {
244  1 assertTrue(Validator.validate("127.0.0.1", Validator.IP4_ADDRESS));
245   
246  1 assertTrue(Validator.validate("0.0.0.0", Validator.IP4_ADDRESS));
247  1 assertTrue(Validator.validate("1.0.0.0", Validator.IP4_ADDRESS));
248  1 assertTrue(Validator.validate("0.1.0.0", Validator.IP4_ADDRESS));
249  1 assertTrue(Validator.validate("0.0.1.0", Validator.IP4_ADDRESS));
250  1 assertTrue(Validator.validate("0.0.0.1", Validator.IP4_ADDRESS));
251   
252  1 assertTrue(Validator.validate("20.20.20.20", Validator.IP4_ADDRESS));
253  1 assertTrue(Validator.validate("99.100.200.10", Validator.IP4_ADDRESS));
254  1 assertTrue(Validator.validate("140.145.240.245", Validator.IP4_ADDRESS));
255  1 assertTrue(Validator.validate("255.255.255.255", Validator.IP4_ADDRESS));
256    }
257   
 
258  1 toggle @Test
259    void isValidIP4_WithPort() {
260  1 assertTrue(Validator.validate("127.0.0.1:80", Validator.IP4_ADDRESS));
261   
262  1 assertTrue(Validator.validate("127.0.0.1:0", Validator.IP4_ADDRESS));
263  1 assertTrue(Validator.validate("127.0.0.1:1", Validator.IP4_ADDRESS));
264  1 assertTrue(Validator.validate("127.0.0.1:10", Validator.IP4_ADDRESS));
265  1 assertTrue(Validator.validate("127.0.0.1:100", Validator.IP4_ADDRESS));
266  1 assertTrue(Validator.validate("127.0.0.1:1000", Validator.IP4_ADDRESS));
267  1 assertTrue(Validator.validate("127.0.0.1:9999", Validator.IP4_ADDRESS));
268  1 assertTrue(Validator.validate("127.0.0.1:10000", Validator.IP4_ADDRESS));
269  1 assertTrue(Validator.validate("127.0.0.1:19999", Validator.IP4_ADDRESS));
270  1 assertTrue(Validator.validate("127.0.0.1:29999", Validator.IP4_ADDRESS));
271  1 assertTrue(Validator.validate("127.0.0.1:39999", Validator.IP4_ADDRESS));
272  1 assertTrue(Validator.validate("127.0.0.1:49999", Validator.IP4_ADDRESS));
273  1 assertTrue(Validator.validate("127.0.0.1:59999", Validator.IP4_ADDRESS));
274    //-----------------------------------------------------------------------
275  1 assertTrue(Validator.validate("127.0.0.1:60000", Validator.IP4_ADDRESS));
276  1 assertTrue(Validator.validate("127.0.0.1:61000", Validator.IP4_ADDRESS));
277  1 assertTrue(Validator.validate("127.0.0.1:62000", Validator.IP4_ADDRESS));
278  1 assertTrue(Validator.validate("127.0.0.1:63000", Validator.IP4_ADDRESS));
279  1 assertTrue(Validator.validate("127.0.0.1:64000", Validator.IP4_ADDRESS));
280  1 assertTrue(Validator.validate("127.0.0.1:64999", Validator.IP4_ADDRESS));
281    //-----------------------------------------------------------------------
282  1 assertTrue(Validator.validate("127.0.0.1:65000", Validator.IP4_ADDRESS));
283  1 assertTrue(Validator.validate("127.0.0.1:65499", Validator.IP4_ADDRESS));
284    //-----------------------------------------------------------------------
285  1 assertTrue(Validator.validate("127.0.0.1:65500", Validator.IP4_ADDRESS));
286  1 assertTrue(Validator.validate("127.0.0.1:65529", Validator.IP4_ADDRESS));
287    //-----------------------------------------------------------------------
288  1 assertTrue(Validator.validate("127.0.0.1:65530", Validator.IP4_ADDRESS));
289  1 assertTrue(Validator.validate("127.0.0.1:65535", Validator.IP4_ADDRESS));
290    }
291   
 
292  1 toggle @Test
293    void isIP4_WithInvalidPort() {
294  1 assertFalse(Validator.validate("127.0.0.1:65536", Validator.IP4_ADDRESS));
295  1 assertFalse(Validator.validate("127.0.0.1:555555", Validator.IP4_ADDRESS));
296    }
297   
 
298  1 toggle @Test
299    void isInvalidIP4_Format() {
300  1 assertFalse(Validator.validate("255.255.255", Validator.IP4_ADDRESS));
301  1 assertFalse(Validator.validate("255.255", Validator.IP4_ADDRESS));
302  1 assertFalse(Validator.validate("255", Validator.IP4_ADDRESS));
303    }
304   
 
305  1 toggle @Test
306    void isInvalidIP4_LedingZeros() {
307  1 assertFalse(Validator.validate("1.1.1.01", Validator.IP4_ADDRESS));
308  1 assertFalse(Validator.validate("1.1.1.001", Validator.IP4_ADDRESS));
309  1 assertFalse(Validator.validate("1.1.01.1", Validator.IP4_ADDRESS));
310  1 assertFalse(Validator.validate("1.1.001.1", Validator.IP4_ADDRESS));
311  1 assertFalse(Validator.validate("1.01.1.1", Validator.IP4_ADDRESS));
312  1 assertFalse(Validator.validate("1.001.1.1", Validator.IP4_ADDRESS));
313  1 assertFalse(Validator.validate("01.1.1.1", Validator.IP4_ADDRESS));
314  1 assertFalse(Validator.validate("001.1.1.1", Validator.IP4_ADDRESS));
315    }
316   
 
317  1 toggle @Test
318    void isInvalidIP4_Ending() {
319  1 assertFalse(Validator.validate("256.255.255.255", Validator.IP4_ADDRESS));
320  1 assertFalse(Validator.validate("255.256.255.255", Validator.IP4_ADDRESS));
321  1 assertFalse(Validator.validate("255.255.256.255", Validator.IP4_ADDRESS));
322  1 assertFalse(Validator.validate("255.255.255.256", Validator.IP4_ADDRESS));
323  1 assertFalse(Validator.validate("355.255.255.255", Validator.IP4_ADDRESS));
324    }
325   
 
326  1 toggle @Test
327    void isVersionNumber() {
328  1 assertTrue(Validator.validate("1", Validator.SEMANTIC_VERSION_NUMBER));
329  1 assertTrue(Validator.validate("9", Validator.SEMANTIC_VERSION_NUMBER));
330  1 assertTrue(Validator.validate("1.0", Validator.SEMANTIC_VERSION_NUMBER));
331  1 assertTrue(Validator.validate("1.0.0", Validator.SEMANTIC_VERSION_NUMBER));
332  1 assertTrue(Validator.validate("1.10", Validator.SEMANTIC_VERSION_NUMBER));
333  1 assertTrue(Validator.validate("1.0.10", Validator.SEMANTIC_VERSION_NUMBER));
334  1 assertTrue(Validator.validate("10.100.1000", Validator.SEMANTIC_VERSION_NUMBER));
335  1 assertTrue(Validator.validate("123.1234.12345", Validator.SEMANTIC_VERSION_NUMBER));
336  1 assertTrue(Validator.validate("1234", Validator.SEMANTIC_VERSION_NUMBER));
337  1 assertTrue(Validator.validate("12.1-SNAPSHOT", Validator.SEMANTIC_VERSION_NUMBER));
338  1 assertTrue(Validator.validate("1.109.1234567890", Validator.SEMANTIC_VERSION_NUMBER));
339   
340  1 assertTrue(Validator.validate("1-xYz", Validator.SEMANTIC_VERSION_NUMBER));
341  1 assertTrue(Validator.validate("1.2-SNAPSHOT", Validator.SEMANTIC_VERSION_NUMBER));
342  1 assertTrue(Validator.validate("1.2.3-xyzXYZxyzX", Validator.SEMANTIC_VERSION_NUMBER));
343    }
344   
 
345  1 toggle @Test
346    void isNotVersionNumber_StartWithZero() {
347  1 assertFalse(Validator.validate("0", Validator.SEMANTIC_VERSION_NUMBER));
348  1 assertFalse(Validator.validate("01.02", Validator.SEMANTIC_VERSION_NUMBER));
349  1 assertFalse(Validator.validate("1.0.03", Validator.SEMANTIC_VERSION_NUMBER));
350  1 assertFalse(Validator.validate("0.0.0-LABEL", Validator.SEMANTIC_VERSION_NUMBER));
351    }
352   
 
353  1 toggle @Test
354    void isNotVersionNumber_Format() {
355  1 assertFalse(Validator.validate("1.0.0.0", Validator.SEMANTIC_VERSION_NUMBER));
356  1 assertFalse(Validator.validate("A", Validator.SEMANTIC_VERSION_NUMBER));
357  1 assertFalse(Validator.validate(".1", Validator.SEMANTIC_VERSION_NUMBER));
358  1 assertFalse(Validator.validate("1.", Validator.SEMANTIC_VERSION_NUMBER));
359  1 assertFalse(Validator.validate("1.0.", Validator.SEMANTIC_VERSION_NUMBER));
360  1 assertFalse(Validator.validate("1.0.0.", Validator.SEMANTIC_VERSION_NUMBER));
361  1 assertFalse(Validator.validate("1.0.0-", Validator.SEMANTIC_VERSION_NUMBER));
362  1 assertFalse(Validator.validate("1.0.0-abcabcabcab", Validator.SEMANTIC_VERSION_NUMBER));
363    }
364   
 
365  1 toggle @Test
366    void isValidEMail() {
367  1 assertTrue(Validator.validate("john@sample.eu", Validator.E_MAIL_ADDRESS));
368  1 assertTrue(Validator.validate("john.doe@sample.org", Validator.E_MAIL_ADDRESS));
369  1 assertTrue(Validator.validate("john_doe@sample.org", Validator.E_MAIL_ADDRESS));
370  1 assertTrue(Validator.validate("john-doe@sample.org", Validator.E_MAIL_ADDRESS));
371  1 assertTrue(Validator.validate("john_doe@sample.org", Validator.E_MAIL_ADDRESS));
372  1 assertTrue(Validator.validate("_john-doe@sample.org", Validator.E_MAIL_ADDRESS));
373  1 assertTrue(Validator.validate("123@sample.org", Validator.E_MAIL_ADDRESS));
374  1 assertTrue(Validator.validate("_1@sample.org", Validator.E_MAIL_ADDRESS));
375  1 assertTrue(Validator.validate("a@sample.org", Validator.E_MAIL_ADDRESS));
376    }
377   
 
378  1 toggle @Test
379    void isInvalidEMail() {
380  1 assertFalse(Validator.validate("john@sample", Validator.E_MAIL_ADDRESS));
381  1 assertFalse(Validator.validate("john@", Validator.E_MAIL_ADDRESS));
382  1 assertFalse(Validator.validate("@sample.o", Validator.E_MAIL_ADDRESS));
383  1 assertFalse(Validator.validate("_@sample.o", Validator.E_MAIL_ADDRESS));
384  1 assertFalse(Validator.validate("john@sample.o", Validator.E_MAIL_ADDRESS));
385  1 assertFalse(Validator.validate("john.sample.o", Validator.E_MAIL_ADDRESS));
386  1 assertFalse(Validator.validate("-john.sample.o", Validator.E_MAIL_ADDRESS));
387    }
388   
 
389  1 toggle @Test
390    void isIntegerInRange() {
391  1 assertTrue(Validator.isIntegerInRange(1, 1, 5));
392  1 assertTrue(Validator.isIntegerInRange(3, 1, 5));
393  1 assertTrue(Validator.isIntegerInRange(5, 1, 5));
394    }
395   
 
396  1 toggle @Test
397    void isIntegerNotInRange() {
398  1 assertFalse(Validator.isIntegerInRange(0, 1, 5));
399  1 assertFalse(Validator.isIntegerInRange(6, 1, 5));
400    }
401   
 
402  1 toggle @Test
403    void isDateAfter() {
404    //now() is after 2015
405  1 assertTrue(Validator.isDateAfter(ZonedDateTime.now(),
406    ZonedDateTime.of(2015, 12, 31, 23, 59, 0, 0, ZoneId.of("UTC"))));
407    //after
408  1 assertTrue(Validator.isDateAfter(ZonedDateTime.of(2016, 1, 1, 0, 0, 0, 0, ZoneId.of("UTC")),
409    ZonedDateTime.of(2015, 12, 31, 23, 59, 0, 0, ZoneId.of("UTC"))));
410    }
411   
 
412  1 toggle @Test
413    void isDateNotAfter() {
414    //equal
415  1 assertFalse(Validator.isDateAfter(ZonedDateTime.of(2015, 12, 31, 23, 59, 0, 0, ZoneId.of("UTC")),
416    ZonedDateTime.of(2015, 12, 31, 23, 59, 0, 0, ZoneId.of("UTC"))));
417   
418  1 assertFalse(Validator.isDateAfter(null, null));
419  1 assertFalse(Validator.isDateAfter(ZonedDateTime.now(), null));
420  1 assertFalse(Validator.isDateAfter(null, ZonedDateTime.now()));
421   
422  1 assertFalse(Validator.isDateAfter(ZonedDateTime.of(2015, 12, 31, 23, 59, 0, 0, ZoneId.of("UTC")), ZonedDateTime.now()));
423  1 assertFalse(Validator.isDateAfter(ZonedDateTime.of(2015, 12, 31, 23, 59, 0, 0, ZoneId.of("UTC")),
424    ZonedDateTime.of(2016, 12, 31, 23, 59, 0, 0, ZoneId.of("UTC"))));
425    }
426   
 
427  1 toggle @Test
428    void isDateBefore() {
429    //2015 is before now() => TRUE
430  1 assertTrue(Validator.isDateBefore(ZonedDateTime.of(2015, 12, 31, 23, 59, 0, 0, ZoneId.of("UTC")),
431    ZonedDateTime.now()));
432    //before
433  1 assertTrue(Validator.isDateBefore(ZonedDateTime.of(2015, 12, 31, 23, 59, 0, 0, ZoneId.of("UTC")),
434    ZonedDateTime.of(2016, 1, 1, 0, 0, 0, 0, ZoneId.of("UTC"))));
435    }
436   
 
437  1 toggle @Test
438    void isDateNotBefore() {
439    //equal
440  1 assertFalse(Validator.isDateAfter(ZonedDateTime.of(2015, 12, 31, 23, 59, 0, 0, ZoneId.of("UTC")),
441    ZonedDateTime.of(2015, 12, 31, 23, 59, 0, 0, ZoneId.of("UTC"))));
442   
443  1 assertFalse(Validator.isDateBefore(null, null));
444  1 assertFalse(Validator.isDateBefore(ZonedDateTime.now(), null));
445  1 assertFalse(Validator.isDateBefore(null, ZonedDateTime.now()));
446    //now() is before 2015 => FALSE
447  1 assertFalse(Validator.isDateBefore(ZonedDateTime.now(), ZonedDateTime.of(2015, 12, 31, 23, 59, 0, 0, ZoneId.of("UTC"))));
448  1 assertFalse(Validator.isDateBefore(ZonedDateTime.of(2015, 12, 31, 23, 59, 0, 0, ZoneId.of("UTC")),
449    ZonedDateTime.of(2015, 12, 31, 23, 49, 0, 0, ZoneId.of("UTC"))));
450    }
451   
 
452  1 toggle @Test
453    void isDateInRange() {
454  1 assertTrue(Validator.isDateInRange(
455    ZonedDateTime.of(2015, 6, 15, 12, 0, 0, 0, ZoneId.of("UTC")),
456    ZonedDateTime.of(2014, 1, 1, 0, 0, 0, 0, ZoneId.of("UTC")),
457    ZonedDateTime.of(2016, 12, 31, 23, 59, 0, 0, ZoneId.of("UTC"))
458    ));
459    }
460   
 
461  1 toggle @Test
462    void isDateNotInRange() {
463  1 ZonedDateTime check = ZonedDateTime.now();
464  1 assertFalse(Validator.isDateInRange(check, check, check));
465    }
466   
 
467  1 toggle @Test
468    void isDateNotInRange_LowerBoundry() {
469  1 assertFalse(Validator.isDateInRange(
470    ZonedDateTime.of(2014, 1, 1, 0, 0, 0, 0, ZoneId.of("UTC")),
471    ZonedDateTime.of(2014, 1, 1, 0, 0, 0, 0, ZoneId.of("UTC")),
472    ZonedDateTime.of(2016, 12, 31, 23, 59, 0, 0, ZoneId.of("UTC"))
473    ));
474    }
475   
 
476  1 toggle @Test
477    void isDateNotInRange_UpperBoundry() {
478  1 assertFalse(Validator.isDateInRange(
479    ZonedDateTime.of(2016, 12, 31, 23, 59, 0, 0, ZoneId.of("UTC")),
480    ZonedDateTime.of(2014, 1, 1, 0, 0, 0, 0, ZoneId.of("UTC")),
481    ZonedDateTime.of(2016, 12, 31, 23, 59, 0, 0, ZoneId.of("UTC"))
482    ));
483    }
484   
 
485  1 toggle @Test
486    void isDateNotInRange_After() {
487  1 assertFalse(Validator.isDateInRange(
488    ZonedDateTime.of(2017, 1, 1, 12, 0, 0, 0, ZoneId.of("UTC")),
489    ZonedDateTime.of(2014, 1, 1, 0, 0, 0, 0, ZoneId.of("UTC")),
490    ZonedDateTime.of(2016, 12, 31, 23, 59, 0, 0, ZoneId.of("UTC"))
491    ));
492    }
493   
 
494  1 toggle @Test
495    void isDateNotInRange_Before() {
496  1 assertFalse(Validator.isDateInRange(
497    ZonedDateTime.of(2013, 1, 1, 0, 0, 0, 0, ZoneId.of("UTC")),
498    ZonedDateTime.of(2014, 1, 1, 0, 0, 0, 0, ZoneId.of("UTC")),
499    ZonedDateTime.of(2016, 12, 31, 23, 59, 0, 0, ZoneId.of("UTC"))
500    ));
501    }
502   
 
503  1 toggle @Test
504    void isDateNotInRange_NullPointer() {
505  1 assertFalse(Validator.isDateInRange(null, ZonedDateTime.now(), ZonedDateTime.now()));
506  1 assertFalse(Validator.isDateInRange(ZonedDateTime.now(), null, ZonedDateTime.now()));
507  1 assertFalse(Validator.isDateInRange(ZonedDateTime.now(), ZonedDateTime.now(), null));
508   
509  1 assertFalse(Validator.isDateInRange(ZonedDateTime.now(), null, null));
510  1 assertFalse(Validator.isDateInRange(null, ZonedDateTime.now(), null));
511  1 assertFalse(Validator.isDateInRange(null, null, ZonedDateTime.now()));
512   
513  1 assertFalse(Validator.isDateInRange(null, null, null));
514    }
515   
 
516  1 toggle @Test
517    void isValidIsbn10() {
518  1 assertTrue(Validator.isIsbn("3836278340"));
519  1 assertTrue(Validator.isIsbn("38-3627-834-0"));
520  1 assertTrue(Validator.isIsbn("0-9752298-0-X"));
521    }
522   
 
523  1 toggle @Test
524    void isInvalidIsbn10() {
525  1 assertFalse(Validator.isIsbn("3836278344"));
526  1 assertFalse(Validator.isIsbn("9836278340"));
527    }
528   
 
529  1 toggle @Test
530    void isValidIsbn13() {
531  1 assertTrue(Validator.isIsbn("9783836278348"));
532  1 assertTrue(Validator.isIsbn("978-3-8362-7834-8"));
533    }
534   
 
535  1 toggle @Test
536    void isInvalidIsbn13() {
537  1 assertFalse(Validator.isIsbn("9783846278348"));
538    }
539   
 
540  1 toggle @Test
541    void isInvalidIsbn_NotInterger() throws Exception {
542  1 assertThrows(Exception.class, () -> {
543  1 Validator.isIsbn("d836278340");
544    });
545    }
546   
 
547  1 toggle @Test
548    void isInvalidIsbn_empty() throws Exception {
549  1 assertThrows(Exception.class, () -> {
550  1 Validator.isIsbn("");
551    });
552    }
553   
 
554  1 toggle @Test
555    void isInvalidIsbn10_toShort() throws Exception {
556  1 assertThrows(Exception.class, () -> {
557  1 Validator.isIsbn("383627834");
558    });
559    }
560   
 
561  0 toggle void isInvalidIsbn10_tolong() throws Exception {
562  0 assertThrows(Exception.class, () -> {
563  0 Validator.isIsbn("38362783400");
564    });
565    }
566   
 
567  1 toggle @Test
568    void isInvalidIsbn13_toShort() throws Exception {
569  1 assertThrows(Exception.class, () -> {
570  1 Validator.isIsbn("978383627834");
571    });
572    }
573   
 
574  0 toggle void isInvalidIsbn13_tolong() throws Exception {
575  0 assertThrows(Exception.class, () -> {
576  0 Validator.isIsbn("97838362783481");
577    });
578    }
579    }