1   package com.imcode.util;
2   
3   import junit.framework.*;
4   import org.apache.commons.lang.time.DateUtils;
5   
6   public class HumanReadableTest extends TestCase {
7   
8       public void testGetHumanReadableTimeSpan() throws Exception {
9           assertEquals( "1ms", HumanReadable.getHumanReadableTimeSpan( 1 ) );
10          assertEquals( "2s, 1ms", HumanReadable.getHumanReadableTimeSpan( 2 * DateUtils.MILLIS_IN_SECOND + 1 ) );
11          assertEquals( "3m, 1s", HumanReadable.getHumanReadableTimeSpan( 3 * DateUtils.MILLIS_IN_MINUTE
12                                                                         + 1 * DateUtils.MILLIS_IN_SECOND ) );
13          assertEquals( "4h, 1ms", HumanReadable.getHumanReadableTimeSpan( 4 * DateUtils.MILLIS_IN_HOUR + 1 ) );
14          assertEquals( "1h, 1m, 1s, 1ms", HumanReadable.getHumanReadableTimeSpan( DateUtils.MILLIS_IN_HOUR
15                                                                                  + DateUtils.MILLIS_IN_MINUTE
16                                                                                  + DateUtils.MILLIS_IN_SECOND
17                                                                                  + 1 ) );
18      }
19  
20      public void testGetHumanReadableByteSize() throws Exception {
21          assertEquals( "1023 B", HumanReadable.getHumanReadableByteSize( 1023 ) );
22          assertEquals( "1 kB", HumanReadable.getHumanReadableByteSize( 1024 ) );
23          assertEquals( "1.5 kB", HumanReadable.getHumanReadableByteSize( 1024+512 )) ;
24          assertEquals( "1.5 MB", HumanReadable.getHumanReadableByteSize( 1048576+524288 )) ;
25          assertEquals( "1 GB", HumanReadable.getHumanReadableByteSize( 1048576*1024 )) ;
26      }
27  }