package com.statusParser.tests; import com.statusParser.Mysql; import org.junit.*; import static org.junit.Assert.*; import java.io.ByteArrayOutputStream; import java.io.PrintStream; /** * Created with IntelliJ IDEA. * User: sadvr * Date: 1/11/14 * Time: 4:11 AM */ public class MysqlTestDrive { private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); private final ByteArrayOutputStream errContent = new ByteArrayOutputStream(); private static PrintStream oldOut; private static PrintStream oldErr; @Before public void setUpStreams() { System.setOut(new PrintStream(outContent)); System.setErr(new PrintStream(errContent)); oldOut = System.out; oldErr = System.err; } @After public void cleanUpStreams() { System.setOut(null); System.setErr(null); /* System.out.flush(); System.setOut(oldOut); System.setErr(oldErr); */ } @Test public void out() { System.out.print("hello"); assertEquals("hello", outContent.toString()); } @Test public void err() { System.err.print("hello again"); assertEquals("hello again", errContent.toString()); } @Test public void getConnection() { Mysql mysql = new Mysql(); assertTrue(outContent.toString().matches("com.mysql.jdbc.JDBC4Connection@[A-Za-z0-9\n]+")); } }