Skip to content

Commit

Permalink
remove hamcrest conditions (#1249)
Browse files Browse the repository at this point in the history
  • Loading branch information
ferozco authored and bulldozer-bot[bot] committed Sep 18, 2019
1 parent 063f151 commit 8381ea9
Show file tree
Hide file tree
Showing 29 changed files with 250 additions and 362 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.fail;
import static org.hamcrest.Matchers.is;

import com.google.common.collect.Lists;
import com.palantir.conjure.java.client.config.ClientConfiguration;
Expand All @@ -34,7 +33,6 @@
import java.util.concurrent.Future;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import org.assertj.core.api.HamcrestCondition;
import org.junit.Test;
import org.junit.experimental.theories.DataPoints;
import org.junit.experimental.theories.FromDataPoints;
Expand Down Expand Up @@ -86,7 +84,7 @@ public void testConnectionError_performsFailover(
failoverTestCase.server1.shutdown();
failoverTestCase.server2.enqueue(new MockResponse().setBody("\"foo\""));

assertThat(proxy.string()).is(new HamcrestCondition<>(is("foo")));
assertThat(proxy.string()).isEqualTo("foo");
}

@Test
Expand All @@ -107,7 +105,7 @@ public void testConnectionError_performsFailover_concurrentRequests(
things.add(executorService.submit(() -> proxy.string()));
}
for (int i = 0; i < 10; i++) {
assertThat(things.get(i).get()).is(new HamcrestCondition<>(is("foo")));
assertThat(things.get(i).get()).isEqualTo("foo");
}
}

Expand All @@ -132,7 +130,7 @@ public void testConnectionError_whenOneCallFailsThenSubsequentNewCallsCanStillSu
MockWebServer anotherServer1 = new MockWebServer(); // Not a @Rule so we can control start/stop/port explicitly
anotherServer1.start(failoverTestCase.server1.getPort());
anotherServer1.enqueue(new MockResponse().setBody("\"foo\""));
assertThat(proxy.string()).is(new HamcrestCondition<>(is("foo")));
assertThat(proxy.string()).isEqualTo("foo");
anotherServer1.shutdown();
}

Expand All @@ -146,7 +144,7 @@ public void testQosError_performsFailover(
failoverTestCase.server1.enqueue(new MockResponse().setBody("\"foo\""));
failoverTestCase.server2.enqueue(new MockResponse().setBody("\"bar\""));

assertThat(proxy.string()).is(new HamcrestCondition<>(is("bar")));
assertThat(proxy.string()).isEqualTo("bar");
}

@Test
Expand All @@ -163,8 +161,8 @@ public void testConnectionError_performsFailoverOnDnsFailure(
"http://localhost:" + failoverTestCase.server1.getPort()))
.maxNumRetries(2)
.build());
assertThat(bogusHostProxy.string()).is(new HamcrestCondition<>(is("foo")));
assertThat(failoverTestCase.server1.getRequestCount()).is(new HamcrestCondition<>(is(1)));
assertThat(bogusHostProxy.string()).isEqualTo("foo");
assertThat(failoverTestCase.server1.getRequestCount()).isEqualTo(1);
}

@Test
Expand All @@ -182,7 +180,7 @@ public void testQosError_performsRetryWithOneNode() throws Exception {
.maxNumRetries(2)
.build());

assertThat(anotherProxy.string()).is(new HamcrestCondition<>(is("foo")));
assertThat(anotherProxy.string()).isEqualTo("foo");
}

@Test
Expand All @@ -201,7 +199,7 @@ public void testQosError_performsRetryWithOneNodeAndCache() throws Exception {
.failedUrlCooldown(Duration.ofMillis(CACHE_DURATION))
.build());

assertThat(anotherProxy.string()).is(new HamcrestCondition<>(is("foo")));
assertThat(anotherProxy.string()).isEqualTo("foo");
}

