Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions receipt/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ dependencies {
implementation "androidx.paging:paging-runtime:$pagingRuntimeVersion"

testImplementation "org.robolectric:robolectric:$robolectricVersion"

androidTestImplementation "androidx.test:rules:$testRulesVersion"
androidTestImplementation "androidx.test.espresso:espresso-contrib:$espressoVersion"
androidTestImplementation "androidx.test.espresso:espresso-intents:$espressoVersion"
androidTestImplementation "com.squareup.okhttp3:mockwebserver:$mockServerVersion"
androidTestImplementation "com.squareup.leakcanary:leakcanary-android-instrumentation:$leakcanaryVersion"
androidTestImplementation "com.squareup.leakcanary:leakcanary-support-fragment:$leakcanaryVersion"
}

def aarFile = file("$buildDir/outputs/aar/receipt-$version" + ".aar")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.hyperwallet.android.transfermethod.ui;
package com.hyperwallet.android.receipt;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
Expand Down Expand Up @@ -26,11 +26,10 @@
import androidx.test.rule.ActivityTestRule;

import com.hyperwallet.android.Hyperwallet;
import com.hyperwallet.android.hyperwallet_ui.R;
import com.hyperwallet.android.receipt.repository.ReceiptRepositoryFactory;
import com.hyperwallet.android.receipt.view.ListReceiptActivity;
import com.hyperwallet.android.rule.HyperwalletExternalResourceManager;
import com.hyperwallet.android.rule.HyperwalletMockWebServer;
import com.hyperwallet.android.ui.repository.RepositoryFactory;
import com.hyperwallet.android.util.RecyclerViewCountAssertion;
import com.hyperwallet.android.util.TestAuthenticationProvider;

Expand Down Expand Up @@ -60,12 +59,13 @@ public void setup() {

mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager
.getResourceContent("authentication_token_response.json")).mock();

setLocale(Locale.US);
}

@After
public void cleanup() {
RepositoryFactory.clearInstance();
ReceiptRepositoryFactory.clearInstance();
}

