1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.protect;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
/**
* @author bratseth
*/
public class ValidatorTestCase {
@Test
public void testEnsureNotNull() {
try {
Validator.ensureNotNull("Description",null);
fail("No exception");
}
catch (Exception e) {
// success
}
}
@Test
public void testEnsureNotInitialized() {
try {
Validator.ensureNotInitialized("Description","Field-owner","Initialized-field-value");
fail("No exception");
}
catch (Exception e) {
// success
}
}
@Test
public void testEnsureInRange() {
try {
Validator.ensureInRange("Description",2,4,5);
fail("No exception");
}
catch (Exception e) {
// success
}
}
@Test
public void testSmallerInts() {
try {
Validator.ensureSmaller("Small-description",3,"Large-description",2);
fail("No exception");
}
catch (Exception e) {
// success
}
}
@Test
public void testSmallerComparables() {
try {
Validator.ensureSmaller("Small-description","b","Large-description","a");
fail("No exception");
}
catch (Exception e) {
// success
}
}
@Test
public void testEnsure() {
try {
Validator.ensure("Description",false);
fail("No exception");
}
catch (Exception e) {
// success
}
}
@Test
public void testEnsureInstanceOf() {
try {
Validator.ensureInstanceOf("Description","item",Integer.class);
fail("No exception");
}
catch (Exception e) {
// success
}
}
@Test
public void testVarArgsEnsure() {
Validator.ensure(true, "ignored");
try {
Validator.ensure(false, "a", "b", "c");
} catch (Exception e) {
assertEquals("abc", e.getMessage());
}
}
}
|