Commit a9c2eb39 authored by Andy Wilkinson's avatar Andy Wilkinson

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
parent 954da9cd
...@@ -16,6 +16,9 @@ ...@@ -16,6 +16,9 @@
package sample.atomikos; package sample.atomikos;
import java.io.PrintWriter;
import java.io.StringWriter;
import org.hamcrest.Matcher; import org.hamcrest.Matcher;
import org.hamcrest.core.SubstringMatcher; import org.hamcrest.core.SubstringMatcher;
import org.junit.Rule; import org.junit.Rule;
...@@ -38,12 +41,14 @@ public class SampleAtomikosApplicationTests { ...@@ -38,12 +41,14 @@ public class SampleAtomikosApplicationTests {
@Test @Test
public void testTransactionRollback() throws Exception { public void testTransactionRollback() throws Exception {
SampleAtomikosApplication.main(new String[] {}); SampleAtomikosApplication.main(new String[] {});
String expected = ""; StringWriter expectedWriter = new StringWriter();
expected += "----> josh\n"; PrintWriter printer = new PrintWriter(expectedWriter);
expected += "Count is 1\n"; printer.println("----> josh");
expected += "Simulated error\n"; printer.println("Count is 1");
expected += "Count is 1\n"; printer.println("Simulated error");
assertThat(this.outputCapture.toString(), containsString(expected)); printer.println("Count is 1");
assertThat(this.outputCapture.toString(),
containsString(expectedWriter.toString()));
assertThat(this.outputCapture.toString(), containsStringOnce("---->")); assertThat(this.outputCapture.toString(), containsStringOnce("---->"));
} }
......
...@@ -16,14 +16,15 @@ ...@@ -16,14 +16,15 @@
package sample.bitronix; package sample.bitronix;
import java.io.PrintWriter;
import java.io.StringWriter;
import org.hamcrest.Matcher; import org.hamcrest.Matcher;
import org.hamcrest.core.SubstringMatcher; import org.hamcrest.core.SubstringMatcher;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.springframework.boot.test.OutputCapture; import org.springframework.boot.test.OutputCapture;
import sample.bitronix.SampleBitronixApplication;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
...@@ -40,12 +41,14 @@ public class SampleBitronixApplicationTests { ...@@ -40,12 +41,14 @@ public class SampleBitronixApplicationTests {
@Test @Test
public void testTransactionRollback() throws Exception { public void testTransactionRollback() throws Exception {
SampleBitronixApplication.main(new String[] {}); SampleBitronixApplication.main(new String[] {});
String expected = ""; StringWriter expectedWriter = new StringWriter();
expected += "----> josh\n"; PrintWriter printer = new PrintWriter(expectedWriter);
expected += "Count is 1\n"; printer.println("----> josh");
expected += "Simulated error\n"; printer.println("Count is 1");
expected += "Count is 1\n"; printer.println("Simulated error");
assertThat(this.outputCapture.toString(), containsString(expected)); printer.println("Count is 1");
assertThat(this.outputCapture.toString(),
containsString(expectedWriter.toString()));
assertThat(this.outputCapture.toString(), containsStringOnce("---->")); assertThat(this.outputCapture.toString(), containsStringOnce("---->"));
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment