From 65d1bfc47191414c6daf07749b1b0f790e757fce Mon Sep 17 00:00:00 2001 From: Deepu Ganapathiyadan Date: Mon, 6 Jan 2020 11:57:47 -0800 Subject: [PATCH] Move RequestHandle test cases to separate class --- .../bridge/RequestHandleTests.java | 108 ++++++++++++++++++ .../bridge/RequestProcessorTest.java | 91 --------------- 2 files changed, 108 insertions(+), 91 deletions(-) create mode 100644 android/electrode-reactnative-bridge/src/androidTest/java/com/walmartlabs/electrode/reactnative/bridge/RequestHandleTests.java diff --git a/android/electrode-reactnative-bridge/src/androidTest/java/com/walmartlabs/electrode/reactnative/bridge/RequestHandleTests.java b/android/electrode-reactnative-bridge/src/androidTest/java/com/walmartlabs/electrode/reactnative/bridge/RequestHandleTests.java new file mode 100644 index 00000000..d94f33bd --- /dev/null +++ b/android/electrode-reactnative-bridge/src/androidTest/java/com/walmartlabs/electrode/reactnative/bridge/RequestHandleTests.java @@ -0,0 +1,108 @@ +package com.walmartlabs.electrode.reactnative.bridge; + +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; + +import com.walmartlabs.electrode.reactnative.sample.api.PersonApi; + +import org.junit.Test; + +import java.util.concurrent.CountDownLatch; + +import static junit.framework.TestCase.assertEquals; +import static junit.framework.TestCase.assertNotNull; +import static junit.framework.TestCase.assertSame; +import static junit.framework.TestCase.fail; + +public class RequestHandleTests extends BaseBridgeTestCase { + + @Test + public void testRequestHandlerRemoval() { + final CountDownLatch countDownLatch = new CountDownLatch(3); + final String requestName = "testRequestHandlerRemoval"; + + RequestHandlerHandle requestHandle = new RequestHandlerProcessor<>(requestName, None.class, None.class, new ElectrodeBridgeRequestHandler() { + @Override + public void onRequest(@Nullable None payload, @NonNull ElectrodeBridgeResponseListener responseListener) { + assertSame(None.NONE, payload); + responseListener.onSuccess(null); + countDownLatch.countDown(); + } + }).execute(); + + + new RequestProcessor(requestName, null, None.class, new ElectrodeBridgeResponseListener() { + @Override + public void onFailure(@NonNull FailureMessage failureMessage) { + fail(); + } + + @Override + public void onSuccess(@Nullable None responseData) { + assertSame(None.NONE, responseData); + countDownLatch.countDown(); + } + }).execute(); + + requestHandle.unregister(); + + new RequestProcessor(requestName, null, None.class, new ElectrodeBridgeResponseListener() { + @Override + public void onFailure(@NonNull FailureMessage failureMessage) { + failureMessage.getMessage(); + countDownLatch.countDown(); + } + + @Override + public void onSuccess(@Nullable None responseData) { + fail(); + } + }).execute(); + + waitForCountDownToFinishOrFail(countDownLatch); + } + + @Test + public void testRequestHandlerRemovalWithApi() { + final CountDownLatch countDownLatch = new CountDownLatch(3); + final int RESULT_AGE = 10; + + RequestHandlerHandle handlerHandle = PersonApi.requests().registerGetAgeRequestHandler(new ElectrodeBridgeRequestHandler() { + @Override + public void onRequest(@Nullable String payload, @NonNull ElectrodeBridgeResponseListener responseListener) { + responseListener.onSuccess(RESULT_AGE); + countDownLatch.countDown(); + } + }); + + PersonApi.requests().getAge("user", new ElectrodeBridgeResponseListener() { + @Override + public void onSuccess(@Nullable Integer responseData) { + assertNotNull(responseData); + assertEquals(RESULT_AGE, responseData.intValue()); + countDownLatch.countDown(); + } + + @Override + public void onFailure(@NonNull FailureMessage failureMessage) { + fail(); + } + }); + + handlerHandle.unregister(); + + PersonApi.requests().getAge("user", new ElectrodeBridgeResponseListener() { + @Override + public void onSuccess(@Nullable Integer responseData) { + fail(); + } + + @Override + public void onFailure(@NonNull FailureMessage failureMessage) { + assertNotNull(failureMessage); + countDownLatch.countDown(); + } + }); + waitForCountDownToFinishOrFail(countDownLatch); + } +} diff --git a/android/electrode-reactnative-bridge/src/androidTest/java/com/walmartlabs/electrode/reactnative/bridge/RequestProcessorTest.java b/android/electrode-reactnative-bridge/src/androidTest/java/com/walmartlabs/electrode/reactnative/bridge/RequestProcessorTest.java index eab393f1..0516a58e 100644 --- a/android/electrode-reactnative-bridge/src/androidTest/java/com/walmartlabs/electrode/reactnative/bridge/RequestProcessorTest.java +++ b/android/electrode-reactnative-bridge/src/androidTest/java/com/walmartlabs/electrode/reactnative/bridge/RequestProcessorTest.java @@ -1195,95 +1195,4 @@ public void onResponse(ReadableMap response) { waitForCountDownToFinishOrFail(countDownLatch); } - - @Test - public void testRequestHandlerRemoval() { - final CountDownLatch countDownLatch = new CountDownLatch(3); - final String requestName = "testRequestHandlerRemoval"; - - RequestHandlerHandle requestHandle = new RequestHandlerProcessor<>(requestName, None.class, None.class, new ElectrodeBridgeRequestHandler() { - @Override - public void onRequest(@Nullable None payload, @NonNull ElectrodeBridgeResponseListener responseListener) { - assertSame(None.NONE, payload); - responseListener.onSuccess(null); - countDownLatch.countDown(); - } - }).execute(); - - - new RequestProcessor(requestName, null, None.class, new ElectrodeBridgeResponseListener() { - @Override - public void onFailure(@NonNull FailureMessage failureMessage) { - fail(); - } - - @Override - public void onSuccess(@Nullable None responseData) { - assertSame(None.NONE, responseData); - countDownLatch.countDown(); - } - }).execute(); - - requestHandle.unregister(); - - new RequestProcessor(requestName, null, None.class, new ElectrodeBridgeResponseListener() { - @Override - public void onFailure(@NonNull FailureMessage failureMessage) { - failureMessage.getMessage(); - countDownLatch.countDown(); - } - - @Override - public void onSuccess(@Nullable None responseData) { - fail(); - } - }).execute(); - - waitForCountDownToFinishOrFail(countDownLatch); - } - - @Test - public void testRequestHandlerRemovalWithApi() { - final CountDownLatch countDownLatch = new CountDownLatch(3); - final int RESULT_AGE = 10; - - RequestHandlerHandle handlerHandle = PersonApi.requests().registerGetAgeRequestHandler(new ElectrodeBridgeRequestHandler() { - @Override - public void onRequest(@Nullable String payload, @NonNull ElectrodeBridgeResponseListener responseListener) { - responseListener.onSuccess(RESULT_AGE); - countDownLatch.countDown(); - } - }); - - PersonApi.requests().getAge("user", new ElectrodeBridgeResponseListener() { - @Override - public void onSuccess(@Nullable Integer responseData) { - assertNotNull(responseData); - assertEquals(RESULT_AGE, responseData.intValue()); - countDownLatch.countDown(); - } - - @Override - public void onFailure(@NonNull FailureMessage failureMessage) { - fail(); - } - }); - - handlerHandle.unregister(); - - PersonApi.requests().getAge("user", new ElectrodeBridgeResponseListener() { - @Override - public void onSuccess(@Nullable Integer responseData) { - fail(); - } - - @Override - public void onFailure(@NonNull FailureMessage failureMessage) { - assertNotNull(failureMessage); - countDownLatch.countDown(); - } - }); - waitForCountDownToFinishOrFail(countDownLatch); - } - }