I have a following parametrized test
@ParameterizedTest
@ValueSource(strings = {
"[1;1f[?25l",
"[K[K\n",
"[0m 8 [48;2;142;142;142m[38;2;0;0;0m ♜ [48;2;204;204;204m[38;2;0;0;0m ♞ [48;2;142;142;142m[38;2;0;0;0m ♝ [48;2;204;204;204m[38;2;0;0;0m ♛ [48;2;142;142;142m[38;2;0;0;0m ♚ [48;2;204;204;204m[38;2;0;0;0m ♝ [48;2;142;142;142m[38;2;0;0;0m ♞ [48;2;204;204;204m[38;2;0;0;0m ♜ [0m Board value: 0",
"[K[0m 7 [48;2;204;204;204m[38;2;0;0;0m[1m ♙ [48;2;142;142;142m[38;2;0;0;0m[1m ♙ [48;2;204;204;204m[38;2;0;0;0m[1m ♙ [48;2;142;142;142m[38;2;0;0;0m[1m ♙ [48;2;204;204;204m[38;2;0;0;0m[1m ♙ [48;2;142;142;142m[38;2;0;0;0m[1m ♙ [48;2;204;204;204m[38;2;0;0;0m[1m ♙ [48;2;142;142;142m[38;2;0;0;0m[1m ♙ [0m Player 1 taken:",
"[K[0m 6 [48;2;142;142;142m[38;2;0;0;0m [48;2;204;204;204m[38;2;0;0;0m [48;2;142;142;142m[38;2;0;0;0m [48;2;204;204;204m[38;2;0;0;0m [48;2;142;142;142m[38;2;0;0;0m [48;2;204;204;204m[38;2;0;0;0m [48;2;142;142;142m[38;2;0;0;0m [48;2;204;204;204m[38;2;0;0;0m [0m Player 2 taken:",
"[K[0m 5 [48;2;204;204;204m[38;2;0;0;0m [48;2;142;142;142m[38;2;0;0;0m [48;2;204;204;204m[38;2;0;0;0m [48;2;142;142;142m[38;2;0;0;0m [48;2;204;204;204m[38;2;0;0;0m [48;2;142;142;142m[38;2;0;0;0m [48;2;204;204;204m[38;2;0;0;0m [48;2;142;142;142m[38;2;0;0;0m [0m",
"[K[0m 4 [48;2;142;142;142m[38;2;0;0;0m [48;2;204;204;204m[38;2;0;0;0m [48;2;142;142;142m[38;2;0;0;0m [48;2;204;204;204m[38;2;0;0;0m [48;2;142;142;142m[38;2;0;0;0m [48;2;204;204;204m[38;2;0;0;0m [48;2;142;142;142m[38;2;0;0;0m [48;2;204;204;204m[38;2;0;0;0m [0m",
"[K[0m 3 [48;2;204;204;204m[38;2;0;0;0m [48;2;142;142;142m[38;2;0;0;0m [48;2;204;204;204m[38;2;0;0;0m [48;2;142;142;142m[38;2;0;0;0m [48;2;204;204;204m[38;2;0;0;0m [48;2;142;142;142m[38;2;0;0;0m [48;2;204;204;204m[38;2;0;0;0m [48;2;142;142;142m[38;2;0;0;0m [0m",
"[K[0m 2 [48;2;142;142;142m[38;2;255;255;255m[1m ♙ [48;2;204;204;204m[38;2;255;255;255m[1m ♙ [48;2;142;142;142m[38;2;255;255;255m[1m ♙ [48;2;204;204;204m[38;2;255;255;255m[1m ♙ [48;2;142;142;142m[38;2;255;255;255m[1m ♙ [48;2;204;204;204m[38;2;255;255;255m[1m ♙ [48;2;142;142;142m[38;2;255;255;255m[1m ♙ [48;2;204;204;204m[38;2;255;255;255m[1m ♙ [0m",
"[K[0m 1 [48;2;204;204;204m[38;2;255;255;255m ♜ [48;2;142;142;142m[38;2;255;255;255m ♞ [48;2;204;204;204m[38;2;255;255;255m ♝ [48;2;142;142;142m[38;2;255;255;255m ♛ [48;2;204;204;204m[38;2;255;255;255m ♚ [48;2;142;142;142m[38;2;255;255;255m ♝ [48;2;204;204;204m[38;2;255;255;255m ♞ [48;2;142;142;142m[38;2;255;255;255m ♜ [0m",
"[K A B C D E F G H",
"1: Player 1's Turn: "
})
void showBoardShouldReturnProperBoardRepresentationForBasicBoardWhenScreenFileIsFalse(String line) throws IOException {
// given
java.util.HashMap<String, String> options = new java.util.HashMap<>();
Main.options = options;
ChessConfig config = new ChessConfig("");
config.loadConfiguration();
Main.config = config;
PrintStream originalOut = System.out;
ByteArrayOutputStream bo = new ByteArrayOutputStream();
System.setOut(new PrintStream(bo));
// when
Main.showBoard(new LiteBoard(), null, new LiteMinimax("", 6, 0), 0, 0, true);
bo.flush();
String resultPrinted = new String(bo.toByteArray());
// then
System.setOut(originalOut);
assertTrue(resultPrinted.contains(line));
}
It works when run separately but keeps failing when I run it along other tests. I found out that the third string is being evaluated to the following one
[K[0m 7 [48;2;204;204;204m[38;2;0;0;0m[1m ? [48;2;142;142;142m[38;2;0;0;0m[1m ? [48;2;204;204;204m[38;2;0;0;0m[1m ? [48;2;142;142;142m[38;2;0;0;0m[1m ? [48;2;204;204;204m[38;2;0;0;0m[1m ? [48;2;142;142;142m[38;2;0;0;0m[1m ? [48;2;204;204;204m[38;2;0;0;0m[1m ? [48;2;142;142;142m[38;2;0;0;0m[1m ? [0m Player 1 taken:
I changed it but it is still failing. I am using Eclipse, and the board (it is a chess game from the Web which I am trying to refactor) is displayed in this format.