1 54 55 package junitx.framework; 56 57 import java.util.List ; 58 59 65 public class ListAssert { 66 67 70 private ListAssert() { 71 } 72 73 77 public static void assertEquals(List expected, List actual) { 78 assertEquals(null, expected, actual); 79 } 80 81 85 public static void assertEquals(String message, List expected, List actual) { 86 if ((expected == null && actual == null) || (expected != null && expected.equals(actual))) { 87 return; 88 } 89 90 for (int ii = 0; ii < expected.size(); ii++) { 91 assertContains(message, actual, expected.get(ii)); 92 } 93 String formatted = "[length]"; 94 if (message != null) { 95 formatted = message + " " + formatted; 96 } 97 98 Assert.assertEquals(formatted, expected.size(), actual.size()); 99 } 100 101 105 public static void assertContains(List actual, Object value) { 106 assertContains(null, actual, value); 107 } 108 109 113 public static void assertContains(String message, List actual, Object value) { 114 Assert.assertNotNull(message, actual); 115 if (actual.contains(value)) { 116 return; 117 } 118 failNotContains(message, actual, value); 119 } 120 121 private static void failNotContains(String message, List actual, Object value) { 122 String formatted = ""; 123 if (message != null) { 124 formatted = message + " "; 125 } 126 127 StringBuffer listcontent = new StringBuffer (); 128 for (int ii = 0; ii < actual.size() - 1; ii++) { 129 listcontent.append(actual.get(ii)).append(", "); 130 } 131 listcontent.append(actual.get(actual.size() - 1)); 132 133 throw new junit.framework.AssertionFailedError(formatted + "expecting <" + value + "> in <" + listcontent.toString() + ">"); 134 } 135 136 } 137 | Popular Tags |