Repository: cayenne Updated Branches: refs/heads/master fed246bbb -> bb70d83a0
http://git-wip-us.apache.org/repos/asf/cayenne/blob/bb70d83a/modeler/cayenne-modeler/src/test/java/org/apache/cayenne/modeler/util/CircularArrayTest.java ---------------------------------------------------------------------- diff --git a/modeler/cayenne-modeler/src/test/java/org/apache/cayenne/modeler/util/CircularArrayTest.java b/modeler/cayenne-modeler/src/test/java/org/apache/cayenne/modeler/util/CircularArrayTest.java index 11fce3d..3328658 100644 --- a/modeler/cayenne-modeler/src/test/java/org/apache/cayenne/modeler/util/CircularArrayTest.java +++ b/modeler/cayenne-modeler/src/test/java/org/apache/cayenne/modeler/util/CircularArrayTest.java @@ -19,6 +19,8 @@ package org.apache.cayenne.modeler.util; +import java.util.Objects; + import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -28,18 +30,10 @@ public class CircularArrayTest { @Test public void testArray() { - String a = "A"; - String b = "B"; - String c = "C"; - String d = "D"; - String e = "E"; - String f = "F"; - String g = "G"; - String h = "H"; - - String s = null; + String a = "A", b = "B", c = "C", d = "D", e = "E", f = "F", g = "G", h = "H"; + String s; - CircularArray q = new CircularArray(5); + CircularArray<String> q = new CircularArray<>(5); assertAdd(q, a, "[A, null, null, null, null]"); assertRemove(q, a, "[null, null, null, null, null]"); @@ -66,103 +60,81 @@ public class CircularArrayTest { assertAdd(q, f, "[B, C, D, E, F]"); assertAdd(q, g, "[C, D, E, F, G]"); - assertRemove(q, e, "[C, D, F, G, null]"); - assertAdd(q, h, "[C, D, F, G, H]"); assertRemove(q, c, "[D, F, G, H, null]"); - assertRemove(q, h, "[D, F, G, null, null]"); - assertRemove(q, f, "[D, G, null, null, null]"); - assertRemove(q, g, "[D, null, null, null, null]"); - assertRemove(q, d, "[null, null, null, null, null]"); - q = new CircularArray(3); + q = new CircularArray<>(3); q.add(a); int i = q.indexOf(a); if (i != 0) { - System.out.println("indexOf(a) should be zero instead got [" - + String.valueOf(i) - + "]"); + System.out.println("indexOf(a) should be zero instead got [" + String.valueOf(i) + "]"); } - s = (String) q.get(0); - if (s != a) { + s = q.get(0); + if (!Objects.equals(s, a)) { System.out.println("get(0) should be 'a' instead got [" + s + "]"); } i = q.size(); if (i != 1) { - System.out.println("size() should be 1 instead got [" - + String.valueOf(i) - + "]"); + System.out.println("size() should be 1 instead got [" + String.valueOf(i) + "]"); } q.add(b); i = q.indexOf(b); if (i != 1) { - System.out.println("indexOf(b) should be 1 instead got [" - + String.valueOf(i) - + "]"); + System.out.println("indexOf(b) should be 1 instead got [" + String.valueOf(i) + "]"); } - s = (String) q.get(0); - if (s != a) { + s = q.get(0); + if (!Objects.equals(s, a)) { System.out.println("get(0) should be 'a' instead got [" + s + "]"); } - s = (String) q.get(1); - if (s != b) { + s = q.get(1); + if (!Objects.equals(s, b)) { System.out.println("get(1) should be 'b' instead got [" + s + "]"); } i = q.size(); if (i != 2) { - System.out.println("size() should be 2 instead got [" - + String.valueOf(i) - + "]"); + System.out.println("size() should be 2 instead got [" + String.valueOf(i) + "]"); } q.add(c); i = q.indexOf(c); if (i != 2) { - System.out.println("indexOf(c) should be 2 instead got [" - + String.valueOf(i) - + "]"); + System.out.println("indexOf(c) should be 2 instead got [" + String.valueOf(i) + "]"); } - s = (String) q.get(0); - if (s != a) { + s = q.get(0); + if (!Objects.equals(s, a)) { System.out.println("get(0) should be 'a' instead got [" + s + "]"); } - s = (String) q.get(1); - if (s != b) { + s = q.get(1); + if (!Objects.equals(s, b)) { System.out.println("get(1) should be 'b' instead got [" + s + "]"); } - s = (String) q.get(2); - if (s != c) { + s = q.get(2); + if (!Objects.equals(s, c)) { System.out.println("get(1) should be 'c' instead got [" + s + "]"); } i = q.size(); if (i != 3) { - System.out.println("size() should be 3 instead got [" - + String.valueOf(i) - + "]"); + System.out.println("size() should be 3 instead got [" + String.valueOf(i) + "]"); } q.add(d); i = q.size(); if (i != 3) { - System.out.println("size() should be 3 instead got [" - + String.valueOf(i) - + "]"); + System.out.println("size() should be 3 instead got [" + String.valueOf(i) + "]"); } q.add(e); i = q.size(); if (i != 3) { - System.out.println("size() should be 3 instead got [" - + String.valueOf(i) - + "]"); + System.out.println("size() should be 3 instead got [" + String.valueOf(i) + "]"); } if (q.contains(a)) { @@ -171,23 +143,19 @@ public class CircularArrayTest { i = q.indexOf(c); if (i != 0) { - System.out.println("indexOf(c) should be zero instead got [" - + String.valueOf(i) - + "]"); + System.out.println("indexOf(c) should be zero instead got [" + String.valueOf(i) + "]"); } - s = (String) q.get(0); - if (s != c) { + s = q.get(0); + if (!Objects.equals(s, c)) { System.out.println("get(0) should be 'c' instead got [" + s + "]"); } i = q.indexOf(d); if (i != 1) { - System.out.println("indexOf(d) should be 1 instead got [" - + String.valueOf(i) - + "]"); + System.out.println("indexOf(d) should be 1 instead got [" + String.valueOf(i) + "]"); } - s = (String) q.get(1); - if (s != d) { + s = q.get(1); + if (!Objects.equals(s, d)) { System.out.println("get(1) should be 'd' instead got [" + s + "]"); } @@ -197,61 +165,52 @@ public class CircularArrayTest { + String.valueOf(i) + "]"); } - s = (String) q.get(2); - if (s != e) { + s = q.get(2); + if (!Objects.equals(s, e)) { System.out.println("get(2) should be 'e' instead got [" + s + "]"); } q.resize(5); i = q.capacity(); if (i != 5) { - System.out.println("size() should be 5 after resizing to 5 instead got [" - + String.valueOf(i) - + "]"); + System.out.println("size() should be 5 after resizing to 5 instead got [" + String.valueOf(i) + "]"); } // should be the same after resizing i = q.size(); if (i != 3) { - System.out.println("size() should be 3 instead got [" - + String.valueOf(i) - + "]"); + System.out.println("size() should be 3 instead got [" + String.valueOf(i) + "]"); } i = q.indexOf(e); if (i != 2) { - System.out.println("indexOf(e) should be 2 instead got [" - + String.valueOf(i) - + "]"); + System.out.println("indexOf(e) should be 2 instead got [" + String.valueOf(i) + "]"); } - s = (String) q.get(2); - if (s != e) { + s = q.get(2); + if (!Objects.equals(s, e)) { System.out.println("get(2) should be 'e' instead got [" + s + "]"); } q.resize(2); i = q.capacity(); if (i != 2) { - System.out.println("size() should be 2 after resizing to 2 instead got [" - + String.valueOf(i) - + "]"); + System.out.println("size() should be 2 after resizing to 2 instead got [" + String.valueOf(i) + "]"); } } @Test public void testToString() { - CircularArray a = new CircularArray(5); + CircularArray<String> a = new CircularArray<>(5); assertEquals("[null, null, null, null, null]", a.toString()); } - public void assertAdd(CircularArray a, Object obj, String expected) { + public void assertAdd(CircularArray<String> a, String obj, String expected) { a.add(obj); assertEquals(expected, a.toString()); } - public void assertRemove(CircularArray a, Object obj, String expected) { - int i = a.indexOf(obj); - i = a.convert(i); + public void assertRemove(CircularArray<String> a, String obj, String expected) { + a.indexOf(obj); a.remove(obj); assertEquals(expected, a.toString()); }