Skip to content

Commit

Permalink
polished
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Oct 24, 2024
1 parent c2f5697 commit c9a2ccc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
14 changes: 7 additions & 7 deletions src/test/java/org/takes/tk/TkProxyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ final class TkProxyTest {
/**
* Collection of HTTP method matches for which nobody is returned.
*/
private static final Map<String, Factory> NOBODIES =
private static final Map<String, TkProxyTest.Factory> NOBODIES =
new MapOf<>(
new IterableOf<>(
new MapEntry<>(RqMethod.GET, RqWithoutBody::new),
new MapEntry<>(RqMethod.HEAD, RqWithoutBody::new),
new MapEntry<>(RqMethod.DELETE, RqWithoutBody::new),
new MapEntry<>(RqMethod.OPTIONS, RqWithoutBody::new),
new MapEntry<>(RqMethod.TRACE, RqWithoutBody::new)
new MapEntry<>(RqMethod.GET, TkProxyTest.RqWithoutBody::new),
new MapEntry<>(RqMethod.HEAD, TkProxyTest.RqWithoutBody::new),
new MapEntry<>(RqMethod.DELETE, TkProxyTest.RqWithoutBody::new),
new MapEntry<>(RqMethod.OPTIONS, TkProxyTest.RqWithoutBody::new),
new MapEntry<>(RqMethod.TRACE, TkProxyTest.RqWithoutBody::new)
)
);

Expand Down Expand Up @@ -278,7 +278,7 @@ void addsAllInitialHeaders() throws Exception {

private static Request createEchoRequest(final Request req) throws IOException {
final String method = new RqMethod.Base(req).method();
return NOBODIES.getOrDefault(method, rq -> req).create(req);
return TkProxyTest.NOBODIES.getOrDefault(method, rq -> req).create(req);
}

/**
Expand Down
19 changes: 8 additions & 11 deletions src/test/java/org/takes/tk/TkRetryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,21 @@ void retriesOnExceptionTillCount() {
Assertions.assertThrows(
IOException.class,
() -> {
final int count = TkRetryTest.COUNT;
final int delay = TkRetryTest.DELAY;
final Take take = Mockito.mock(Take.class);
Mockito
.when(take.act(Mockito.any(Request.class)))
.thenThrow(new IOException());
.thenThrow(new IOException("oops"));
final long start = System.nanoTime();
final int count = TkRetryTest.COUNT;
final int delay = TkRetryTest.DELAY;
try {
new TkRetry(count, delay, take).act(
new RqFake(RqMethod.GET)
);
} catch (final IOException exception) {
final long spent = System.nanoTime() - start;
MatcherAssert.assertThat(
Long.valueOf(
count * delay - TkRetryTest.HUNDRED
) * TkRetryTest.TO_NANOS,
(long) (count * delay - TkRetryTest.HUNDRED) * (long) TkRetryTest.TO_NANOS,
Matchers.lessThanOrEqualTo(spent)
);
throw exception;
Expand All @@ -109,21 +107,20 @@ void retriesOnExceptionTillCount() {

@Test
void retriesOnExceptionTillSuccess() throws Exception {
final int count = TkRetryTest.COUNT;
final int delay = TkRetryTest.DELAY;
final String data = "data";
final Take take = Mockito.mock(Take.class);
Mockito
.when(take.act(Mockito.any(Request.class)))
.thenThrow(new IOException())
.thenThrow(new IOException("oops"))
.thenReturn(new RsText(data));
final long start = System.nanoTime();
final int delay = TkRetryTest.DELAY;
final RsPrint response = new RsPrint(
new TkRetry(count, delay, take).act(new RqFake(RqMethod.GET))
new TkRetry(TkRetryTest.COUNT, delay, take).act(new RqFake(RqMethod.GET))
);
final long spent = System.nanoTime() - start;
MatcherAssert.assertThat(
Long.valueOf(delay - TkRetryTest.HUNDRED) * TkRetryTest.TO_NANOS,
(long) (delay - TkRetryTest.HUNDRED) * (long) TkRetryTest.TO_NANOS,
Matchers.lessThanOrEqualTo(spent)
);
MatcherAssert.assertThat(
Expand Down

0 comments on commit c9a2ccc

Please sign in to comment.