From 4b3cd9aaf0dfd89f3789165f26bab63108a4db0d Mon Sep 17 00:00:00 2001 From: Julia Beliaeva Date: Wed, 15 Nov 2017 22:53:14 +0300 Subject: [PATCH] [vcs-log] fix extra space in time string, add tests --- .../com/intellij/vcs/log/util/StopWatch.java | 9 +++++--- .../intellij/vcs/log/util/StopWatchTest.kt | 22 +++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 platform/vcs-log/impl/test/com/intellij/vcs/log/util/StopWatchTest.kt diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/util/StopWatch.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/util/StopWatch.java index f9ac6d2815a5..00f57c06d70a 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/util/StopWatch.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/util/StopWatch.java @@ -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]; + } } } } diff --git a/platform/vcs-log/impl/test/com/intellij/vcs/log/util/StopWatchTest.kt b/platform/vcs-log/impl/test/com/intellij/vcs/log/util/StopWatchTest.kt new file mode 100644 index 000000000000..1d858ecf69f2 --- /dev/null +++ b/platform/vcs-log/impl/test/com/intellij/vcs/log/util/StopWatchTest.kt @@ -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)) + } +} \ No newline at end of file