Use AssertJ in spring-boot-samples
See gh-5083
This commit is contained in:
@@ -17,8 +17,7 @@
|
||||
package sample.bitronix;
|
||||
|
||||
import bitronix.tm.resource.jms.PoolingConnectionFactory;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.hamcrest.core.SubstringMatcher;
|
||||
import org.assertj.core.api.Condition;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -26,10 +25,7 @@ import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.test.OutputCapture;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.sameInstance;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Basic integration tests for demo application.
|
||||
@@ -45,10 +41,10 @@ public class SampleBitronixApplicationTests {
|
||||
public void testTransactionRollback() throws Exception {
|
||||
SampleBitronixApplication.main(new String[] {});
|
||||
String output = this.outputCapture.toString();
|
||||
assertThat(output, containsString(1, "---->"));
|
||||
assertThat(output, containsString(1, "----> josh"));
|
||||
assertThat(output, containsString(2, "Count is 1"));
|
||||
assertThat(output, containsString(1, "Simulated error"));
|
||||
assertThat(output).has(substring(1, "---->"));
|
||||
assertThat(output).has(substring(1, "----> josh"));
|
||||
assertThat(output).has(substring(2, "Count is 1"));
|
||||
assertThat(output).has(substring(1, "Simulated error"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -58,25 +54,22 @@ public class SampleBitronixApplicationTests {
|
||||
Object jmsConnectionFactory = context.getBean("jmsConnectionFactory");
|
||||
Object xaJmsConnectionFactory = context.getBean("xaJmsConnectionFactory");
|
||||
Object nonXaJmsConnectionFactory = context.getBean("nonXaJmsConnectionFactory");
|
||||
assertThat(jmsConnectionFactory, sameInstance(xaJmsConnectionFactory));
|
||||
assertThat(jmsConnectionFactory, instanceOf(PoolingConnectionFactory.class));
|
||||
assertThat(nonXaJmsConnectionFactory,
|
||||
not(instanceOf(PoolingConnectionFactory.class)));
|
||||
assertThat(jmsConnectionFactory).isSameAs(xaJmsConnectionFactory);
|
||||
assertThat(jmsConnectionFactory).isInstanceOf(PoolingConnectionFactory.class);
|
||||
assertThat(nonXaJmsConnectionFactory)
|
||||
.isNotInstanceOf(PoolingConnectionFactory.class);
|
||||
}
|
||||
|
||||
private Matcher<? super String> containsString(final int times, String s) {
|
||||
return new SubstringMatcher(s) {
|
||||
private Condition<String> substring(final int times, final String substring) {
|
||||
return new Condition<String>(
|
||||
"containing '" + substring + "' " + times + " times") {
|
||||
|
||||
@Override
|
||||
protected String relationship() {
|
||||
return "containing " + times + " times";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean evalSubstringOf(String s) {
|
||||
public boolean matches(String value) {
|
||||
int i = 0;
|
||||
while (s.contains(this.substring)) {
|
||||
s = s.substring(s.indexOf(this.substring) + this.substring.length());
|
||||
while (value.contains(substring)) {
|
||||
int beginIndex = value.indexOf(substring) + substring.length();
|
||||
value = value.substring(beginIndex);
|
||||
i++;
|
||||
}
|
||||
return i == times;
|
||||
|
||||
Reference in New Issue
Block a user