@Test public void formatTimeTakenMs() { class TestCase { Pattern mExpected; String mInputMessage; public TestCase(String expectedRE, String inputMessage) { mExpected = Pattern.compile(expectedRE); mInputMessage = inputMessage; } } List<TestCase> testCases = new ArrayList<>(); testCases.add(new TestCase("^Task A took (.*) ms.$", "Task A")); testCases.add(new TestCase("^Task B took (.*) ms.$", "Task B")); long delta = 100; for (TestCase testCase : testCases) { String result = FormatUtils.formatTimeTakenMs(CommonUtils.getCurrentMs() - delta, testCase.mInputMessage); Matcher match = testCase.mExpected.matcher(result); assertTrue(match.matches()); assertTrue(delta <= Long.parseLong(match.group(1))); assertTrue(Long.parseLong(match.group(1)) <= 2 * delta); } }
public static String formatTimeTakenMs(long startTimeMs, String message) { return message + " took " + (CommonUtils.getCurrentMs() - startTimeMs) + " ms."; }
FormatUtils { public static String formatTimeTakenMs(long startTimeMs, String message) { return message + " took " + (CommonUtils.getCurrentMs() - startTimeMs) + " ms."; } }
FormatUtils { public static String formatTimeTakenMs(long startTimeMs, String message) { return message + " took " + (CommonUtils.getCurrentMs() - startTimeMs) + " ms."; } private  FormatUtils(); }
FormatUtils { public static String formatTimeTakenMs(long startTimeMs, String message) { return message + " took " + (CommonUtils.getCurrentMs() - startTimeMs) + " ms."; } private  FormatUtils(); static String parametersToString(Object... objs); static String byteBufferToString(ByteBuffer buf); static String byteArrayToHexString(byte[] bytes); static String byteArrayToHexString(byte[] bytes, String prefix, String separator); static String formatTimeTakenMs(long startTimeMs, String message); static String formatTimeTakenNs(long startTimeNs, String message); static String getSizeFromBytes(long bytes); static long parseSpaceSize(String spaceSize); static long parseTimeSize(String timeSize); static String formatMode(short mode, boolean directory, boolean hasExtended); }
FormatUtils { public static String formatTimeTakenMs(long startTimeMs, String message) { return message + " took " + (CommonUtils.getCurrentMs() - startTimeMs) + " ms."; } private  FormatUtils(); static String parametersToString(Object... objs); static String byteBufferToString(ByteBuffer buf); static String byteArrayToHexString(byte[] bytes); static String byteArrayToHexString(byte[] bytes, String prefix, String separator); static String formatTimeTakenMs(long startTimeMs, String message); static String formatTimeTakenNs(long startTimeNs, String message); static String getSizeFromBytes(long bytes); static long parseSpaceSize(String spaceSize); static long parseTimeSize(String timeSize); static String formatMode(short mode, boolean directory, boolean hasExtended);  }