1 package org.apache.maven.cli.event;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.lang.reflect.InvocationTargetException;
23 import java.lang.reflect.Method;
24
25 import junit.framework.TestCase;
26
27 public class ExecutionEventLoggerTest
28 extends TestCase
29 {
30
31 private static String getFormattedTime( long time )
32 throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException,
33 InvocationTargetException
34 {
35 Method method = ExecutionEventLogger.class.getDeclaredMethod( "getFormattedTime", long.class );
36 boolean accessible = method.isAccessible();
37 try
38 {
39 method.setAccessible( true );
40 return (String) method.invoke( null, time );
41 }
42 finally
43 {
44 method.setAccessible( accessible );
45 }
46 }
47
48 public void testGetFormattedTime()
49 throws Exception
50 {
51 assertEquals( "0.001s", getFormattedTime( 1 ) );
52 assertEquals( "0.999s", getFormattedTime( 1000 - 1 ) );
53 assertEquals( "1.000s", getFormattedTime( 1000 ) );
54 assertEquals( "59.999s", getFormattedTime( 60 * 1000 - 1 ) );
55 assertEquals( "1:00.000s", getFormattedTime( 60 * 1000 ) );
56 assertEquals( "59:59.999s", getFormattedTime( 60 * 60 * 1000 - 1 ) );
57 assertEquals( "1:00:00.000s", getFormattedTime( 60 * 60 * 1000 ) );
58 assertEquals( "23:59:59.999s", getFormattedTime( 24 * 60 * 60 * 1000 - 1 ) );
59 assertEquals( "24:00:00.000s", getFormattedTime( 24 * 60 * 60 * 1000 ) );
60 }
61 }