@Test
Expand Down Expand Up @@ -231,7 +229,7 @@ public void testCache_recovery() throws Exception {

anotherServer1.enqueue(new MockResponse().setResponseCode(503));
anotherServer1.enqueue(new MockResponse().setBody("\"foo\""));
assertThat(anotherProxy.string()).is(new HamcrestCondition<>(is("foo")));
assertThat(anotherProxy.string()).isEqualTo("foo");
anotherServer1.shutdown();
}

Expand All @@ -249,8 +247,8 @@ public void testPerformsRoundRobin() throws Exception {
proxy.string();
proxy.string();

assertThat(failoverTestCase.server1.getRequestCount()).is(new HamcrestCondition<>(is(1)));
assertThat(failoverTestCase.server2.getRequestCount()).is(new HamcrestCondition<>(is(1)));
assertThat(failoverTestCase.server1.getRequestCount()).isEqualTo(1);
assertThat(failoverTestCase.server2.getRequestCount()).isEqualTo(1);
}

private static class FailoverTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.hamcrest.Matchers.is;

import com.palantir.conjure.java.okhttp.HostMetricsRegistry;
import javax.ws.rs.GET;
Expand All @@ -29,7 +28,6 @@
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import okhttp3.mockwebserver.RecordedRequest;
import org.assertj.core.api.HamcrestCondition;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
Expand Down Expand Up @@ -93,52 +91,52 @@ public void testCannotDecorateInterfaceWithOptionalPathParam() {
public void testRegularPathParam() throws Exception {
proxy.path("str2");
RecordedRequest takeRequest = server.takeRequest();
assertThat(takeRequest.getPath()).is(new HamcrestCondition<>(is("/foo/str2")));
assertThat(takeRequest.getPath()).isEqualTo("/foo/str2");
}

@Test
public void testAbsentQuery() throws Exception {
proxy.query(com.google.common.base.Optional.absent(), "str2");
RecordedRequest takeRequest = server.takeRequest();
assertThat(takeRequest.getRequestLine()).is(new HamcrestCondition<>(is("GET /foo?req=str2 HTTP/1.1")));
assertThat(takeRequest.getRequestLine()).isEqualTo("GET /foo?req=str2 HTTP/1.1");
}

@Test
public void testEmptyStringQuery() throws Exception {
proxy.query(com.google.common.base.Optional.of(""), "str2");
RecordedRequest takeRequest = server.takeRequest();
assertThat(takeRequest.getRequestLine()).is(new HamcrestCondition<>(is("GET /foo?opt=&req=str2 HTTP/1.1")));
assertThat(takeRequest.getRequestLine()).isEqualTo("GET /foo?opt=&req=str2 HTTP/1.1");
}

@Test
public void testStringQuery() throws Exception {
proxy.query(com.google.common.base.Optional.of("str"), "str2");
RecordedRequest takeRequest = server.takeRequest();
assertThat(takeRequest.getRequestLine()).is(new HamcrestCondition<>(is("GET /foo?opt=str&req=str2 HTTP/1.1")));
assertThat(takeRequest.getRequestLine()).isEqualTo("GET /foo?opt=str&req=str2 HTTP/1.1");
}

@Test
public void testAbsentHeader() throws Exception {
proxy.header(com.google.common.base.Optional.absent(), "str2");
RecordedRequest takeRequest = server.takeRequest();
assertThat(takeRequest.getHeader("opt")).is(new HamcrestCondition<>(is("")));
assertThat(takeRequest.getHeader("req")).is(new HamcrestCondition<>(is("str2")));
assertThat(takeRequest.getHeader("opt")).isEqualTo("");
assertThat(takeRequest.getHeader("req")).isEqualTo("str2");
}

@Test
public void testEmptyStringHeader() throws Exception {
proxy.header(com.google.common.base.Optional.of(""), "str2");
RecordedRequest takeRequest = server.takeRequest();
assertThat(takeRequest.getHeader("opt")).is(new HamcrestCondition<>(is("")));
assertThat(takeRequest.getHeader("req")).is(new HamcrestCondition<>(is("str2")));
assertThat(takeRequest.getHeader("opt")).isEqualTo("");
assertThat(takeRequest.getHeader("req")).isEqualTo("str2");
}

@Test
public void testStringHeader() throws Exception {
proxy.header(com.google.common.base.Optional.of("str"), "str2");
RecordedRequest takeRequest = server.takeRequest();
assertThat(takeRequest.getHeader("opt")).is(new HamcrestCondition<>(is("str")));
assertThat(takeRequest.getHeader("req")).is(new HamcrestCondition<>(is("str2")));
assertThat(takeRequest.getHeader("opt")).isEqualTo("str");
assertThat(takeRequest.getHeader("req")).isEqualTo("str2");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.hamcrest.Matchers.is;

import com.palantir.conjure.java.okhttp.HostMetricsRegistry;
import java.util.Optional;
Expand All @@ -33,7 +32,6 @@
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import okhttp3.mockwebserver.RecordedRequest;
import org.assertj.core.api.HamcrestCondition;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
Expand Down Expand Up @@ -122,68 +120,68 @@ public void testCannotDecorateInterfaceWithOptionalPathParam() {
public void testRegularPathParam() throws Exception {
proxy.path("str2");
RecordedRequest takeRequest = server.takeRequest();
assertThat(takeRequest.getPath()).is(new HamcrestCondition<>(is("/foo/str2")));
assertThat(takeRequest.getPath()).isEqualTo("/foo/str2");
}

@Test
public void testAbsentQuery() throws Exception {
proxy.query(Optional.empty(), "str2");
RecordedRequest takeRequest = server.takeRequest();
assertThat(takeRequest.getRequestLine()).is(new HamcrestCondition<>(is("GET /foo?req=str2 HTTP/1.1")));
assertThat(takeRequest.getRequestLine()).isEqualTo("GET /foo?req=str2 HTTP/1.1");
}

@Test
public void testEmptyStringQuery() throws Exception {
proxy.query(Optional.of(""), "str2");
RecordedRequest takeRequest = server.takeRequest();
assertThat(takeRequest.getRequestLine()).is(new HamcrestCondition<>(is("GET /foo?opt=&req=str2 HTTP/1.1")));
assertThat(takeRequest.getRequestLine()).isEqualTo("GET /foo?opt=&req=str2 HTTP/1.1");
}

@Test
public void testStringQuery() throws Exception {
proxy.query(Optional.of("str"), "str2");
RecordedRequest takeRequest = server.takeRequest();
assertThat(takeRequest.getRequestLine()).is(new HamcrestCondition<>(is("GET /foo?opt=str&req=str2 HTTP/1.1")));
assertThat(takeRequest.getRequestLine()).isEqualTo("GET /foo?opt=str&req=str2 HTTP/1.1");
}

@Test
public void testAbsentHeader() throws Exception {
proxy.header(Optional.empty(), "str2");
RecordedRequest takeRequest = server.takeRequest();
assertThat(takeRequest.getHeader("opt")).is(new HamcrestCondition<>(is("")));
assertThat(takeRequest.getHeader("req")).is(new HamcrestCondition<>(is("str2")));
assertThat(takeRequest.getHeader("opt")).isEqualTo("");
assertThat(takeRequest.getHeader("req")).isEqualTo("str2");
}

@Test
public void testEmptyStringHeader() throws Exception {
proxy.header(Optional.of(""), "str2");
RecordedRequest takeRequest = server.takeRequest();
assertThat(takeRequest.getHeader("opt")).is(new HamcrestCondition<>(is("")));
assertThat(takeRequest.getHeader("req")).is(new HamcrestCondition<>(is("str2")));
assertThat(takeRequest.getHeader("opt")).isEqualTo("");
assertThat(takeRequest.getHeader("req")).isEqualTo("str2");
}

@Test
public void testStringHeader() throws Exception {
proxy.header(Optional.of("str"), "str2");
RecordedRequest takeRequest = server.takeRequest();
assertThat(takeRequest.getHeader("opt")).is(new HamcrestCondition<>(is("str")));
assertThat(takeRequest.getHeader("req")).is(new HamcrestCondition<>(is("str2")));
assertThat(takeRequest.getHeader("opt")).isEqualTo("str");
assertThat(takeRequest.getHeader("req")).isEqualTo("str2");
}

@Ignore("TODO(rfink): Add support for header encoding")
@Test
public void testStringHeader_withNonAsciiCharacters() throws Exception {
proxy.header(Optional.of("ü"), "ø");
RecordedRequest takeRequest = server.takeRequest();
assertThat(takeRequest.getHeader("opt")).is(new HamcrestCondition<>(is("ü")));
assertThat(takeRequest.getHeader("req")).is(new HamcrestCondition<>(is("ø")));
assertThat(takeRequest.getHeader("opt")).isEqualTo("ü");
assertThat(takeRequest.getHeader("req")).isEqualTo("ø");
}

@Test
public void testAbsentIntQuery() throws Exception {
proxy.queryInt(OptionalInt.empty(), "str2");
RecordedRequest takeRequest = server.takeRequest();
assertThat(takeRequest.getRequestLine()).is(new HamcrestCondition<>(is("GET /foo/int?req=str2 HTTP/1.1")));
assertThat(takeRequest.getRequestLine()).isEqualTo("GET /foo/int?req=str2 HTTP/1.1");
}

@Test
Expand All @@ -197,23 +195,23 @@ public void testIntQuery() throws Exception {
public void testAbsentIntHeader() throws Exception {
proxy.headerInt(OptionalInt.empty(), "str2");
RecordedRequest takeRequest = server.takeRequest();
assertThat(takeRequest.getHeader("opt")).is(new HamcrestCondition<>(is("")));
assertThat(takeRequest.getHeader("req")).is(new HamcrestCondition<>(is("str2")));
assertThat(takeRequest.getHeader("opt")).isEqualTo("");
assertThat(takeRequest.getHeader("req")).isEqualTo("str2");
}

@Test
public void testIntHeader() throws Exception {
proxy.headerInt(OptionalInt.of(1234), "str2");
RecordedRequest takeRequest = server.takeRequest();
assertThat(takeRequest.getHeader("opt")).is(new HamcrestCondition<>(is("1234")));
assertThat(takeRequest.getHeader("req")).is(new HamcrestCondition<>(is("str2")));
assertThat(takeRequest.getHeader("opt")).isEqualTo("1234");
assertThat(takeRequest.getHeader("req")).isEqualTo("str2");
}

@Test
public void testAbsentDoubleQuery() throws Exception {
proxy.queryDouble(OptionalDouble.empty(), "str2");
RecordedRequest takeRequest = server.takeRequest();
assertThat(takeRequest.getRequestLine()).is(new HamcrestCondition<>(is("GET /foo/double?req=str2 HTTP/1.1")));
assertThat(takeRequest.getRequestLine()).isEqualTo("GET /foo/double?req=str2 HTTP/1.1");
}

@Test
Expand All @@ -227,23 +225,23 @@ public void testDoubleQuery() throws Exception {
public void testAbsentDoubleHeader() throws Exception {
proxy.headerDouble(OptionalDouble.empty(), "str2");
RecordedRequest takeRequest = server.takeRequest();
assertThat(takeRequest.getHeader("opt")).is(new HamcrestCondition<>(is("")));
assertThat(takeRequest.getHeader("req")).is(new HamcrestCondition<>(is("str2")));
assertThat(takeRequest.getHeader("opt")).isEqualTo("");
assertThat(takeRequest.getHeader("req")).isEqualTo("str2");
}

@Test
public void testDoubleHeader() throws Exception {
proxy.headerDouble(OptionalDouble.of(1234.567), "str2");
RecordedRequest takeRequest = server.takeRequest();
assertThat(takeRequest.getHeader("opt")).is(new HamcrestCondition<>(is("1234.567")));
assertThat(takeRequest.getHeader("req")).is(new HamcrestCondition<>(is("str2")));
assertThat(takeRequest.getHeader("opt")).isEqualTo("1234.567");
assertThat(takeRequest.getHeader("req")).isEqualTo("str2");
}

@Test
public void testAbsentLongQuery() throws Exception {
proxy.queryLong(OptionalLong.empty(), "str2");
RecordedRequest takeRequest = server.takeRequest();
assertThat(takeRequest.getRequestLine()).is(new HamcrestCondition<>(is("GET /foo/long?req=str2 HTTP/1.1")));
assertThat(takeRequest.getRequestLine()).isEqualTo("GET /foo/long?req=str2 HTTP/1.1");
}

@Test
Expand All @@ -257,16 +255,16 @@ public void testLongQuery() throws Exception {
public void testAbsentLongHeader() throws Exception {
proxy.headerLong(OptionalLong.empty(), "str2");
RecordedRequest takeRequest = server.takeRequest();
assertThat(takeRequest.getHeader("opt")).is(new HamcrestCondition<>(is("")));
assertThat(takeRequest.getHeader("req")).is(new HamcrestCondition<>(is("str2")));
assertThat(takeRequest.getHeader("opt")).isEqualTo("");
assertThat(takeRequest.getHeader("req")).isEqualTo("str2");
}

@Test
public void testLongHeader() throws Exception {
proxy.headerLong(OptionalLong.of(12345678901234L), "str2");
RecordedRequest takeRequest = server.takeRequest();
assertThat(takeRequest.getHeader("opt")).is(new HamcrestCondition<>(is("12345678901234")));
assertThat(takeRequest.getHeader("req")).is(new HamcrestCondition<>(is("str2")));
assertThat(takeRequest.getHeader("opt")).isEqualTo("12345678901234");
assertThat(takeRequest.getHeader("req")).isEqualTo("str2");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
package com.palantir.conjure.java.client.jaxrs;

import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.is;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
Expand Down Expand Up @@ -46,7 +44,6 @@
import okhttp3.mockwebserver.MockWebServer;
import okhttp3.mockwebserver.RecordedRequest;
import org.assertj.core.api.Assertions;
import org.assertj.core.api.HamcrestCondition;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
Expand Down Expand Up @@ -80,13 +77,13 @@ public void testClientIsInstrumentedWithTracer() throws InterruptedException {
service.param("somevalue");

Tracer.unsubscribe(TracerTest.class.getName());
assertThat(observedSpans).is(new HamcrestCondition<>(containsInAnyOrder(
assertThat(observedSpans).containsExactlyInAnyOrder(
Maps.immutableEntry(SpanType.LOCAL, "OkHttp: GET /{param}"),
Maps.immutableEntry(SpanType.LOCAL, "OkHttp: attempt 0"),
Maps.immutableEntry(SpanType.LOCAL, "OkHttp: client-side-concurrency-limiter 0/10"),
Maps.immutableEntry(SpanType.LOCAL, "OkHttp: dispatcher"),
Maps.immutableEntry(SpanType.CLIENT_OUTGOING, "OkHttp: wait-for-headers"),
Maps.immutableEntry(SpanType.CLIENT_OUTGOING, "OkHttp: wait-for-body"))));
Maps.immutableEntry(SpanType.CLIENT_OUTGOING, "OkHttp: wait-for-body"));

RecordedRequest request = server.takeRequest();
assertThat(request.getHeader(TraceHttpHeaders.TRACE_ID)).isEqualTo(traceId);
Expand Down Expand Up @@ -179,7 +176,7 @@ private void reduceConcurrencyLimitTo1() {
server.enqueue(new MockResponse().setResponseCode(429));
});
server.enqueue(new MockResponse().setBody("\"server\""));
assertThat(service.string()).is(new HamcrestCondition<>(is("server")));
assertThat(service.string()).isEqualTo("server");
}
}
}
Loading

0 comments on commit 8381ea9

Please sign in to comment.