Browse Source

Polishing

pull/29430/head
Sam Brannen 1 year ago
parent
commit
95139fca76
  1. 21
      spring-test/src/test/java/org/springframework/test/context/jdbc/SqlScriptsTestExecutionListenerTests.java

21
spring-test/src/test/java/org/springframework/test/context/jdbc/SqlScriptsTestExecutionListenerTests.java

@ -22,7 +22,6 @@ import org.mockito.BDDMockito;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.core.annotation.AnnotationConfigurationException; import org.springframework.core.annotation.AnnotationConfigurationException;
import org.springframework.test.context.TestContext; import org.springframework.test.context.TestContext;
import org.springframework.test.context.jdbc.SqlConfig.TransactionMode;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
@ -32,6 +31,7 @@ import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.AFTER_TEST_CLASS; import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.AFTER_TEST_CLASS;
import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TEST_CLASS; import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TEST_CLASS;
import static org.springframework.test.context.jdbc.SqlConfig.TransactionMode.ISOLATED;
/** /**
* Unit tests for {@link SqlScriptsTestExecutionListener}. * Unit tests for {@link SqlScriptsTestExecutionListener}.
@ -71,11 +71,12 @@ class SqlScriptsTestExecutionListenerTests {
BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz); BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("foo")); given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("foo"));
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() -> assertThatExceptionOfType(AnnotationConfigurationException.class)
listener.beforeTestMethod(testContext)) .isThrownBy(() -> listener.beforeTestMethod(testContext))
.withMessageContaining("Different @AliasFor mirror values") .withMessageContainingAll(
.withMessageContaining("attribute 'scripts' and its alias 'value'") "Different @AliasFor mirror values",
.withMessageContaining("values of [{bar}] and [{foo}]"); "attribute 'scripts' and its alias 'value'",
"values of [{bar}] and [{foo}]");
} }
@Test @Test
@ -129,9 +130,9 @@ class SqlScriptsTestExecutionListenerTests {
} }
private void assertExceptionContains(String msg) throws Exception { private void assertExceptionContains(String msg) throws Exception {
assertThatIllegalStateException().isThrownBy(() -> assertThatIllegalStateException()
listener.beforeTestMethod(testContext)) .isThrownBy(() -> listener.beforeTestMethod(testContext))
.withMessageContaining(msg); .withMessageContaining(msg);
} }
@ -160,7 +161,7 @@ class SqlScriptsTestExecutionListenerTests {
static class IsolatedWithoutTxMgr { static class IsolatedWithoutTxMgr {
@Sql(scripts = "foo.sql", config = @SqlConfig(transactionMode = TransactionMode.ISOLATED)) @Sql(scripts = "foo.sql", config = @SqlConfig(transactionMode = ISOLATED))
public void foo() { public void foo() {
} }
} }

Loading…
Cancel
Save