Skip to content

Commit

Permalink
rft - use commons-lang3 to format duration with words instead of millis
Browse files Browse the repository at this point in the history
for example: `<120 000L> milliseconds` now became as `2 minutes`
  • Loading branch information
MerkushevKirill committed Sep 30, 2014
1 parent 35c8e6a commit cd616e7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Expand Up @@ -3,6 +3,7 @@
import org.hamcrest.Description;

import static java.util.concurrent.TimeUnit.SECONDS;
import static org.apache.commons.lang3.time.DurationFormatUtils.formatDurationWords;

/**
* @author Alexander Tolmachev starlight@yandex-team.ru
Expand Down Expand Up @@ -38,6 +39,6 @@ public boolean shouldStopWaiting() {

@Override
public void describeTo(Description description) {
description.appendValue(timeout).appendText(" milliseconds");
description.appendText(formatDurationWords(timeout, true, true));
}
}
@@ -0,0 +1,33 @@
package ru.yandex.qatools.matchers.decorators;

import org.hamcrest.StringDescription;
import org.junit.Test;

import java.util.concurrent.TimeUnit;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

/**
* User: lanwen
* Date: 30.09.14
* Time: 17:52
*/
public class TimeoutWaiterTest {

@Test
public void shouldReturn30SecondsDescriptionByDefault() throws Exception {
StringDescription description = new StringDescription();
TimeoutWaiter.timeoutHasExpired().describeTo(description);

assertThat("Should format 30 seconds by default", description.toString(), equalTo("30 seconds"));
}

@Test
public void shouldReturnMinutesInDescription() throws Exception {
StringDescription description = new StringDescription();
TimeoutWaiter.timeoutHasExpired(TimeUnit.MINUTES.toMillis(2)).describeTo(description);

assertThat("Should format millis as minutes if can", description.toString(), equalTo("2 minutes"));
}
}

0 comments on commit cd616e7

Please sign in to comment.