View Javadoc
1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
25   *
26   */
27  
28  package org.apache.http.util;
29  
30  import java.util.Arrays;
31  import java.util.Collections;
32  import java.util.List;
33  
34  import org.junit.Assert;
35  import org.junit.Test;
36  
37  /**
38   * Unit tests for {@link Args}.
39   */
40  public class TestArgs {
41  
42      @Test
43      public void testArgCheckPass() {
44          Args.check(true, "All is well");
45      }
46  
47      @Test(expected=IllegalArgumentException.class)
48      public void testArgCheckFail() {
49          Args.check(false, "Oopsie");
50      }
51  
52      @Test
53      public void testArgNotNullPass() {
54          final String stuff = "stuff";
55          Assert.assertSame(stuff, Args.notNull(stuff, "Stuff"));
56      }
57  
58      @Test(expected=IllegalArgumentException.class)
59      public void testArgNotNullFail() {
60          Args.notNull(null, "Stuff");
61      }
62  
63      @Test
64      public void testArgNotEmptyPass() {
65          final String stuff = "stuff";
66          Assert.assertSame(stuff, Args.notEmpty(stuff, "Stuff"));
67      }
68  
69      @Test(expected=IllegalArgumentException.class)
70      public void testArgNotEmptyFail1() {
71          Args.notEmpty((String) null, "Stuff");
72      }
73  
74      @Test(expected=IllegalArgumentException.class)
75      public void testArgNotEmptyFail2() {
76          Args.notEmpty("", "Stuff");
77      }
78  
79      @Test(expected=IllegalArgumentException.class)
80      public void testArgNotBlankFail1() {
81          Args.notBlank((String) null, "Stuff");
82      }
83  
84      @Test(expected=IllegalArgumentException.class)
85      public void testArgNotBlankFail2() {
86          Args.notBlank("", "Stuff");
87      }
88  
89      @Test(expected=IllegalArgumentException.class)
90      public void testArgNotBlankFail3() {
91          Args.notBlank(" \t \n\r", "Stuff");
92      }
93  
94      @Test
95      public void testArgCollectionNotEmptyPass() {
96          final List<String> list = Arrays.asList("stuff");
97          Assert.assertSame(list, Args.notEmpty(list, "List"));
98      }
99  
100     @Test(expected=IllegalArgumentException.class)
101     public void testArgCollectionNotEmptyFail1() {
102         Args.notEmpty((List<?>) null, "List");
103     }
104 
105     @Test(expected=IllegalArgumentException.class)
106     public void testArgCollectionNotEmptyFail2() {
107         Args.notEmpty(Collections.emptyList(), "List");
108     }
109 
110     @Test
111     public void testPositiveIntPass() {
112         Assert.assertEquals(1, Args.positive(1, "Number"));
113     }
114 
115     @Test(expected=IllegalArgumentException.class)
116     public void testPositiveIntFail1() {
117         Args.positive(-1, "Number");
118     }
119 
120     @Test(expected=IllegalArgumentException.class)
121     public void testPositiveIntFail2() {
122         Args.positive(0, "Number");
123     }
124 
125     @Test
126     public void testPositiveLongPass() {
127         Assert.assertEquals(1L, Args.positive(1L, "Number"));
128     }
129 
130     @Test(expected=IllegalArgumentException.class)
131     public void testPositiveLongFail1() {
132         Args.positive(-1L, "Number");
133     }
134 
135     @Test(expected=IllegalArgumentException.class)
136     public void testPositiveLongFail2() {
137         Args.positive(0L, "Number");
138     }
139 
140     @Test
141     public void testNotNegativeIntPass1() {
142         Assert.assertEquals(1, Args.notNegative(1, "Number"));
143     }
144 
145     @Test
146     public void testNotNegativeIntPass2() {
147         Assert.assertEquals(0, Args.notNegative(0, "Number"));
148     }
149 
150     @Test(expected=IllegalArgumentException.class)
151     public void testNotNegativeIntFail1() {
152         Args.notNegative(-1, "Number");
153     }
154 
155     @Test
156     public void testNotNegativeLongPass1() {
157         Assert.assertEquals(1L, Args.notNegative(1L, "Number"));
158     }
159 
160     @Test
161     public void testNotNegativeLongPass2() {
162         Assert.assertEquals(0L, Args.notNegative(0L, "Number"));
163     }
164 
165     @Test(expected=IllegalArgumentException.class)
166     public void testNotNegativeLongFail1() {
167         Args.notNegative(-1L, "Number");
168     }
169 
170 }