package org.gridkit.jvmtool.cmd;

import org.gridkit.jvmtool.cmd.StackSampleAnalyzerCmd.DateFormater;
import org.gridkit.jvmtool.cmd.StackSampleAnalyzerCmd.DecimalFormater;
import org.gridkit.jvmtool.cmd.StackSampleAnalyzerCmd.MemRateFormater;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import java.util.TimeZone;

public class StackSampleAnalyzerCmdTest {

  @Rule public ExpectedException thrown = ExpectedException.none();

  @Test
  public void testNullTimeZoneDateFormaterToString(){
    Assert.assertEquals("", new DateFormater(null).toString(null));
  }

  @Test
  public void testDateFormaterToString(){
    Assert.assertEquals("2019.02.18_17:17:14", new DateFormater(TimeZone.getTimeZone("UTC")).toString(1550510234000L));
  }

  @Test
  public void testDateFormaterToStringException() {
    thrown.expect(NullPointerException.class);
    new DateFormater(null).toString(0L);
    // Exception thrown
  }

  @Test
  public void testDecimalFormaterToStringNullParam() {
    Assert.assertEquals("", new DecimalFormater(9).toString(null));
  }

  @Test
  public void testDecimalFormaterToStringNonNumericParam() {
    Assert.assertEquals("", new DecimalFormater(9).toString("text"));
  }

  @Test
  public void testDecimalFormaterToStringLongParam() {
    Assert.assertEquals("\t4", new DecimalFormater(9).toString(4L));
  }

  @Test
  public void testDecimalFormaterToStringNumericParam() {
    Assert.assertEquals("\t4.000000000", new DecimalFormater(9).toString(4));
  }

  @Test
  public void testMemRateFormaterToStringNullParam() {
    Assert.assertEquals("", new MemRateFormater().toString(null));
  }

  @Test
  public void testMemRateFormaterToStringNaNParam() {
    Assert.assertEquals("", new MemRateFormater().toString(Double.NaN));
  }

  @Test
  public void testMemRateFormaterToStringNoRate() {
    Assert.assertEquals("0/s", new MemRateFormater().toString(0));
  }

  @Test
  public void testMemRateFormaterToString() {
    Assert.assertEquals("9/s", new MemRateFormater().toString(9));
  }

  @Test
  public void testMemRateFormaterToStringKps() {
    Assert.assertEquals("19k/s", new MemRateFormater().toString(20475));
  }

  @Test
  public void testMemRateFormaterToStringMps() {
    Assert.assertEquals("70m/s", new MemRateFormater().toString(74160839));
  }

  @Test
  public void testMemRateFormaterToStringGps() {
    Assert.assertEquals("10g/s", new MemRateFormater().toString(10737418240L));
  }

}

@@ -1493,18 +1493,304 @@
 %22%5Ct4
-.000000000
+%22, new DecimalFormater(9).toString(4));%0A  %7D%0A%0A  @Test%0A  public void testDecimalFormaterToStringNumericParam2() %7B%0A    Assert.assertEquals(%22%5Ct4.0000001%22, new DecimalFormater(9).toString(4.0000001));%0A  %7D%0A%0A  @Test%0A  public void testDecimalFormaterToStringNumericParam3() %7B%0A    Assert.assertEquals(%22%5Ct4
 %22, n
@@ -1800,33 +1800,33 @@
 DecimalFormater(
-9
+2
 ).toString(4));%0A
@@ -1813,32 +1813,40 @@
 er(2).toString(4
+.0000001
 ));%0A  %7D%0A%0A  @Test

Test fix