View Javadoc
1   /**
2    * Copyright 2005-2015 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.datadictionary.validation.utils;
17  
18  import org.junit.Test;
19  import org.junit.Assert;
20  import org.kuali.rice.krad.datadictionary.validation.Person;
21  import org.kuali.rice.krad.datadictionary.validation.ValidationUtils;
22  
23  import java.util.ArrayList;
24  import java.util.HashMap;
25  import java.util.HashSet;
26  
27  /**
28   * Unit test for ValidationUtils.isNullOrEmpty()
29   */
30  public class NullOrEmptyTest {
31  
32      @Test
33      public void testNullObject() {
34          Person person = null ;
35          Assert.assertTrue(ValidationUtils.isNullOrEmpty(person));
36      }
37  
38      @Test
39      public void testNotNullObject() {
40          Person person = new Person();
41          Assert.assertFalse(ValidationUtils.isNullOrEmpty(person));
42      }
43  
44      @Test
45      public void testStringEmpty() {
46          String message = "";
47          Assert.assertTrue(ValidationUtils.isNullOrEmpty(message));
48      }
49  
50      @Test
51      public void testStringNotEmpty() {
52          String message = "Hi";
53          Assert.assertFalse(ValidationUtils.isNullOrEmpty(message));
54      }
55  
56      @Test
57      public void testListEmpty() {
58          ArrayList<String> quickList = new ArrayList<String>();
59          Assert.assertTrue(ValidationUtils.isNullOrEmpty(quickList));
60      }
61  
62      @Test
63      public void testListNotEmpty() {
64          ArrayList<String> quickList = new ArrayList<String>();
65          quickList.add("Hi");
66          Assert.assertFalse(ValidationUtils.isNullOrEmpty(quickList));
67      }
68  
69      @Test
70      public void testSetEmpty() {
71          HashSet<String> quickSet = new HashSet<String>() ;
72          Assert.assertTrue(ValidationUtils.isNullOrEmpty(quickSet));
73      }
74  
75      @Test
76      public void testSetNotEmpty() {
77          HashSet<String> quickSet = new HashSet<String>() ;
78          quickSet.add("Hi");
79          Assert.assertFalse(ValidationUtils.isNullOrEmpty(quickSet));
80      }
81  
82      @Test
83      public void testMapEmpty() {
84          HashMap<String, String> quickMap = new HashMap<String, String>();
85          Assert.assertTrue(ValidationUtils.isNullOrEmpty(quickMap));
86      }
87  
88      @Test
89      public void testMapNotEmpty() {
90          HashMap<String, String> quickMap = new HashMap<String, String>();
91          quickMap.put("Hi", "There!");
92          Assert.assertFalse(ValidationUtils.isNullOrEmpty(quickMap));
93      }
94  }