// Call when not tracking state @Test public void testRunNotTracking() { sLogger.setWriter(new StringWriter()); sLogger.start(); assertTrue(sLogger.isRunning()); ArrayList<StateGroup> grouplist = new ArrayList<>(); grouplist.add(group); resetAll(); expect(mockTracker.isTrackingState()).andReturn(false).anyTimes(); expect(mockTracker.getIoSet()).andReturn(ioSet).anyTimes(); expect(mockTracker.getStateList()).andReturn(grouplist).anyTimes(); replayAll(); Thread t = new Thread( new Runnable() { @Override public void run() { try { Thread.sleep(2500); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } sLogger.stop(); } }); t.start(); sLogger.run(); }
@Test public void testStart() { assertFalse(sLogger.isRunning()); sLogger.start(); assertTrue(sLogger.isRunning()); }
@Test public void testSetWriter() { StringWriter sw = new StringWriter(); sLogger.setWriter(sw); assertEquals(sw, sLogger.getOutput()); }
@Test public void testWriteInfoNullWriter() { String s; StringWriter writer = new StringWriter(); try { sLogger.writeInfo(null, ioSet); s = writer.getBuffer().toString(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
@Test(expected = NullPointerException.class) public void testWriteInfoNullInfo() { String s; StringWriter writer = new StringWriter(); try { sLogger.writeInfo(writer, null); s = writer.getBuffer().toString(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
// Test with null input // Test with valid input @Test public void testWriteStartValid() { String s; StringWriter writer = new StringWriter(); try { sLogger.writeStart(writer); s = writer.getBuffer().toString(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
@Test public void testWriteStartNull() { String s = null; StringWriter writer = new StringWriter(); try { sLogger.writeStart(null); s = writer.getBuffer().toString(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } assertEquals("", s.toString()); }
// Test with null input // Test with valid input @Test public void testWriteStateValid() { String s; StringWriter writer = new StringWriter(); ArrayList<StateGroup> list = new ArrayList<>(); list.add(group); list.add(group); try { sLogger.writeState(writer, list); s = writer.getBuffer().toString(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
@Test public void testIsRunning() { sLogger.start(); assertTrue(sLogger.isRunning()); }