1 package junitx.framework; 2 3 import javax.naming.directory.Attribute ; 4 import javax.naming.directory.*; 5 import javax.naming.directory.BasicAttributes ; 6 7 import junit.framework.AssertionFailedError; 8 import junit.framework.TestCase; 9 10 14 public class NamingAssertTest extends TestCase { 15 16 public NamingAssertTest(String name) { 17 super(name); 18 } 19 20 public void testEqualsAttributesSingleValue() { 21 Attributes expected = new BasicAttributes (); 22 expected.put(new BasicAttribute("attrID", "value1")); 23 24 Attributes actual = new BasicAttributes (); 25 actual.put(new BasicAttribute("attrID", "value1")); 26 27 NamingAssert.assertEquals(expected, actual); 28 } 29 30 public void testFailAttributesNullActual() { 31 Attributes expected = new BasicAttributes (); 32 expected.put(new BasicAttribute("attrID", "value1")); 33 try { 34 NamingAssert.assertEquals(expected, null); 35 } catch (AssertionFailedError e) { 36 assertEquals("[actual] expected not <null>", e.getMessage()); 37 return; 38 } 39 fail(); 40 } 41 42 public void testFailAttributesNullExpected() { 43 Attributes actual = new BasicAttributes (); 44 actual.put(new BasicAttribute("attrID", "value1")); 45 try { 46 NamingAssert.assertEquals(null, actual); 47 } catch (AssertionFailedError e) { 48 assertEquals("[expected] expected not <null>", e.getMessage()); 49 return; 50 } 51 fail(); 52 } 53 54 public void testFailEqualsAttributesSingleValue() { 55 Attributes expected = new BasicAttributes (); 56 expected.put(new BasicAttribute("attrID", "value1")); 57 58 Attributes actual = new BasicAttributes (); 59 actual.put(new BasicAttribute("attrID", "value2")); 60 try { 61 NamingAssert.assertEquals(expected, actual); 62 } catch (AssertionFailedError e) { 63 assertEquals("expecting <value1> in <value2>", e.getMessage()); 64 return; 65 } 66 fail(); 67 } 68 69 public void testEqualsAttributeSingleValue() { 70 Attribute expected = new BasicAttribute("attrID", "value1"); 71 Attribute actual = new BasicAttribute("attrID", "value1"); 72 73 NamingAssert.assertEquals(expected, actual); 74 } 75 76 public void testFailAttributeNullActual() { 77 Attribute expected = new BasicAttribute("attrID", "value1"); 78 try { 79 NamingAssert.assertEquals(expected, null); 80 } catch (AssertionFailedError e) { 81 assertEquals("[actual] expected not <null>", e.getMessage()); 82 return; 83 } 84 fail(); 85 } 86 87 public void testFailAttributeNullExpected() { 88 Attribute actual = new BasicAttribute("attrID", "value1"); 89 try { 90 NamingAssert.assertEquals(null, actual); 91 } catch (AssertionFailedError e) { 92 assertEquals("[expected] expected not <null>", e.getMessage()); 93 return; 94 } 95 fail(); 96 } 97 98 public void testFailEqualsAttributeSingleValue() { 99 Attribute expected = new BasicAttribute("attrID", "value1"); 100 Attribute actual = new BasicAttribute("attrID", "value2"); 101 try { 102 NamingAssert.assertEquals(expected, actual); 103 } catch (AssertionFailedError e) { 104 assertEquals("expecting <value1> in <value2>", e.getMessage()); 105 return; 106 } 107 fail(); 108 } 109 110 } 111 | Popular Tags |