Skip to content

Commit

Permalink
Replace assert with JUnit assertions (#648)
Browse files Browse the repository at this point in the history
* Replace assert with Exception

* Run basic test with experimental Java to reduce false negatives
  • Loading branch information
sebbASF authored Jul 27, 2024
1 parent 7d5fb89 commit 9ca6fbb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ jobs:
server-username: NEXUS_USER # env variable for username in deploy
server-password: NEXUS_PW # env variable for token in deploy
- name: Build with Maven
if: ${{ !matrix.experimental }}
run: mvn --errors --show-version --batch-mode --no-transfer-progress -DtrimStackTrace=false
- name: Test only with Maven
if: ${{ matrix.experimental }}
# Skip PMD etc when using experimental Java
run: mvn --errors --show-version --batch-mode --no-transfer-progress -DtrimStackTrace=false clean test
- name: Deploy SNAPSHOT using minimal build
if: matrix.deploy && github.repository == 'apache/commons-io' && github.ref_name == 'master'
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,9 @@ public long skip(final long n) throws IOException {
* @throws IOException if an I/O error occurs.
*/
private long skipInternal(final long n) throws IOException {
assert stateChangeLock.isLocked();
if (!stateChangeLock.isLocked()) {
throw new IllegalStateException("Expected stateChangeLock to be locked");
}
waitForAsyncReadComplete();
if (isEndOfStream()) {
return 0;
Expand All @@ -495,7 +497,9 @@ private long skipInternal(final long n) throws IOException {
int toSkip = (int) n;
// We need to skip from both active buffer and read ahead buffer
toSkip -= activeBuffer.remaining();
assert toSkip > 0; // skipping from activeBuffer already handled.
if (toSkip <= 0) { // skipping from activeBuffer already handled.
throw new IllegalStateException("Expected toSkip > 0, actual: " + toSkip);
}
activeBuffer.position(0);
activeBuffer.flip();
readAheadBuffer.position(toSkip + readAheadBuffer.position());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ public static Builder builder() {
}

static long toSleepMillis(final long bytesRead, final long maxBytesPerSec, final long elapsedMillis) {
assert elapsedMillis >= 0 : "The elapsed time should be greater or equal to zero";
if (elapsedMillis < 0) {
throw new IllegalArgumentException("The elapsed time should be greater or equal to zero");
}
if (bytesRead <= 0 || maxBytesPerSec <= 0 || elapsedMillis == 0) {
return 0;
}
Expand All @@ -147,7 +149,9 @@ static long toSleepMillis(final long bytesRead, final long maxBytesPerSec, final

private ThrottledInputStream(final InputStream proxy, final long maxBytesPerSecond) {
super(proxy);
assert maxBytesPerSecond > 0 : "Bandwidth " + maxBytesPerSecond + " is invalid.";
if (maxBytesPerSecond <= 0) {
throw new IllegalArgumentException("Bandwidth " + maxBytesPerSecond + " is invalid.");
}
this.maxBytesPerSecond = maxBytesPerSecond;
}

Expand Down

0 comments on commit 9ca6fbb

Please sign in to comment.