1 54 55 package junitx.framework; 56 57 import javax.naming.NamingEnumeration ; 58 import javax.naming.NamingException ; 59 import javax.naming.directory.Attribute ; 60 import javax.naming.directory.Attributes ; 61 62 import junit.framework.Assert; 63 import junitx.util.NamingUtil; 64 65 72 public class NamingAssert { 73 74 77 private NamingAssert() { 78 } 79 80 84 public static void assertEquals(Attributes expected, Attributes actual) { 85 assertEquals(null, expected, actual); 86 } 87 88 92 public static void assertEquals(String message, Attributes expected, Attributes actual) { 93 if ((expected == null && actual == null) || (expected != null && expected.equals(actual))) { 94 return; 95 } 96 97 String formatted = ""; 98 if (message != null) { 99 formatted = message + " "; 100 } 101 102 Assert.assertNotNull(formatted + "[expected] expected not <null>", expected); 103 Assert.assertNotNull(formatted + "[actual] expected not <null>", actual); 104 105 try { 106 NamingEnumeration ids = expected.getIDs(); 107 while (ids.hasMore()) { 108 String key = ids.next().toString(); 109 assertEquals(message, expected.get(key), actual.get(key)); 110 } 111 } catch (NamingException e) { 112 throw new AssertionFailedError(e); 113 } 114 } 115 116 120 public static void assertEquals(Attribute expected, Attribute actual) { 121 assertEquals(null, expected, actual); 122 } 123 124 128 public static void assertEquals(String message, Attribute expected, Attribute actual) { 129 if ((expected == null && actual == null) || (expected != null && expected.equals(actual))) { 130 return; 131 } 132 133 String formatted = ""; 134 if (message != null) { 135 formatted = message + " "; 136 } 137 138 Assert.assertNotNull(formatted + "[expected] expected not <null>", expected); 139 Assert.assertNotNull(formatted + "[actual] expected not <null>", actual); 140 141 try { 142 assertEquals(message, expected.getAll(), actual.getAll()); 143 } catch (NamingException e) { 144 throw new AssertionFailedError(e); 145 } 146 } 147 148 152 public static void assertEquals(NamingEnumeration expected, NamingEnumeration actual) { 153 assertEquals(null, expected, actual); 154 } 155 156 160 public static void assertEquals(String message, NamingEnumeration expected, NamingEnumeration actual) { 161 try { 162 ListAssert.assertEquals(message, NamingUtil.toList(expected), NamingUtil.toList(actual)); 163 } catch (NamingException e) { 164 throw new AssertionFailedError(e); 165 } 166 } 167 168 } 169 | Popular Tags |