Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public interface ApplicationContextAssertProvider<C extends ApplicationContext>
extends ApplicationContext, AssertProvider<ApplicationContextAssert<C>>, Closeable {

/**
* Return an assert for AspectJ.
* @return an AspectJ assert
* Return an assert for AssertJ.
* @return an AssertJ assert
* @deprecated to prevent accidental use. Prefer standard AssertJ
* {@code assertThat(context)...} calls instead.
*/
Expand Down Expand Up @@ -131,6 +131,7 @@ static <T extends ApplicationContextAssertProvider<C>, C extends ApplicationCont
Assert.isTrue(type.isInterface(), "'type' must be an interface");
Assert.notNull(contextType, "'contextType' must not be null");
Assert.isTrue(contextType.isInterface(), "'contextType' must be an interface");
Assert.notNull(contextSupplier, "'contextSupplier' must not be null");
Class<?>[] interfaces = merge(new Class<?>[] { type, contextType }, additionalContextInterfaces);
return (T) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), interfaces,
new AssertProviderApplicationContextInvocationHandler(contextType, contextSupplier));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
Expand All @@ -32,18 +29,17 @@
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.mockito.BDDMockito.then;
import static org.mockito.Mockito.mock;

/**
* Tests for {@link ApplicationContextAssertProvider} and
* {@link AssertProviderApplicationContextInvocationHandler}.
*
* @author Phillip Webb
*/
@ExtendWith(MockitoExtension.class)
class ApplicationContextAssertProviderTests {

@Mock
private ConfigurableApplicationContext mockContext;
private final ConfigurableApplicationContext mockContext = mock();

private RuntimeException startupFailure;

Expand All @@ -61,6 +57,7 @@ void setup() {
}

@Test
@SuppressWarnings("NullAway") // Test null check
void getWhenTypeIsNullShouldThrowException() {
assertThatIllegalArgumentException().isThrownBy(
() -> ApplicationContextAssertProvider.get(null, ApplicationContext.class, this.mockContextSupplier))
Expand All @@ -69,35 +66,38 @@ void getWhenTypeIsNullShouldThrowException() {

@Test
void getWhenTypeIsClassShouldThrowException() {
assertThatIllegalArgumentException().isThrownBy(
() -> ApplicationContextAssertProvider.get(null, ApplicationContext.class, this.mockContextSupplier))
.withMessageContaining("'type' must not be null");
}

@Test
void getWhenContextTypeIsNullShouldThrowException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> ApplicationContextAssertProvider.get(TestAssertProviderApplicationContextClass.class,
ApplicationContext.class, this.mockContextSupplier))
.withMessageContaining("'type' must be an interface");
}

@Test
void getWhenContextTypeIsClassShouldThrowException() {
@SuppressWarnings("NullAway") // Test null check
void getWhenContextTypeIsNullShouldThrowException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> ApplicationContextAssertProvider.get(TestAssertProviderApplicationContext.class, null,
this.mockContextSupplier))
.withMessageContaining("'contextType' must not be null");
}

@Test
void getWhenSupplierIsNullShouldThrowException() {
void getWhenContextTypeIsClassShouldThrowException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> ApplicationContextAssertProvider.get(TestAssertProviderApplicationContext.class,
StaticApplicationContext.class, this.mockContextSupplier))
.withMessageContaining("'contextType' must be an interface");
}

@Test
@SuppressWarnings("NullAway") // Test null check
void getWhenSupplierIsNullShouldThrowException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> ApplicationContextAssertProvider.get(TestAssertProviderApplicationContext.class,
ApplicationContext.class, null))
.withMessageContaining("'contextSupplier' must not be null");
}

@Test
void getWhenContextStartsShouldReturnProxyThatCallsRealMethods() {
ApplicationContextAssertProvider<ApplicationContext> context = get(this.mockContextSupplier);
Expand Down