1 15 package org.apache.hivemind; 16 17 import org.apache.hivemind.test.HiveMindTestCase; 18 import org.apache.hivemind.util.Defense; 19 20 26 public class TestDefense extends HiveMindTestCase 27 { 28 public void testNotNull() 29 { 30 Defense.notNull("foo", "bar"); 31 } 32 33 public void testIsNull() 34 { 35 try 36 { 37 Defense.notNull(null, "woops"); 38 unreachable(); 39 } 40 catch (NullPointerException ex) 41 { 42 assertEquals(HiveMindMessages.paramNotNull("woops"), ex.getMessage()); 43 } 44 } 45 46 public void testCorrectType() 47 { 48 Defense.isAssignable("Hello", String .class, "param"); 49 } 50 51 public void testIncorrectType() 52 { 53 try 54 { 55 Defense.isAssignable("Hello", Number .class, "param"); 56 unreachable(); 57 } 58 catch (ClassCastException ex) 59 { 60 assertEquals( 61 "Parameter param is of type java.lang.String which is not compatible with java.lang.Number.", 62 ex.getMessage()); 63 } 64 } 65 66 public void testIncorrectTypeWithArrays() 67 { 68 try 69 { 70 Defense.isAssignable(new int[0], String [].class, "param"); 71 unreachable(); 72 } 73 catch (ClassCastException ex) 74 { 75 assertEquals( 76 "Parameter param is of type int[] which is not compatible with java.lang.String[].", 77 ex.getMessage()); 78 } 79 } 80 } | Popular Tags |