Skip to content

Commit

Permalink
Addressed review comments.
Browse files Browse the repository at this point in the history
1. Remove RESPONSE_STREAMING_REQUEST_OPTIONS static variable.
2. Remove unused factory methods.
3. Replace checkState method with junit5 Assertions API
  • Loading branch information
tomatophobia committed Apr 3, 2023
1 parent adb9e6b commit e69f7b7
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 399 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.linecorp.armeria.client.HttpClient;
import com.linecorp.armeria.client.RequestOptions;
import com.linecorp.armeria.client.endpoint.EndpointGroup;
import com.linecorp.armeria.common.ExchangeType;
import com.linecorp.armeria.common.HttpRequest;
import com.linecorp.armeria.common.Scheme;

Expand All @@ -34,11 +33,6 @@ final class DefaultWebTestClient implements WebTestClient {

static final WebTestClient DEFAULT = new DefaultWebTestClient(BlockingWebClient.of());

static final RequestOptions RESPONSE_STREAMING_REQUEST_OPTIONS =
RequestOptions.builder()
.exchangeType(ExchangeType.RESPONSE_STREAMING)
.build();

private final BlockingWebClient delegate;

DefaultWebTestClient(BlockingWebClient delegate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

package com.linecorp.armeria.testing.junit5.client;

import static com.google.common.base.Preconditions.checkState;
import static java.util.Objects.requireNonNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.nio.charset.Charset;
import java.util.Arrays;

import com.linecorp.armeria.common.HttpData;

Expand All @@ -34,94 +34,91 @@ public final class HttpDataAssert extends AssertThat<HttpData, TestHttpResponse>

public TestHttpResponse isEqualTo(HttpData expected) {
requireNonNull(expected, "expected");
checkState(actual().equals(expected), "\nexpected: %s\n but was: %s", expected, actual());
assertEquals(expected, actual());
return back();
}

public TestHttpResponse isEmpty() {
checkState(actual().equals(HttpData.empty()), "\nExpecting empty but was not");
assertTrue(actual().isEmpty());
return back();
}

public TestHttpResponse arrayContains(byte... expected) {
requireNonNull(expected, "expected");
checkState(bytesContains(actual().array(), expected), "\nExpecting to contain %s but was not", Arrays.toString(expected));
assertTrue(bytesContains(actual().array(), expected));
return back();
}

public TestHttpResponse arrayContains(Byte[] expected) {
requireNonNull(expected, "expected");
checkState(bytesContains(actual().array(), toPrimitiveByteArray(expected)), "\nExpecting to contain %s but was not", Arrays.toString(expected));
assertTrue(bytesContains(actual().array(), toPrimitiveByteArray(expected)));
return back();
}

public TestHttpResponse arrayContains(int... expected) {
requireNonNull(expected, "expected");
checkState(bytesContains(actual().array(), toByteArray(expected)), "\nExpecting to contain %s but was not", Arrays.toString(expected));
assertTrue(bytesContains(actual().array(), toByteArray(expected)));
return back();
}

public TestHttpResponse arrayContainsExactly(byte... expected) {
requireNonNull(expected, "expected");
checkState(bytesContainsExactly(actual().array(), expected), "\nExpecting to contain %s but was not", Arrays.toString(expected));
assertTrue(bytesContainsExactly(actual().array(), expected));
return back();
}

public TestHttpResponse arrayContainsExactly(Byte[] expected) {
requireNonNull(expected, "expected");
checkState(bytesContainsExactly(actual().array(), toPrimitiveByteArray(expected)), "\nExpecting to contain %s but was not", Arrays.toString(expected));
assertTrue(bytesContainsExactly(actual().array(), toPrimitiveByteArray(expected)));
return back();
}

public TestHttpResponse arrayContainsExactly(int... expected) {
requireNonNull(expected, "expected");
checkState(bytesContainsExactly(actual().array(), toByteArray(expected)), "\nExpecting to contain %s but was not", Arrays.toString(expected));
assertTrue(bytesContainsExactly(actual().array(), toByteArray(expected)));
return back();
}

public TestHttpResponse lengthIsEqualTo(int expected) {
checkState(actual().length() == expected, "\nexpected: %s\n but was: %s", expected, actual().length());
assertEquals(expected, actual().length());
return back();
}

public TestHttpResponse stringIsEqualTo(Charset charset, String expected) {
requireNonNull(charset, "charset");
requireNonNull(expected, "expected");
checkState(actual().toString(charset).equals(expected), "\nexpected: %s\n but was: %s", expected,
actual().toString(charset));
assertEquals(expected, actual().toString(charset));
return back();
}

public TestHttpResponse stringUtf8IsEqualTo(String expected) {
requireNonNull(expected, "expected");
checkState(actual().toStringUtf8().equals(expected), "\nexpected: %s\n but was: %s", expected,
actual().toStringUtf8());
assertEquals(expected, actual().toStringUtf8());
return back();
}

public TestHttpResponse stringAsciiIsEqualTo(String expected) {
requireNonNull(expected, "expected");
checkState(actual().toStringAscii().equals(expected), "\nexpected: %s\n but was: %s", expected,
actual().toStringAscii());
assertEquals(expected, actual().toStringAscii());
return back();
}

public TestHttpResponse stringContains(Charset charset, String expected) {
requireNonNull(charset, "charset");
requireNonNull(expected, "expected");
checkState(actual().toString(charset).contains(expected), "\nExpecting to contain %s but was not", expected);
assertTrue(actual().toString(charset).contains(expected));
return back();
}

public TestHttpResponse stringUtf8Contains(String expected) {
requireNonNull(expected, "expected");
checkState(actual().toStringUtf8().contains(expected), "\nExpecting to contain %s but was not", expected);
assertTrue(actual().toStringUtf8().contains(expected));
return back();
}

public TestHttpResponse stringAsciiContains(String expected) {
requireNonNull(expected, "expected");
checkState(actual().toStringAscii().contains(expected), "\nExpecting to contain %s but was not", expected);
assertTrue(actual().toStringAscii().contains(expected));
return back();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@

package com.linecorp.armeria.testing.junit5.client;

import static com.google.common.base.Preconditions.checkState;
import static java.util.Objects.requireNonNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.linecorp.armeria.common.ContentDisposition;
import com.linecorp.armeria.common.HttpHeaders;
Expand All @@ -35,112 +37,102 @@ public final class HttpHeadersAssert extends AssertThat<HttpHeaders, TestHttpRes

public TestHttpResponse isEqualTo(HttpHeaders expected) {
requireNonNull(expected, "expected");
checkState(actual().equals(expected), "\nexpected: %s\n but was: %s", expected, actual());
assertEquals(expected, actual());
return back();
}

public TestHttpResponse contentLengthIsEqualTo(long expected) {
checkState(actual().contentLength() == expected, "\nexpected: %s\n but was: %s", expected,
actual().contentLength());
assertEquals(expected, actual().contentLength());
return back();
}

public TestHttpResponse contentTypeIsEqualTo(MediaType expected) {
requireNonNull(expected, "expected");
checkState(actual().contentType().equals(expected), "\nexpected: %s\n but was: %s", expected,
actual().contentType());
assertEquals(expected, actual().contentType());
return back();
}

public TestHttpResponse contentDispositionIsEqualTo(ContentDisposition expected) {
requireNonNull(expected, "expected");
checkState(actual().contentDisposition().equals(expected), "\nexpected: %s\n but was: %s", expected,
actual().contentDisposition());
assertEquals(expected, actual().contentDisposition());
return back();
}

public TestHttpResponse contains(CharSequence name) {
requireNonNull(name, "name");
checkState(actual().contains(name), "\nExpecting to contain %s but was not", name);
assertTrue(actual().contains(name));
return back();
}

public TestHttpResponse contains(CharSequence name, String value) {
requireNonNull(name, "name");
requireNonNull(value, "value");
checkState(actual().contains(name, value), "\nExpecting to contain %s: %s but was not", name, value);
assertTrue(actual().contains(name, value));
return back();
}

public TestHttpResponse containsObject(CharSequence name, Object value) {
requireNonNull(name, "name");
requireNonNull(value, "value");
checkState(actual().containsObject(name, value), "\nExpecting to contain %s: %s but was not", name,
value);
assertTrue(actual().containsObject(name, value));
return back();
}

public TestHttpResponse containsBoolean(CharSequence name, boolean value) {
requireNonNull(name, "name");
checkState(actual().containsBoolean(name, value), "\nExpecting to contain %s: %s but was not", name,
value);
assertTrue(actual().containsBoolean(name, value));
return back();
}

public TestHttpResponse containsInt(CharSequence name, int value) {
requireNonNull(name, "name");
checkState(actual().containsInt(name, value), "\nExpecting to contain %s: %s but was not", name, value);
assertTrue(actual().containsInt(name, value));
return back();
}

public TestHttpResponse containsLong(CharSequence name, long value) {
requireNonNull(name, "name");
checkState(actual().containsLong(name, value), "\nExpecting to contain %s: %s but was not", name,
value);
assertTrue(actual().containsLong(name, value));
return back();
}

public TestHttpResponse containsFloat(CharSequence name, float value) {
requireNonNull(name, "name");
checkState(actual().containsFloat(name, value), "\nExpecting to contain %s: %s but was not", name,
value);
assertTrue(actual().containsFloat(name, value));
return back();
}

public TestHttpResponse containsDouble(CharSequence name, double value) {
requireNonNull(name, "name");
checkState(actual().containsDouble(name, value), "\nExpecting to contain %s: %s but was not", name,
value);
assertTrue(actual().containsDouble(name, value));
return back();
}

public TestHttpResponse containsTimeMillis(CharSequence name, long value) {
requireNonNull(name, "name");
checkState(actual().containsTimeMillis(name, value), "\nExpecting to contain %s: %s but was not", name,
value);
assertTrue(actual().containsTimeMillis(name, value));
return back();
}

public TestHttpResponse sizeIsEqualTo(int expected) {
checkState(actual().size() == expected, "\nexpected: %s\n but was: %s", expected, actual().size());
assertEquals(expected, actual().size());
return back();
}

public TestHttpResponse isEmpty() {
checkState(actual().isEmpty(), "\nExpecting empty but was not");
assertTrue(actual().isEmpty());
return back();
}

public TestHttpResponse namesContains(AsciiString expected) {
requireNonNull(expected, "expected");
checkState(actual().names().contains(expected), "\nExpecting to contain %s but was not", expected);
assertTrue(actual().names().contains(expected));
return back();
}

public TestHttpResponse namesDoesNotContains(AsciiString expected) {
requireNonNull(expected, "expected");
checkState(!actual().names().contains(expected), "\nExpecting to not contain %s but was",
expected);
assertFalse(actual().names().contains(expected));
return back();
}
}

0 comments on commit e69f7b7

Please sign in to comment.