001 package org.apache.maven.cli.event;
002
003 /*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements. See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership. The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License. You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied. See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022 import java.lang.reflect.InvocationTargetException;
023 import java.lang.reflect.Method;
024
025 import junit.framework.TestCase;
026
027 public class ExecutionEventLoggerTest
028 extends TestCase
029 {
030
031 private static String getFormattedTime( long time )
032 throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException,
033 InvocationTargetException
034 {
035 Method method = ExecutionEventLogger.class.getDeclaredMethod( "getFormattedTime", long.class );
036 boolean accessible = method.isAccessible();
037 try
038 {
039 method.setAccessible( true );
040 return (String) method.invoke( null, time );
041 }
042 finally
043 {
044 method.setAccessible( accessible );
045 }
046 }
047
048 public void testGetFormattedTime()
049 throws Exception
050 {
051 assertEquals( "0.001s", getFormattedTime( 1 ) );
052 assertEquals( "0.999s", getFormattedTime( 1000 - 1 ) );
053 assertEquals( "1.000s", getFormattedTime( 1000 ) );
054 assertEquals( "59.999s", getFormattedTime( 60 * 1000 - 1 ) );
055 assertEquals( "1:00.000s", getFormattedTime( 60 * 1000 ) );
056 assertEquals( "59:59.999s", getFormattedTime( 60 * 60 * 1000 - 1 ) );
057 assertEquals( "1:00:00.000s", getFormattedTime( 60 * 60 * 1000 ) );
058 assertEquals( "23:59:59.999s", getFormattedTime( 24 * 60 * 60 * 1000 - 1 ) );
059 assertEquals( "24:00:00.000s", getFormattedTime( 24 * 60 * 60 * 1000 ) );
060 }
061 }