Skip to content

Commit

Permalink
mobile: Switch to Truth from AssertJ (envoyproxy#32305)
Browse files Browse the repository at this point in the history
Signed-off-by: Fredy Wijaya <[email protected]>
  • Loading branch information
fredyw authored Feb 9, 2024
1 parent 6967e17 commit 610afbf
Show file tree
Hide file tree
Showing 55 changed files with 195 additions and 200 deletions.
3 changes: 1 addition & 2 deletions mobile/bazel/envoy_mobile_dependencies.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def kotlin_dependencies(extra_maven_dependencies = []):
"org.jetbrains.dokka:dokka-cli:1.5.31",
"org.jetbrains.dokka:javadoc-plugin:1.5.31",
# Test artifacts
"org.assertj:assertj-core:3.23.1",
"com.google.truth:truth:1.4.0",
"junit:junit:4.13",
"org.mockito:mockito-inline:4.8.0",
"org.mockito:mockito-core:4.8.0",
Expand All @@ -88,7 +88,6 @@ def kotlin_dependencies(extra_maven_dependencies = []):
"androidx.test.ext:junit:1.1.3",
"org.robolectric:robolectric:4.8.2",
"org.hamcrest:hamcrest:2.2",
"com.google.truth:truth:1.1.3",
] + extra_maven_dependencies,
version_conflict_policy = "pinned",
repositories = [
Expand Down
3 changes: 1 addition & 2 deletions mobile/bazel/kotlin_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def _internal_kt_test(name, srcs, deps = [], data = [], jvm_flags = [], reposito
srcs = srcs + dep_srcs,
deps = [
repository + "//bazel:envoy_mobile_test_suite",
"@maven//:org_assertj_assertj_core",
"@maven//:com_google_truth_truth",
"@maven//:junit_junit",
"@maven//:org_mockito_mockito_inline",
"@maven//:org_mockito_mockito_core",
Expand Down Expand Up @@ -102,7 +102,6 @@ def envoy_mobile_android_test(name, srcs, native_lib_name, deps = [], native_dep
"@maven//:androidx_test_rules",
"@maven//:org_robolectric_robolectric",
"@robolectric//bazel:android-all",
"@maven//:org_assertj_assertj_core",
"@maven//:junit_junit",
"@maven//:org_mockito_mockito_inline",
"@maven//:org_mockito_mockito_core",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import io.envoyproxy.envoymobile.engine.types.EnvoyStringAccessor
/**
* Mock implementation of `EnvoyEngine`. Used internally for testing the bridging layer & mocking.
*/
internal class MockEnvoyEngine : EnvoyEngine {
class MockEnvoyEngine : EnvoyEngine {
override fun runWithConfig(
envoyConfiguration: EnvoyConfiguration?,
logLevel: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ import java.nio.ByteBuffer
*
* @param callbacks Callbacks associated with the stream.
*/
internal class MockEnvoyHTTPStream(
val callbacks: EnvoyHTTPCallbacks,
val explicitFlowControl: Boolean
) : EnvoyHTTPStream(0, 0, callbacks, explicitFlowControl) {
class MockEnvoyHTTPStream(val callbacks: EnvoyHTTPCallbacks, val explicitFlowControl: Boolean) :
EnvoyHTTPStream(0, 0, callbacks, explicitFlowControl) {
override fun sendHeaders(headers: MutableMap<String, MutableList<String>>?, endStream: Boolean) {}

override fun sendData(data: ByteBuffer?, endStream: Boolean) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import java.nio.ByteBuffer
* Mock implementation of `Stream` that also provides an interface for sending mocked responses
* through to the stream's callbacks. Created via `MockStreamPrototype`.
*/
class MockStream internal constructor(underlyingStream: MockEnvoyHTTPStream) :
class MockStream(underlyingStream: MockEnvoyHTTPStream) :
Stream(underlyingStream, useByteBufferPosition = false) {
private val mockStream: MockEnvoyHTTPStream = underlyingStream

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import java.util.concurrent.Executor
*
* @param onStart Closure that will be called each time a new stream is started from the prototype.
*/
class MockStreamPrototype
internal constructor(private val onStart: ((stream: MockStream) -> Unit)?) :
class MockStreamPrototype(private val onStart: ((stream: MockStream) -> Unit)?) :
StreamPrototype(MockEnvoyEngine()) {
override fun start(executor: Executor): Stream {
val callbacks = createCallbacks(executor)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package test.kotlin.integration;

import static org.assertj.core.api.Assertions.assertThat;
import static com.google.common.truth.Truth.assertThat;

import android.content.Context;
import androidx.test.core.app.ApplicationProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;

import static org.assertj.core.api.Assertions.assertThat;
import static com.google.common.truth.Truth.assertThat;

// NOLINT(namespace-envoy)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package test.kotlin.integration;

import static org.assertj.core.api.Assertions.assertThat;
import static com.google.common.truth.Truth.assertThat;

import android.content.Context;
import androidx.test.core.app.ApplicationProvider;
Expand Down Expand Up @@ -204,7 +204,7 @@ public void get_noBody() throws Exception {
assertThat(response.getHeaders().getHttpStatus()).isEqualTo(200);
assertThat(response.getBodyAsString()).isEmpty();
assertThat(response.getEnvoyError()).isNull();
assertThat(response.getNbResponseChunks()).isZero();
assertThat(response.getNbResponseChunks()).isEqualTo(0);
}

@Test
Expand Down Expand Up @@ -400,7 +400,7 @@ public void post_cancelUploadOnChunkZero() throws Exception {
Response response = sendRequest(requestScenario);

assertThat(response.isCancelled()).isTrue();
assertThat(response.getRequestChunkSent()).isZero();
assertThat(response.getRequestChunkSent()).isEqualTo(0);
assertThat(response.getEnvoyError()).isNull();
}

Expand All @@ -416,7 +416,7 @@ public void post_cancelUploadOnChunkOne() throws Exception {
Response response = sendRequest(requestScenario);

assertThat(response.isCancelled()).isTrue();
assertThat(response.getRequestChunkSent()).isOne();
assertThat(response.getRequestChunkSent()).isEqualTo(1);
assertThat(response.getEnvoyError()).isNull();
}

Expand Down
4 changes: 2 additions & 2 deletions mobile/test/java/integration/AndroidEnvoyFlowTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package test.kotlin.integration;

import static org.assertj.core.api.Assertions.assertThat;
import static com.google.common.truth.Truth.assertThat;

import android.content.Context;
import androidx.test.core.app.ApplicationProvider;
Expand Down Expand Up @@ -101,7 +101,7 @@ public void get_noBody() throws Exception {
assertThat(response.getHeaders().getHttpStatus()).isEqualTo(200);
assertThat(response.getBodyAsString()).isEmpty();
assertThat(response.getEnvoyError()).isNull();
assertThat(response.getNbResponseChunks()).isZero();
assertThat(response.getNbResponseChunks()).isEqualTo(0);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import io.envoyproxy.envoymobile.engine.types.EnvoyFinalStreamIntel
import io.envoyproxy.envoymobile.engine.types.EnvoyHTTPFilterCallbacks
import io.envoyproxy.envoymobile.engine.testing.TestJni
import java.nio.ByteBuffer
import org.assertj.core.api.Assertions.assertThat
import com.google.common.truth.Truth.assertThat
import org.junit.Test
import java.util.regex.Pattern

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package io.envoyproxy.envoymobile.engine

import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
import org.assertj.core.api.Assertions.assertThat
import com.google.common.truth.Truth.assertThat
import org.junit.Test

class EnvoyNativeResourceRegistryTest {

@Test
fun `release callbacks are invoked when EnvoyNativeResourceWrappers are flagged as unreachable`() {
val latch = CountDownLatch(1)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package io.envoyproxy.envoymobile.engine

import org.assertj.core.api.Assertions.assertThat
import com.google.common.truth.Truth.assertThat
import org.junit.Test

class JvmBridgeUtilityTest {

@Test
fun `retrieveHeaders produces a Map with all headers provided via passHeaders`() {
val utility = JvmBridgeUtility()
Expand All @@ -18,9 +17,7 @@ class JvmBridgeUtilityTest {
"test-1" to listOf("value-1", "value-2")
)

assertThat(headers)
.hasSize(2) // Two keys / header name
.usingRecursiveComparison().isEqualTo(expectedHeaders)
assertThat(headers).isEqualTo(expectedHeaders)
}

@Test
Expand Down Expand Up @@ -58,9 +55,7 @@ class JvmBridgeUtilityTest {
"test-2" to listOf("value-3")
)

assertThat(nextHeaders)
.hasSize(1) // One key / header name
.usingRecursiveComparison().isEqualTo(expectedHeaders)
assertThat(nextHeaders).isEqualTo(expectedHeaders)
}

@Test(expected = AssertionError::class)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.envoyproxy.envoymobile.engine.testing;

import static org.assertj.core.api.Assertions.assertThat;
import static com.google.common.truth.Truth.assertThat;

import android.content.Context;
import androidx.test.core.app.ApplicationProvider;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.envoyproxy.envoymobile.jni;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertThrows;

import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -143,9 +143,9 @@ public void testNewObject() {

@Test
public void testThrowNew() {
assertThatThrownBy(() -> throwNew("java/lang/RuntimeException", "Test"))
.isInstanceOf(RuntimeException.class)
.hasMessageContaining("Test");
RuntimeException exception =
assertThrows(RuntimeException.class, () -> throwNew("java/lang/RuntimeException", "Test"));
assertThat(exception).hasMessageThat().contains("Test");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.envoyproxy.envoymobile.jni;

import static org.assertj.core.api.Assertions.assertThat;
import static com.google.common.truth.Truth.assertThat;

import com.google.protobuf.Struct;
import com.google.protobuf.Value;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.chromium.net.impl;

import static org.assertj.core.api.Assertions.assertThat;
import static com.google.common.truth.Truth.assertThat;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down
Loading

0 comments on commit 610afbf

Please sign in to comment.