package org.threadly.util.debug;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Test;
import org.threadly.util.Clock;
import org.threadly.util.StringUtils;

@SuppressWarnings("javadoc")
public class DebugLoggerTest {
  @After
  public void cleanup() {
    DebugLogger.getAllStoredMessages(); // should clear state
  }
  
  @Test
  public void benchmark() {
    long start = System.nanoTime();
    for (int i = 0; i < 500000; i++) {
      DebugLogger.log("foo");
    }
    long end = System.nanoTime();
    System.out.println((end - start) / Clock.NANOS_IN_MILLISECOND);
  }
  
  @Test
  public void getCurrentMessageQtyTest() {
    // make sure debug logger is clear
    DebugLogger.getAllStoredMessages(false);
    
    assertEquals(0, DebugLogger.getCurrentMessageQty());
    
    DebugLogger.log("testMsg");
    
    assertEquals(1, DebugLogger.getCurrentMessageQty());
  }
  
  @Test
  public void getAllSingleTest() {
    String testStr = StringUtils.makeRandomString(5);
    DebugLogger.log(testStr);
    
    assertTrue(DebugLogger.getAllStoredMessages(false).equals(testStr));
    
    assertEquals(0, DebugLogger.getAllStoredMessages().length());
  }
  
  @Test
  public void getAllMultipleTest() {
    String testStr1 = StringUtils.makeRandomString(5);
    String testStr2 = StringUtils.makeRandomString(5);
    DebugLogger.log(testStr1);
    DebugLogger.log(testStr2);
    
    String result = DebugLogger.getAllStoredMessages(true);
    
    assertTrue(result.contains(testStr1));
    assertTrue(result.contains(testStr2));
    
    assertEquals(0, DebugLogger.getAllStoredMessages().length());
  }
  
  @Test
  public void getQtySingleTest() {
    String testStr = StringUtils.makeRandomString(5);
    DebugLogger.log(testStr);
    
    assertTrue(DebugLogger.getOldestLogMessages(2).equals(testStr));
    
    assertEquals(0, DebugLogger.getAllStoredMessages().length());
  }
  
  @Test
  public void getQtyMultipleTest() {
    String testStr1 = StringUtils.makeRandomString(5);
    String testStr2 = StringUtils.makeRandomString(5);
    DebugLogger.log(testStr1);
    DebugLogger.log(testStr2);
    
    String result = DebugLogger.getOldestLogMessages(2, true);
    
    assertTrue(result.contains(testStr1));
    assertTrue(result.contains(testStr2));
    
    assertEquals(0, DebugLogger.getAllStoredMessages().length());
  }
  
  @Test
  public void getQtyLimitedTest() {
    String testStr1 = StringUtils.makeRandomString(5);
    String testStr2 = StringUtils.makeRandomString(5);
    DebugLogger.log(testStr1);
    DebugLogger.log(testStr2);
    
    String result = DebugLogger.getOldestLogMessages(1, true);
    
    assertTrue(result.contains(testStr1));
    assertFalse(result.contains(testStr2));
    
    assertTrue(DebugLogger.getAllStoredMessages().length() > 0);
  }
}

@@ -113,40 +113,8 @@
 st;%0A
-import org.threadly.util.Clock;%0A
 impo
@@ -324,264 +324,8 @@
 est%0A
-  public void benchmark() %7B%0A    long start = System.nanoTime();%0A    for (int i = 0; i %3C 500000; i++) %7B%0A      DebugLogger.log(%22foo%22);%0A    %7D%0A    long end = System.nanoTime();%0A    System.out.println((end - start) / Clock.NANOS_IN_MILLISECOND);%0A  %7D%0A  %0A  @Test%0A
   pu

remove accidently commited benchmark