1   /*
2    * Copyright Tui Software 2006
3    * 
4    * $Id: AssertTests.java 2092 2008-10-31 14:17:48Z ldoclo $
5    */
6   package org.springframework.richclient.util;
7   
8   import junit.framework.TestCase;
9   
10  
11  /**
12   * Unit tests for the {@link Assert} class.
13   *
14   * @author Kevin Stembridge
15   * @since 0.3
16   *
17   */
18  public class AssertTests extends TestCase {
19  
20      /**
21       * Test method for {@link Assert#required(java.lang.Object, java.lang.String)}.
22       */
23      public final void testRequired() {
24          
25          Assert.required(new Object(), "object");
26          Assert.required(new Object(), null);
27          
28          try {
29              Assert.required(null, "bogus");
30              fail("Should have thrown an IllegalArgumentException");
31          }
32          catch(IllegalArgumentException e) {
33              //do nothing, test succeeded
34          }
35          
36      }
37  
38      /**
39       * Test method for {@link Assert#noElementsNull(java.lang.Object[])}.
40       */
41      public final void testNoElementsNull() {
42          
43          Object[] array = new Object[0];
44          
45          Assert.noElementsNull(array, null);
46          Assert.noElementsNull(array, "bogusArray");
47          
48          try {
49              Assert.noElementsNull(null, "bogusArray");
50              fail("Should have thrown an IllegalArgumentException");
51          }
52          catch (IllegalArgumentException e) {
53              //do nothing, test succeeded
54          }
55          
56          array = new Object[1];
57          
58          try {
59              Assert.noElementsNull(null, "bogusArray");
60              fail("Should have thrown an IllegalArgumentException for a non-null array with a null element");
61          }
62          catch (IllegalArgumentException e) {
63              //do nothing, test succeeded
64          }
65          
66          array = new Object[] {"bogus", null};
67          
68          try {
69              Assert.noElementsNull(null, "bogusArray");
70              fail("Should have thrown an IllegalArgumentException for a non-null array with a null element");
71          }
72          catch (IllegalArgumentException e) {
73              //do nothing, test succeeded
74          }
75          
76      }
77  
78  }