Use AssertJ’s exception assertions rather than fail

Closes gh-15761
This commit is contained in:
Andy Wilkinson
2019-02-04 11:48:14 +00:00
parent 9357a92503
commit 82bc87560c
26 changed files with 264 additions and 428 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,7 +28,7 @@ import org.junit.Before;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
/**
* Tests for {@link SocketTargetServerConnection}.
@@ -75,16 +75,13 @@ public class SocketTargetServerConnectionTests {
this.server.start();
ByteChannel channel = this.connection.open(10);
long startTime = System.currentTimeMillis();
try {
channel.read(ByteBuffer.allocate(5));
fail("No socket timeout thrown");
}
catch (SocketTimeoutException ex) {
// Expected
long runTime = System.currentTimeMillis() - startTime;
assertThat(runTime).isGreaterThanOrEqualTo(10L);
assertThat(runTime).isLessThan(10000L);
}
assertThatExceptionOfType(SocketTimeoutException.class)
.isThrownBy(() -> channel.read(ByteBuffer.allocate(5)))
.satisfies((ex) -> {
long runTime = System.currentTimeMillis() - startTime;
assertThat(runTime).isGreaterThanOrEqualTo(10L);
assertThat(runTime).isLessThan(10000L);
});
}
private static class MockServer {
@@ -162,7 +159,7 @@ public class SocketTargetServerConnectionTests {
channel.close();
}
catch (Exception ex) {
fail();
throw new RuntimeException(ex);
}
}