View Javadoc

1   package org.apache.maven.cli.event;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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  }