Test case for Utils.formatTimer

This commit is contained in:
TranceLove
2018-12-26 15:47:54 +08:00
parent 7ae9487e56
commit efdd93cc50
2 changed files with 10 additions and 1 deletions
@@ -262,7 +262,6 @@ public class Utils {
* Formats input to plain mm:ss format
*/
public static String formatTimer(long timer) {
final long min = timer / 60;
final long sec = timer % 60;
return String.format(Locale.US, "%02d:%02d", min, sec);
@@ -3,6 +3,7 @@ package com.amaze.filemanager.utils;
import org.junit.Test;
import static com.amaze.filemanager.utils.Utils.sanitizeInput;
import static com.amaze.filemanager.utils.Utils.formatTimer;
import static org.junit.Assert.*;
public class UtilsTest {
@@ -17,4 +18,13 @@ public class UtilsTest {
assertEquals("an apple",sanitizeInput("an ...apple")); //test the removing of dots which are between two words.
assertEquals("an apple.",sanitizeInput(";an |apple....")); //test the removing of pipe sign and dots which are between two words. And test the fourth dot is not removed.
}
@Test
public void testFormatTimer() {
assertEquals("10:00", formatTimer(600));
assertEquals("00:00", formatTimer(0));
assertEquals("00:45", formatTimer(45));
assertEquals("02:45", formatTimer(165));
assertEquals("30:33", formatTimer(1833));
}
}