@Test
Expand All @@ -85,33 +85,44 @@ public void testListReceipts_userHasMultipleTransactions() {
.check(matches(atPosition(0, hasDescendant(withText("June 2019")))));
onView(withId(R.id.list_receipts)).check(matches(atPosition(0,
hasDescendant(withText(com.hyperwallet.android.receipt.R.string.credit)))));
onView(withId(R.id.list_receipts)).check(matches(atPosition(0, hasDescendant(withText("Payment")))));
onView(withId(R.id.list_receipts)).check(matches(atPosition(0, hasDescendant(withText("+ 20.00")))));
onView(withId(R.id.list_receipts)).check(matches(atPosition(0, hasDescendant(withText("June 07, 2019")))));
onView(withId(R.id.list_receipts)).check(
matches(atPosition(0, hasDescendant(withText("Payment")))));
onView(withId(R.id.list_receipts)).check(
matches(atPosition(0, hasDescendant(withText("+ 20.00")))));
onView(withId(R.id.list_receipts)).check(
matches(atPosition(0, hasDescendant(withText("June 07, 2019")))));
onView(withId(R.id.list_receipts)).check(matches(atPosition(0, hasDescendant(withText("USD")))));

onView(withId(R.id.list_receipts)).check(matches(atPosition(1,
hasDescendant(withText(com.hyperwallet.android.receipt.R.string.credit)))));
onView(withId(R.id.list_receipts)).check(matches(atPosition(1, hasDescendant(withText("Payment")))));
onView(withId(R.id.list_receipts)).check(matches(atPosition(1, hasDescendant(withText("+ 25.00")))));
onView(withId(R.id.list_receipts)).check(matches(atPosition(1, hasDescendant(withText("June 02, 2019")))));
onView(withId(R.id.list_receipts)).check(
matches(atPosition(1, hasDescendant(withText("Payment")))));
onView(withId(R.id.list_receipts)).check(
matches(atPosition(1, hasDescendant(withText("+ 25.00")))));
onView(withId(R.id.list_receipts)).check(
matches(atPosition(1, hasDescendant(withText("June 02, 2019")))));
onView(withId(R.id.list_receipts)).check(matches(atPosition(1, hasDescendant(withText("CAD")))));

onView(withId(R.id.list_receipts)).check(matches(atPosition(2,
hasDescendant(withText(com.hyperwallet.android.receipt.R.string.debit)))));
onView(withId(R.id.list_receipts)).check(
matches(atPosition(2, hasDescendant(withText("Card Activation Fee")))));
onView(withId(R.id.list_receipts)).check(matches(atPosition(2, hasDescendant(withText("- 1.95")))));
onView(withId(R.id.list_receipts)).check(matches(atPosition(2, hasDescendant(withText("June 01, 2019")))));
onView(withId(R.id.list_receipts)).check(
matches(atPosition(2, hasDescendant(withText("- 1.95")))));
onView(withId(R.id.list_receipts)).check(
matches(atPosition(2, hasDescendant(withText("June 01, 2019")))));
onView(withId(R.id.list_receipts)).check(matches(atPosition(2, hasDescendant(withText("USD")))));

onView(withId(R.id.list_receipts))
.check(matches(atPosition(3, hasDescendant(withText("December 2018")))));
onView(withId(R.id.list_receipts)).check(matches(atPosition(3,
hasDescendant(withText(com.hyperwallet.android.receipt.R.string.debit)))));
onView(withId(R.id.list_receipts)).check(matches(atPosition(3, hasDescendant(withText("Card Load")))));
onView(withId(R.id.list_receipts)).check(matches(atPosition(3, hasDescendant(withText("- 18.05")))));
onView(withId(R.id.list_receipts)).check(matches(atPosition(3, hasDescendant(withText("December 01, 2018")))));
onView(withId(R.id.list_receipts)).check(
matches(atPosition(3, hasDescendant(withText("Card Load")))));
onView(withId(R.id.list_receipts)).check(
matches(atPosition(3, hasDescendant(withText("- 18.05")))));
onView(withId(R.id.list_receipts)).check(
matches(atPosition(3, hasDescendant(withText("December 01, 2018")))));
onView(withId(R.id.list_receipts)).check(matches(atPosition(3, hasDescendant(withText("USD")))));

onView(withId(R.id.list_receipts)).check(new RecyclerViewCountAssertion(4));
Expand All @@ -134,9 +145,12 @@ public void testListReceipts_displayCreditTransaction() {
.check(matches(atPosition(0, hasDescendant(withText("June 2019")))));
onView(withId(R.id.list_receipts)).check(matches(atPosition(0,
hasDescendant(withText(com.hyperwallet.android.receipt.R.string.credit)))));
onView(withId(R.id.list_receipts)).check(matches(atPosition(0, hasDescendant(withText("Payment")))));
onView(withId(R.id.list_receipts)).check(matches(atPosition(0, hasDescendant(withText("+ 25.00")))));
onView(withId(R.id.list_receipts)).check(matches(atPosition(0, hasDescendant(withText("June 02, 2019")))));
onView(withId(R.id.list_receipts)).check(
matches(atPosition(0, hasDescendant(withText("Payment")))));
onView(withId(R.id.list_receipts)).check(
matches(atPosition(0, hasDescendant(withText("+ 25.00")))));
onView(withId(R.id.list_receipts)).check(
matches(atPosition(0, hasDescendant(withText("June 02, 2019")))));
onView(withId(R.id.list_receipts)).check(matches(atPosition(0, hasDescendant(withText("CAD")))));

onView(withId(R.id.list_receipts)).check(new RecyclerViewCountAssertion(1));
Expand All @@ -159,9 +173,12 @@ public void testListReceipts_displayDebitTransaction() {
.check(matches(atPosition(0, hasDescendant(withText("May 2019")))));
onView(withId(R.id.list_receipts)).check(matches(atPosition(0,
hasDescendant(withText(com.hyperwallet.android.receipt.R.string.debit)))));
onView(withId(R.id.list_receipts)).check(matches(atPosition(0, hasDescendant(withText("Card Load")))));
onView(withId(R.id.list_receipts)).check(matches(atPosition(0, hasDescendant(withText("- 18.05")))));
onView(withId(R.id.list_receipts)).check(matches(atPosition(0, hasDescendant(withText("May 02, 2019")))));
onView(withId(R.id.list_receipts)).check(
matches(atPosition(0, hasDescendant(withText("Card Load")))));
onView(withId(R.id.list_receipts)).check(
matches(atPosition(0, hasDescendant(withText("- 18.05")))));
onView(withId(R.id.list_receipts)).check(
matches(atPosition(0, hasDescendant(withText("May 02, 2019")))));
onView(withId(R.id.list_receipts)).check(matches(atPosition(0, hasDescendant(withText("USD")))));

onView(withId(R.id.list_receipts)).check(new RecyclerViewCountAssertion(1));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.hyperwallet.android.receipt.rule;
package com.hyperwallet.android.rule;

import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
Expand Down Expand Up @@ -35,6 +35,7 @@ public String getResourceContent(final String resourceName) {
}

private String getContent(final String resourceName) {

URL resource = classLoader.getResource(resourceName);
InputStream inputStream = null;
Writer writer = new StringWriter();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package com.hyperwallet.android.rule;

import org.junit.rules.TestWatcher;
import org.junit.runner.Description;

import java.io.IOException;
import java.net.HttpURLConnection;

import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;

public final class HyperwalletMockWebServer extends TestWatcher {

private MockWebServer mServer;
private int port;

public HyperwalletMockWebServer(int port) {
this.port = port;
}

@Override
protected void starting(Description description) {
super.starting(description);
mServer = new MockWebServer();
try {
mServer.start(port);
} catch (IOException e) {
throw new IllegalStateException("Unable to start mock server", e);
}
}

@Override
protected void finished(Description description) {
super.finished(description);
try {
mServer.shutdown();
mServer.close();
} catch (IOException e) {
throw new IllegalStateException("Un error occurred when shutting down mock server", e);
}
}

public HyperwalletMockResponse mockResponse() {
return new Builder(mServer).build();
}

public MockWebServer getServer() {
return mServer;
}

public static class HyperwalletMockResponse {

private String path;
private String body;
private int httpResponseCode;
private Builder builder;

HyperwalletMockResponse(Builder builder) {
this.path = builder.path;
this.httpResponseCode = builder.responseCode;
this.body = builder.body;
this.builder = builder;
}

public HyperwalletMockResponse withHttpResponseCode(final int code) {
builder.responseCode(code);
return builder.build();
}

public HyperwalletMockResponse withBody(final String body) {
builder.body(body);
return builder.build();
}

public void mock() {
mockRequest();
}

private String mockRequest() {
builder.server.enqueue(new MockResponse().setResponseCode(httpResponseCode).setBody(body));
return builder.server.url(path).toString();
}

}

private static class Builder {

private String path;
private String body;
private int responseCode;
private MockWebServer server;


Builder(final MockWebServer server) {
this.path = "";
this.responseCode = HttpURLConnection.HTTP_OK;
this.body = "";
this.server = server;
}

Builder responseCode(final int code) {
this.responseCode = code;
return this;
}

Builder body(final String body) {
this.body = body;
return this;
}

HyperwalletMockResponse build() {
return new HyperwalletMockResponse(this);
}
}
}
Loading