diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2020-12-17 10:10:52 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2020-12-17 10:10:52 +0000 |
commit | f35963cb77cba1658e04cbb3787746df57d2e6c9 (patch) | |
tree | 13c32d80ea7bb29615d5d68c32c5fd1803f1fe96 /core/tests | |
parent | b3f8228f21ac139563c7a482cad0e8ff4aaa80ab (diff) | |
parent | 37c6b6deeb9d8bb526fea6b8a3108b9e269e400f (diff) |
Merge "Make a copy of libcore.util.ArraysUtils in framework"
Diffstat (limited to 'core/tests')
-rw-r--r-- | core/tests/coretests/src/com/android/internal/util/ArrayUtilsTest.java | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/core/tests/coretests/src/com/android/internal/util/ArrayUtilsTest.java b/core/tests/coretests/src/com/android/internal/util/ArrayUtilsTest.java index d0267355c92e..e8793a9f6097 100644 --- a/core/tests/coretests/src/com/android/internal/util/ArrayUtilsTest.java +++ b/core/tests/coretests/src/com/android/internal/util/ArrayUtilsTest.java @@ -118,4 +118,89 @@ public class ArrayUtilsTest extends TestCase { assertEquals(3, ArrayUtils.unstableRemoveIf(collection, isNull)); assertEquals(0, collection.size()); } + + @SmallTest + public void testThrowsIfOutOfBounds_passesWhenRangeInsideArray() { + ArrayUtils.throwsIfOutOfBounds(10, 2, 6); + } + + @SmallTest + public void testThrowsIfOutOfBounds_passesWhenRangeIsWholeArray() { + ArrayUtils.throwsIfOutOfBounds(10, 0, 10); + } + + @SmallTest + public void testThrowsIfOutOfBounds_passesWhenEmptyRangeAtStart() { + ArrayUtils.throwsIfOutOfBounds(10, 0, 0); + } + + @SmallTest + public void testThrowsIfOutOfBounds_passesWhenEmptyRangeAtEnd() { + ArrayUtils.throwsIfOutOfBounds(10, 10, 0); + } + + @SmallTest + public void testThrowsIfOutOfBounds_passesWhenEmptyArray() { + ArrayUtils.throwsIfOutOfBounds(0, 0, 0); + } + + @SmallTest + public void testThrowsIfOutOfBounds_failsWhenRangeStartNegative() { + try { + ArrayUtils.throwsIfOutOfBounds(10, -1, 5); + fail(); + } catch (ArrayIndexOutOfBoundsException expected) { + // expected + } + } + + @SmallTest + public void testThrowsIfOutOfBounds_failsWhenCountNegative() { + try { + ArrayUtils.throwsIfOutOfBounds(10, 5, -1); + fail(); + } catch (ArrayIndexOutOfBoundsException expected) { + // expected + } + } + + @SmallTest + public void testThrowsIfOutOfBounds_failsWhenRangeStartTooHigh() { + try { + ArrayUtils.throwsIfOutOfBounds(10, 11, 0); + fail(); + } catch (ArrayIndexOutOfBoundsException expected) { + // expected + } + } + + @SmallTest + public void testThrowsIfOutOfBounds_failsWhenRangeEndTooHigh() { + try { + ArrayUtils.throwsIfOutOfBounds(10, 5, 6); + fail(); + } catch (ArrayIndexOutOfBoundsException expected) { + // expected + } + } + + @SmallTest + public void testThrowsIfOutOfBounds_failsWhenLengthNegative() { + try { + ArrayUtils.throwsIfOutOfBounds(-1, 0, 0); + fail(); + } catch (ArrayIndexOutOfBoundsException expected) { + // expected + } + } + + @SmallTest + public void testThrowsIfOutOfBounds_failsWhenOverflowRangeEndTooHigh() { + try { + ArrayUtils.throwsIfOutOfBounds(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE); + fail(); + } catch (ArrayIndexOutOfBoundsException expected) { + // expected + } + } } |