Browse Source

Update JTA sample tests to work on Windows

Rather than hard-coding assumptions about the line endings, use a
PrintWriter to produce the multi-line expected output
pull/1323/merge
Andy Wilkinson 12 years ago
parent
commit
a9c2eb3919
  1. 17
      spring-boot-samples/spring-boot-sample-jta-atomikos/src/test/java/sample/atomikos/SampleAtomikosApplicationTests.java
  2. 19
      spring-boot-samples/spring-boot-sample-jta-bitronix/src/test/java/sample/bitronix/SampleBitronixApplicationTests.java

17
spring-boot-samples/spring-boot-sample-jta-atomikos/src/test/java/sample/atomikos/SampleAtomikosApplicationTests.java

@ -16,6 +16,9 @@ @@ -16,6 +16,9 @@
package sample.atomikos;
import java.io.PrintWriter;
import java.io.StringWriter;
import org.hamcrest.Matcher;
import org.hamcrest.core.SubstringMatcher;
import org.junit.Rule;
@ -38,12 +41,14 @@ public class SampleAtomikosApplicationTests { @@ -38,12 +41,14 @@ public class SampleAtomikosApplicationTests {
@Test
public void testTransactionRollback() throws Exception {
SampleAtomikosApplication.main(new String[] {});
String expected = "";
expected += "----> josh\n";
expected += "Count is 1\n";
expected += "Simulated error\n";
expected += "Count is 1\n";
assertThat(this.outputCapture.toString(), containsString(expected));
StringWriter expectedWriter = new StringWriter();
PrintWriter printer = new PrintWriter(expectedWriter);
printer.println("----> josh");
printer.println("Count is 1");
printer.println("Simulated error");
printer.println("Count is 1");
assertThat(this.outputCapture.toString(),
containsString(expectedWriter.toString()));
assertThat(this.outputCapture.toString(), containsStringOnce("---->"));
}

19
spring-boot-samples/spring-boot-sample-jta-bitronix/src/test/java/sample/bitronix/SampleBitronixApplicationTests.java

@ -16,14 +16,15 @@ @@ -16,14 +16,15 @@
package sample.bitronix;
import java.io.PrintWriter;
import java.io.StringWriter;
import org.hamcrest.Matcher;
import org.hamcrest.core.SubstringMatcher;
import org.junit.Rule;
import org.junit.Test;
import org.springframework.boot.test.OutputCapture;
import sample.bitronix.SampleBitronixApplication;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertThat;
@ -40,12 +41,14 @@ public class SampleBitronixApplicationTests { @@ -40,12 +41,14 @@ public class SampleBitronixApplicationTests {
@Test
public void testTransactionRollback() throws Exception {
SampleBitronixApplication.main(new String[] {});
String expected = "";
expected += "----> josh\n";
expected += "Count is 1\n";
expected += "Simulated error\n";
expected += "Count is 1\n";
assertThat(this.outputCapture.toString(), containsString(expected));
StringWriter expectedWriter = new StringWriter();
PrintWriter printer = new PrintWriter(expectedWriter);
printer.println("----> josh");
printer.println("Count is 1");
printer.println("Simulated error");
printer.println("Count is 1");
assertThat(this.outputCapture.toString(),
containsString(expectedWriter.toString()));
assertThat(this.outputCapture.toString(), containsStringOnce("---->"));
}

Loading…
Cancel
Save