[vcs-log] fix extra space in time string, add tests

This commit is contained in:
Julia Beliaeva
2017-11-20 17:17:56 +03:00
parent 7f0598c046
commit 4b3cd9aaf0
2 changed files with 28 additions and 3 deletions
@@ -91,9 +91,12 @@ public class StopWatch {
result += quotient + (msec == 0 ? "" : "." + String.format(M_SEC_FORMAT, msec)) + UNIT_NAMES[i];
}
else {
result += quotient + UNIT_NAMES[i] + " ";
if (remainder == 0 && msec != 0) {
result += "0." + String.format(M_SEC_FORMAT, msec) + UNIT_NAMES[0];
result += quotient + UNIT_NAMES[i];
if (remainder != 0 || msec != 0) {
result += " ";
if (remainder == 0) {
result += "0." + String.format(M_SEC_FORMAT, msec) + UNIT_NAMES[0];
}
}
}
}
@@ -0,0 +1,22 @@
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.vcs.log.util
import org.junit.Assert.assertEquals
import org.junit.Test
class StopWatchTestCase {
@Test
fun testEvenMinutes() {
assertEquals("1m", StopWatch.formatTime(60000))
}
@Test
fun testEvenSeconds() {
assertEquals("1m 5s", StopWatch.formatTime(65000))
}
@Test
fun testUnEvenSeconds() {
assertEquals("1m 5.100s", StopWatch.formatTime(65100))
}
}