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
This commit is contained in:
Andy Wilkinson 2014-08-27 11:42:21 +01:00
parent 954da9cd72
commit a9c2eb3919
2 changed files with 22 additions and 14 deletions

View File

@ -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 {
@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("---->"));
}

View File

@ -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 {
@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("---->"));
}