Use assertThatObject to save casting

Update tests that use `assertThat((Object) ...)` to use the convenience
`assertThatObject(...)` method instead.

Issue gh-8945
This commit is contained in:
Phillip Webb 2020-08-04 10:51:17 -07:00 committed by Rob Winch
parent 0a3eeb9c80
commit 2f8e835b11
3 changed files with 9 additions and 9 deletions

View File

@ -22,7 +22,7 @@ import java.util.List;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatObject;
/**
* @author Rob Winch
@ -33,7 +33,7 @@ public class ObjectPostProcessorTests {
@Test
public void convertTypes() {
assertThat((Object) PerformConversion.perform(new ArrayList<>())).isInstanceOf(LinkedList.class);
assertThatObject(PerformConversion.perform(new ArrayList<>())).isInstanceOf(LinkedList.class);
}
static class ListToLinkedListObjectPostProcessor implements ObjectPostProcessor<List<?>> {

View File

@ -23,7 +23,7 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatObject;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.verify;
@ -56,7 +56,7 @@ public abstract class AbstractDelegatingSecurityContextScheduledExecutorServiceT
given((ScheduledFuture<Object>) this.delegate.schedule(this.wrappedRunnable, 1, TimeUnit.SECONDS))
.willReturn(this.expectedResult);
ScheduledFuture<?> result = this.executor.schedule(this.runnable, 1, TimeUnit.SECONDS);
assertThat((Object) result).isEqualTo(this.expectedResult);
assertThatObject(result).isEqualTo(this.expectedResult);
verify(this.delegate).schedule(this.wrappedRunnable, 1, TimeUnit.SECONDS);
}
@ -64,7 +64,7 @@ public abstract class AbstractDelegatingSecurityContextScheduledExecutorServiceT
public void scheduleCallable() {
given(this.delegate.schedule(this.wrappedCallable, 1, TimeUnit.SECONDS)).willReturn(this.expectedResult);
ScheduledFuture<Object> result = this.executor.schedule(this.callable, 1, TimeUnit.SECONDS);
assertThat((Object) result).isEqualTo(this.expectedResult);
assertThatObject(result).isEqualTo(this.expectedResult);
verify(this.delegate).schedule(this.wrappedCallable, 1, TimeUnit.SECONDS);
}
@ -74,7 +74,7 @@ public abstract class AbstractDelegatingSecurityContextScheduledExecutorServiceT
given((ScheduledFuture<Object>) this.delegate.scheduleAtFixedRate(this.wrappedRunnable, 1, 2, TimeUnit.SECONDS))
.willReturn(this.expectedResult);
ScheduledFuture<?> result = this.executor.scheduleAtFixedRate(this.runnable, 1, 2, TimeUnit.SECONDS);
assertThat((Object) result).isEqualTo(this.expectedResult);
assertThatObject(result).isEqualTo(this.expectedResult);
verify(this.delegate).scheduleAtFixedRate(this.wrappedRunnable, 1, 2, TimeUnit.SECONDS);
}
@ -84,7 +84,7 @@ public abstract class AbstractDelegatingSecurityContextScheduledExecutorServiceT
given((ScheduledFuture<Object>) this.delegate.scheduleWithFixedDelay(this.wrappedRunnable, 1, 2,
TimeUnit.SECONDS)).willReturn(this.expectedResult);
ScheduledFuture<?> result = this.executor.scheduleWithFixedDelay(this.runnable, 1, 2, TimeUnit.SECONDS);
assertThat((Object) result).isEqualTo(this.expectedResult);
assertThatObject(result).isEqualTo(this.expectedResult);
verify(this.delegate).scheduleWithFixedDelay(this.wrappedRunnable, 1, 2, TimeUnit.SECONDS);
}

View File

@ -29,6 +29,7 @@ import org.springframework.security.oauth2.client.registration.TestClientRegistr
import org.springframework.security.oauth2.core.OAuth2AccessToken;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatObject;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.given;
@ -80,8 +81,7 @@ public class InMemoryOAuth2AuthorizedClientServiceTests {
given(clientRegistrationRepository.findByRegistrationId(eq(registrationId))).willReturn(this.registration3);
InMemoryOAuth2AuthorizedClientService authorizedClientService = new InMemoryOAuth2AuthorizedClientService(
clientRegistrationRepository, authorizedClients);
assertThat((Object) authorizedClientService.loadAuthorizedClient(registrationId, this.principalName1))
.isNotNull();
assertThatObject(authorizedClientService.loadAuthorizedClient(registrationId, this.principalName1)).isNotNull();
}
@Test(expected = IllegalArgumentException.class)