001    /*
002     * Copyright Tui Software 2006
003     * 
004     * $Id: AssertTests.java 2092 2008-10-31 14:17:48Z ldoclo $
005     */
006    package org.springframework.richclient.util;
007    
008    import junit.framework.TestCase;
009    
010    
011    /**
012     * Unit tests for the {@link Assert} class.
013     *
014     * @author Kevin Stembridge
015     * @since 0.3
016     *
017     */
018    public class AssertTests extends TestCase {
019    
020        /**
021         * Test method for {@link Assert#required(java.lang.Object, java.lang.String)}.
022         */
023        public final void testRequired() {
024            
025            Assert.required(new Object(), "object");
026            Assert.required(new Object(), null);
027            
028            try {
029                Assert.required(null, "bogus");
030                fail("Should have thrown an IllegalArgumentException");
031            }
032            catch(IllegalArgumentException e) {
033                //do nothing, test succeeded
034            }
035            
036        }
037    
038        /**
039         * Test method for {@link Assert#noElementsNull(java.lang.Object[])}.
040         */
041        public final void testNoElementsNull() {
042            
043            Object[] array = new Object[0];
044            
045            Assert.noElementsNull(array, null);
046            Assert.noElementsNull(array, "bogusArray");
047            
048            try {
049                Assert.noElementsNull(null, "bogusArray");
050                fail("Should have thrown an IllegalArgumentException");
051            }
052            catch (IllegalArgumentException e) {
053                //do nothing, test succeeded
054            }
055            
056            array = new Object[1];
057            
058            try {
059                Assert.noElementsNull(null, "bogusArray");
060                fail("Should have thrown an IllegalArgumentException for a non-null array with a null element");
061            }
062            catch (IllegalArgumentException e) {
063                //do nothing, test succeeded
064            }
065            
066            array = new Object[] {"bogus", null};
067            
068            try {
069                Assert.noElementsNull(null, "bogusArray");
070                fail("Should have thrown an IllegalArgumentException for a non-null array with a null element");
071            }
072            catch (IllegalArgumentException e) {
073                //do nothing, test succeeded
074            }
075            
076        }
077    
078    }