Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Base32InputStreamTest.testReadOutOfBounds explicitly check IndexOutOf…
…BoundsException is thrown
  • Loading branch information
nhojpatrick committed Feb 13, 2022
commit 25f3e97ed77cea9a9787c38fd4bb0370d8169e8e
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ limitations under the License.
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<!-- Fix to build on JDK 7: version 4.0.0 requires Java 8. -->
<!-- Can be dropped when CP 49 is released -->
<commons.felix.version>3.5.1</commons.felix.version>
<commons.componentid>codec</commons.componentid>
<commons.module.name>org.apache.commons.codec</commons.module.name>
<commons.jira.id>CODEC</commons.jira.id>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,19 @@

import org.apache.commons.codec.CodecPolicy;
import org.junit.Test;
import org.junit.jupiter.api.function.Executable;

import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.hamcrest.core.IsNull.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class Base32InputStreamTest {

Expand Down Expand Up @@ -442,33 +449,32 @@ public void testReadOutOfBounds() throws Exception {
final ByteArrayInputStream bin = new ByteArrayInputStream(decoded);
try (final Base32InputStream in = new Base32InputStream(bin, true, 4, new byte[] { 0, 0, 0 })) {

try {
in.read(buf, -1, 0);
fail("Expected Base32InputStream.read(buf, -1, 0) to throw IndexOutOfBoundsException");
} catch (final IndexOutOfBoundsException e) {
// Expected
}

try {
in.read(buf, 0, -1);
fail("Expected Base32InputStream.read(buf, 0, -1) to throw IndexOutOfBoundsException");
} catch (final IndexOutOfBoundsException e) {
// Expected
}

try {
in.read(buf, buf.length + 1, 0);
fail("Base32InputStream.read(buf, buf.length + 1, 0) throws IndexOutOfBoundsException");
} catch (final IndexOutOfBoundsException e) {
// Expected
}

try {
in.read(buf, buf.length - 1, 2);
fail("Base32InputStream.read(buf, buf.length - 1, 2) throws IndexOutOfBoundsException");
} catch (final IndexOutOfBoundsException e) {
// Expected
}
assertAll(
() -> {
final Executable testMethod = () -> in.read(buf, -1, 0);
final String message = "Expected Base32InputStream.read(buf, -1, 0) to throw IndexOutOfBoundsException";
final IndexOutOfBoundsException thrown = assertThrows(IndexOutOfBoundsException.class, testMethod, message);
assertThat(message, thrown.getMessage(), is(nullValue()));
},
() -> {
final Executable testMethod = () -> in.read(buf, 0, -1);
final String message = "Expected Base32InputStream.read(buf, 0, -1) to throw IndexOutOfBoundsException";
final IndexOutOfBoundsException thrown = assertThrows(IndexOutOfBoundsException.class, testMethod, message);
assertThat(message, thrown.getMessage(), is(nullValue()));
},
() -> {
final Executable testMethod = () -> in.read(buf, buf.length + 1, 0);
final String message = "Base32InputStream.read(buf, buf.length + 1, 0) throws IndexOutOfBoundsException";
final IndexOutOfBoundsException thrown = assertThrows(IndexOutOfBoundsException.class, testMethod, message);
assertThat(message, thrown.getMessage(), is(nullValue()));
},
() -> {
final Executable testMethod = () -> in.read(buf, buf.length - 1, 2);
final String message = "Base32InputStream.read(buf, buf.length - 1, 2) throws IndexOutOfBoundsException";
final IndexOutOfBoundsException thrown = assertThrows(IndexOutOfBoundsException.class, testMethod, message);
assertThat(message, thrown.getMessage(), is(nullValue()));
}
);
}
}

Expand Down