Polish
This commit is contained in:
@@ -16,12 +16,14 @@
|
||||
|
||||
package smoketest.atomikos;
|
||||
|
||||
import org.assertj.core.api.Condition;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.boot.test.system.CapturedOutput;
|
||||
import org.springframework.boot.test.system.OutputCaptureExtension;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -36,24 +38,16 @@ class SampleAtomikosApplicationTests {
|
||||
@Test
|
||||
void testTransactionRollback(CapturedOutput output) throws Exception {
|
||||
SampleAtomikosApplication.main(new String[] {});
|
||||
assertThat(output.toString()).has(substring(1, "---->")).has(substring(1, "----> josh"))
|
||||
.has(substring(2, "Count is 1")).has(substring(1, "Simulated error"));
|
||||
assertThat(output).satisfies(numberOfOccurrences("---->", 1));
|
||||
assertThat(output).satisfies(numberOfOccurrences("----> josh", 1));
|
||||
assertThat(output).satisfies(numberOfOccurrences("Count is 1", 2));
|
||||
assertThat(output).satisfies(numberOfOccurrences("Simulated error", 1));
|
||||
}
|
||||
|
||||
private Condition<String> substring(int times, String substring) {
|
||||
return new Condition<String>("containing '" + substring + "' " + times + " times") {
|
||||
|
||||
@Override
|
||||
public boolean matches(String value) {
|
||||
int i = 0;
|
||||
while (value.contains(substring)) {
|
||||
int beginIndex = value.indexOf(substring) + substring.length();
|
||||
value = value.substring(beginIndex);
|
||||
i++;
|
||||
}
|
||||
return i == times;
|
||||
}
|
||||
|
||||
private <T extends CharSequence> Consumer<T> numberOfOccurrences(String substring, int expectedCount) {
|
||||
return (charSequence) -> {
|
||||
int count = StringUtils.countOccurrencesOf(charSequence.toString(), substring);
|
||||
assertThat(count).isEqualTo(expectedCount);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,9 @@
|
||||
|
||||
package smoketest.bitronix;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import bitronix.tm.resource.jms.PoolingConnectionFactory;
|
||||
import org.assertj.core.api.Condition;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
@@ -25,6 +26,7 @@ import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.test.system.CapturedOutput;
|
||||
import org.springframework.boot.test.system.OutputCaptureExtension;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -39,8 +41,10 @@ class SampleBitronixApplicationTests {
|
||||
@Test
|
||||
void testTransactionRollback(CapturedOutput output) throws Exception {
|
||||
SampleBitronixApplication.main(new String[] {});
|
||||
assertThat(output.toString()).has(substring(1, "---->")).has(substring(1, "----> josh"))
|
||||
.has(substring(2, "Count is 1")).has(substring(1, "Simulated error"));
|
||||
assertThat(output).satisfies(numberOfOccurrences("---->", 1));
|
||||
assertThat(output).satisfies(numberOfOccurrences("----> josh", 1));
|
||||
assertThat(output).satisfies(numberOfOccurrences("Count is 1", 2));
|
||||
assertThat(output).satisfies(numberOfOccurrences("Simulated error", 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -54,20 +58,10 @@ class SampleBitronixApplicationTests {
|
||||
assertThat(nonXaJmsConnectionFactory).isNotInstanceOf(PoolingConnectionFactory.class);
|
||||
}
|
||||
|
||||
private Condition<String> substring(int times, String substring) {
|
||||
return new Condition<String>("containing '" + substring + "' " + times + " times") {
|
||||
|
||||
@Override
|
||||
public boolean matches(String value) {
|
||||
int i = 0;
|
||||
while (value.contains(substring)) {
|
||||
int beginIndex = value.indexOf(substring) + substring.length();
|
||||
value = value.substring(beginIndex);
|
||||
i++;
|
||||
}
|
||||
return i == times;
|
||||
}
|
||||
|
||||
private <T extends CharSequence> Consumer<T> numberOfOccurrences(String substring, int expectedCount) {
|
||||
return (charSequence) -> {
|
||||
int count = StringUtils.countOccurrencesOf(charSequence.toString(), substring);
|
||||
assertThat(count).isEqualTo(expectedCount);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user