So I'm redirecting my print outputs to a stream, which becomes a char array. Then, when I use Junit, I use .toString() on the char array to make it become a long string. However, when I compare the string with the exact string that it should be, it says they are not equal--if and only if I'm on a Windows 7 computer. When I'm on a linux, or a mac, it seems to work fine, and the test passes. This doesn't seem to make sense for it to work on one computer but not another.
This is the code:
ByteArrayOutputStream os = new ByteArrayOutputStream(); PrintStream myPrintStream = new PrintStream(os); /* * make reference to default print stream */ PrintStream defaultOutstream = System.out; System.setOut(myPrintStream); m.logic(args); // this actually runs my program that creates the output System.setOut(defaultOutstream); // returns output stream to System.out String expected = "Pop\tTitle\n" + "-------------------\n" + "94\tClose Shave, A (1995)\n" + "93\tWrong Trousers, The (1993)\n" + "93\tWallace & Gromit: The Best of Aardman Animation (1996)\n" + "86\tGrand Day Out, A (1992)\n" + "81\tToy Story (1995)\n"; String actual = os.toString(); // converts to string assertEquals(expected, actual);
I assure you, that the expected and the os.toString() is exactly the same, in fact it's copy pasted from it. I've also tried doing assertTrue(expected.compareTo(actual)) which still returns false on a Windows 7 computer. Is this even possible?
Additional info: I'm using Eclipse, Junit 4, tried on Windows 7 32 and 64-bit. Works fine on non-Windows 7 it seems...
Anyone have any idea what could be causing this? When I trace the error on Eclipse, it shows the actual outut and the expected output, and they're exactly the same, yet it says it's not the same. Usually it would highlight the difference, whether it be a space, an extra hard return, or anything.
Thanks for your help/