You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

IteratorWrapperTest.java 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /* *******************************************************************
  2. * Copyright (c) 1999-2001 Xerox Corporation,
  3. * 2002 Palo Alto Research Center, Incorporated (PARC).
  4. * All rights reserved.
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Public License v1.0
  7. * which accompanies this distribution and is available at
  8. * http://www.eclipse.org/legal/epl-v10.html
  9. *
  10. * Contributors:
  11. * Xerox/PARC initial implementation
  12. * ******************************************************************/
  13. package org.aspectj.testing.util;
  14. import java.util.Arrays;
  15. import java.util.Collections;
  16. import java.util.List;
  17. import junit.framework.TestCase;
  18. /**
  19. *
  20. */
  21. public class IteratorWrapperTest extends TestCase {
  22. /**
  23. * Constructor for IteratorWrapperTest.
  24. * @param name
  25. */
  26. public IteratorWrapperTest(String name) {
  27. super(name);
  28. }
  29. public void testIteratorWrapper() {
  30. Object[][] exp = new Object[][] {};
  31. List[] in = new List[] {};
  32. checkIteratorWrapper(in, exp);
  33. in = new List[] {Collections.EMPTY_LIST};
  34. checkIteratorWrapper(in, exp);
  35. in = new List[] {Collections.EMPTY_LIST, Collections.EMPTY_LIST};
  36. checkIteratorWrapper(in, exp);
  37. Object[] ra1 = new Object[] { "1" };
  38. List one = Collections.unmodifiableList(Arrays.asList(ra1));
  39. in = new List[] {one};
  40. exp = new Object[][] { ra1 };
  41. checkIteratorWrapper(in, exp);
  42. in = new List[] {one, one};
  43. exp = new Object[][] { new Object[] { "1", "1"} };
  44. checkIteratorWrapper(in, exp);
  45. Object[] RA_ab = new String[] { "a", "b" };
  46. List List_ab = Collections.unmodifiableList(Arrays.asList(RA_ab));
  47. in = new List[] {List_ab};
  48. exp = new Object[][] {
  49. new Object[] { "a" },
  50. new Object[] { "b" }
  51. };
  52. checkIteratorWrapper(in, exp);
  53. in = new List[] {one, List_ab};
  54. exp = new Object[][] {
  55. new Object[] { "1", "a" },
  56. new Object[] { "1", "b" },
  57. };
  58. checkIteratorWrapper(in, exp);
  59. Object[] RA_cd = new String[] { "c", "d" };
  60. List List_cd = Collections.unmodifiableList(Arrays.asList(RA_cd));
  61. in = new List[] {List_ab, List_cd};
  62. exp = new Object[][] {
  63. new Object[] { "a", "c" },
  64. new Object[] { "b", "c" },
  65. new Object[] { "a", "d" },
  66. new Object[] { "b", "d" }
  67. };
  68. checkIteratorWrapper(in, exp);
  69. in = new List[] {one, one, one};
  70. exp = new Object[][] {
  71. new Object[] { "1", "1", "1" }
  72. };
  73. checkIteratorWrapper(in, exp);
  74. in = new List[] {List_ab, List_ab, List_ab};
  75. exp = new Object[][] {
  76. new Object[] { "a", "a", "a" },
  77. new Object[] { "b", "a", "a" },
  78. new Object[] { "a", "b", "a" },
  79. new Object[] { "b", "b", "a" },
  80. new Object[] { "a", "a", "b" },
  81. new Object[] { "b", "a", "b" },
  82. new Object[] { "a", "b", "b" },
  83. new Object[] { "b", "b", "b" }
  84. };
  85. checkIteratorWrapper(in, exp);
  86. in = new List[] {one, List_ab, List_ab};
  87. exp = new Object[][] {
  88. new Object[] { "1", "a", "a" },
  89. new Object[] { "1", "b", "a" },
  90. new Object[] { "1", "a", "b" },
  91. new Object[] { "1", "b", "b" },
  92. };
  93. checkIteratorWrapper(in, exp);
  94. in = new List[] {one, List_ab, one};
  95. exp = new Object[][] {
  96. new Object[] { "1", "a", "1" },
  97. new Object[] { "1", "b", "1" }
  98. };
  99. checkIteratorWrapper(in, exp);
  100. in = new List[] {List_ab, one, List_ab};
  101. exp = new Object[][] {
  102. new Object[] { "a", "1", "a" },
  103. new Object[] { "b", "1", "a" },
  104. new Object[] { "a", "1", "b" },
  105. new Object[] { "b", "1", "b" }
  106. };
  107. checkIteratorWrapper(in, exp);
  108. in = new List[] {List_ab, one, List_ab, List_ab, Collections.EMPTY_LIST};
  109. exp = new Object[][] {};
  110. checkIteratorWrapper(in, exp);
  111. }
  112. void checkIteratorWrapper(List[] lists, Object[][] exp) {
  113. IteratorWrapper it = new IteratorWrapper(lists);
  114. for (int i = 0; i < exp.length; i++) {
  115. Object[] e = exp[i];
  116. if (!it.hasNext()) {
  117. String s = "exp[" + i + "]: " + Arrays.asList(e) + " it=" + it;
  118. assertTrue(s, false);
  119. }
  120. Object[] actual = (Object[]) it.next();
  121. checkEquals(e, actual, i);
  122. }
  123. if (it.hasNext()) {
  124. String s = "> " + exp.length + " it=" + it;
  125. assertTrue(s, false);
  126. }
  127. }
  128. void checkEquals(Object[] exp, Object[] actual, int index) {
  129. if (null == exp) {
  130. assertTrue(null == actual);
  131. } else {
  132. assertTrue(null != actual);
  133. }
  134. String s = "] exp=" + Arrays.asList(exp) + " act=" + Arrays.asList(actual);
  135. assertTrue(s, exp.length == actual.length);
  136. for (int i = 0; i < actual.length; i++) {
  137. assertTrue(null != exp[i]);
  138. assertTrue("[" + index + ", " + i + s, exp[i].equals(actual[i]));
  139. }
  140. }
  141. }