Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace assert with JUnit assertions #648

Merged
merged 2 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading