Use Assert.state() where appropriate

This commit is contained in:
Sam Brannen
2022-11-14 17:36:11 +01:00
parent 2aa78889d2
commit abf3400c07
30 changed files with 80 additions and 82 deletions

View File

@@ -98,7 +98,7 @@ public final class RecordedInvocation {
*/
@SuppressWarnings("unchecked")
public <T> T getInstance() {
Assert.notNull(this.instance, "Cannot resolve 'this' for static invocations");
Assert.state(this.instance != null, "Cannot resolve 'this' for static invocations");
return (T) this.instance;
}
@@ -108,7 +108,7 @@ public final class RecordedInvocation {
* @throws IllegalStateException in case of static invocations (there is no {@code this})
*/
public TypeReference getInstanceTypeReference() {
Assert.notNull(this.instance, "Cannot resolve 'this' for static invocations");
Assert.state(this.instance != null, "Cannot resolve 'this' for static invocations");
return TypeReference.of(this.instance.getClass());
}

View File

@@ -49,7 +49,7 @@ public final class RuntimeHintsRecorder {
*/
public synchronized static RuntimeHintsInvocations record(Runnable action) {
Assert.notNull(action, "Runnable action must not be null");
Assert.isTrue(RuntimeHintsAgent.isLoaded(), "RuntimeHintsAgent should be loaded in the current JVM");
Assert.state(RuntimeHintsAgent.isLoaded(), "RuntimeHintsAgent must be loaded in the current JVM");
RuntimeHintsRecorder recorder = new RuntimeHintsRecorder();
RecordedInvocationsPublisher.addListener(recorder.listener);
try {

View File

@@ -63,8 +63,8 @@ class RecordedInvocationTests {
@Test
void staticInvocationShouldThrowWhenGetInstance() {
assertThatThrownBy(staticInvocation::getInstance).isInstanceOf(IllegalArgumentException.class);
assertThatThrownBy(staticInvocation::getInstanceTypeReference).isInstanceOf(IllegalArgumentException.class);
assertThatThrownBy(staticInvocation::getInstance).isInstanceOf(IllegalStateException.class);
assertThatThrownBy(staticInvocation::getInstanceTypeReference).isInstanceOf(IllegalStateException.class);
}
@Test