Skip to content

Commit 5861604

Browse files
committed
[test] Added test cases for exceptions in int list test suite
1 parent 0f20b45 commit 5861604

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

tehreer-android/src/androidTest/java/com/mta/tehreer/collections/IntListTestSuite.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import static org.junit.Assert.assertArrayEquals;
2424
import static org.junit.Assert.assertEquals;
25+
import static org.junit.Assert.fail;
2526

2627
public abstract class IntListTestSuite {
2728
protected IntList actual;
@@ -50,6 +51,22 @@ public void testElements() {
5051
}
5152
}
5253

54+
@Test
55+
public void testGetAtMinusOne() {
56+
try {
57+
actual.get(-1);
58+
fail();
59+
} catch (IndexOutOfBoundsException ignored) { }
60+
}
61+
62+
@Test
63+
public void testGetAtLength() {
64+
try {
65+
actual.get(expected.length);
66+
fail();
67+
} catch (IndexOutOfBoundsException ignored) { }
68+
}
69+
5370
@Test
5471
public void testCopyFull() {
5572
int[] array = new int[expected.length];
@@ -90,13 +107,38 @@ public void testCopyAtEnd() {
90107
assertArrayEquals(copiedChunk, expected);
91108
}
92109

110+
@Test
111+
public void testCopyToNullArray() {
112+
try {
113+
actual.copyTo(null, 0);
114+
fail();
115+
} catch (NullPointerException ignored) { }
116+
}
117+
118+
@Test
119+
public void testCopyToSmallArray() {
120+
if (expected.length == 0) {
121+
return;
122+
}
123+
124+
try {
125+
int[] array = new int[expected.length / 2];
126+
actual.copyTo(array, 0);
127+
fail();
128+
} catch (ArrayIndexOutOfBoundsException ignored) { }
129+
}
130+
93131
private static void testSubList(IntList subList, int[] expected) {
94132
SubListTestSuite suite = new SubListTestSuite(subList, expected);
95133
suite.testSize();
96134
suite.testElements();
135+
suite.testGetAtMinusOne();
136+
suite.testGetAtLength();
97137
suite.testCopyFull();
98138
suite.testCopyAtStart();
99139
suite.testCopyAtEnd();
140+
suite.testCopyToNullArray();
141+
suite.testCopyToSmallArray();
100142
suite.testToArray();
101143
suite.testEquals();
102144
}

0 commit comments

Comments
 (0)