1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.util.lang;
17
18 import static org.hamcrest.MatcherAssert.assertThat;
19 import static org.hamcrest.Matchers.allOf;
20 import static org.hamcrest.Matchers.containsString;
21
22 import org.junit.Test;
23 import org.junit.experimental.categories.Category;
24
25 import de.smartics.testdoc.annotations.Uut;
26 import de.smartics.testdoc.categories.type.Coverage;
27 import de.smartics.util.test.lang.LangTestUtils;
28
29
30
31
32 @Uut(type = Arguments.class)
33 public class ArgumentsTest
34 {
35
36
37
38
39 private static final String ARGUMENT_NAME = "arg";
40
41 private static final Object OBJECT_VALUE = "object";
42
43 private static final String STRING_VALUE = "string";
44
45 private static final String MESSAGE = "message";
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61 @Test(expected = NullPointerException.class)
62 public void rejectsNullValueWithNullPointerException()
63 {
64 Arguments.checkNotNull(ARGUMENT_NAME, null);
65 }
66
67 @Test
68 public void acceptsNonNullValue()
69 {
70 Arguments.checkNotNull(ARGUMENT_NAME, OBJECT_VALUE);
71 }
72
73 @SuppressWarnings("unchecked")
74 @Test(expected = NullPointerException.class)
75 public void allowsToPassAnOptionalMessageForNullCheck()
76 {
77 try
78 {
79 Arguments.checkNotNull(ARGUMENT_NAME, null, MESSAGE);
80 }
81 catch (final NullArgumentException e)
82 {
83 assertThat(e.getMessage(),
84 allOf(containsString(ARGUMENT_NAME), containsString(MESSAGE)));
85 throw e;
86 }
87 }
88
89 @Test
90 @Category(Coverage.class)
91 public void allowsToPassAnOptionalMessageForNullCheckEvenIfNoExceptionIsThrown()
92 {
93 Arguments.checkNotNull(ARGUMENT_NAME, OBJECT_VALUE, MESSAGE);
94 }
95
96
97
98 @Test(expected = BlankArgumentException.class)
99 public void rejectsBlankValueWithNullPointerException()
100 {
101 Arguments.checkNotBlank(ARGUMENT_NAME, null);
102 }
103
104 @Test
105 public void acceptsNonBlankValue()
106 {
107 Arguments.checkNotBlank(ARGUMENT_NAME, STRING_VALUE);
108 }
109
110 @SuppressWarnings("unchecked")
111 @Test(expected = BlankArgumentException.class)
112 public void allowsToPassAnOptionalMessageForBlankCheck()
113 {
114 try
115 {
116 Arguments.checkNotBlank(ARGUMENT_NAME, null, MESSAGE);
117 }
118 catch (final BlankArgumentException e)
119 {
120 assertThat(e.getMessage(),
121 allOf(containsString(ARGUMENT_NAME), containsString(MESSAGE)));
122 throw e;
123 }
124 }
125
126 @Test
127 @Category(Coverage.class)
128 public void allowsToPassAnOptionalMessageForBlankCheckEvenIfNoExceptionIsThrown()
129 {
130 Arguments.checkNotNull(ARGUMENT_NAME, OBJECT_VALUE, MESSAGE);
131 }
132
133
134
135 @Test
136 @Category(Coverage.class)
137 public void isAnUtilityClass()
138 {
139 LangTestUtils.runPrivateConstructorTest(Arguments.class);
140 }
141 }