Skip to content

Commit

Permalink
VBM on Android - Initial Appium : Implemented fake network and passin…
Browse files Browse the repository at this point in the history
…g loadData for MainActivityBridge
  • Loading branch information
Fyzxs committed Jan 25, 2017
1 parent 8298547 commit eeb4ece
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 40 deletions.
@@ -1,19 +1,20 @@
package com.quantityandconversion.hackernews;

class MainActivityBridge {
// private final MainActivity mainActivity;
private final MainActivity mainActivity;

public MainActivityBridge(final MainActivity mainActivity) {
if(mainActivity == null) throw new IllegalArgumentException("mainActivity cannot be null");

// this.mainActivity = mainActivity;
this.mainActivity = mainActivity;
}

/* package */ void loadData() {
new MainActivityMediator(this).loadItemData();
}


/* package */ void loadedItemData() {

mainActivity.setTopStoryCount("value");
}
}
Expand Up @@ -24,7 +24,7 @@ public void onResponse(Call<Items> call, Response<Items> response) {

@Override
public void onFailure(Call<Items> call, Throwable t) {
throw new RuntimeException("This shouldn't happen");
throw new UnsupportedOperationException("Not Yet Implemented");
}
});
}
Expand Down
@@ -1,10 +1,16 @@
package com.quantityandconversion.hackernews;

import com.quantityandconversion.test.MockWebServerTestClass;

import org.junit.Test;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

public class MainActivityBridgeTests {
public class MainActivityBridgeTests extends MockWebServerTestClass {

@Test
public void constructor(){
Expand All @@ -16,14 +22,14 @@ public void constructor(){
new MainActivityBridge(new MainActivity());
}

// @Test
// public void loadData() throws InterruptedException {
//
// final CountDownLatch latch = new CountDownLatch(1);
// final FakeMainActivity fakeMainActivity = new FakeMainActivity(latch);
// final MainActivityBridge mainActivityBridge = new MainActivityBridge(fakeMainActivity);
// mainActivityBridge.loadData();
//
// assertThat(latch.await(1, TimeUnit.SECONDS)).isTrue();
// }
@Test
public void loadData() throws InterruptedException {
itemNetworkTestResponses.simpleItemIdList(mockWebServer);
final CountDownLatch latch = new CountDownLatch(1);
final FakeMainActivity fakeMainActivity = new FakeMainActivity(latch);
final MainActivityBridge mainActivityBridge = new MainActivityBridge(fakeMainActivity);
mainActivityBridge.loadData();

assertThat(latch.await(1, TimeUnit.SECONDS)).isTrue();
}
}
@@ -1,21 +1,16 @@
package com.quantityandconversion.hackernews;

import com.quantityandconversion.hackernews.network.item.internal.ItemNetworkTestResponses;
import com.quantityandconversion.test.MockWebServerTestClass;

import org.junit.Rule;
import org.junit.Test;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import okhttp3.mockwebserver.MockWebServer;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

public class MainActivityMediatorTests {
@Rule
public final MockWebServer mockWebServer = new MockWebServer();
public class MainActivityMediatorTests extends MockWebServerTestClass {

@Test
public void constructor(){
Expand All @@ -29,7 +24,7 @@ public void constructor(){

@Test
public void loadItemData() throws InterruptedException {
new ItemNetworkTestResponses().simpleItemIdList(mockWebServer);
itemNetworkTestResponses.simpleItemIdList(mockWebServer);

final CountDownLatch latch = new CountDownLatch(1);
new MainActivityMediator(new FakeMainActivityBridge(latch, new MainActivity())).loadItemData();
Expand Down
@@ -1,28 +1,23 @@
package com.quantityandconversion.hackernews.network.item;

import com.quantityandconversion.hackernews.network.item.internal.ItemNetworkTestResponses;
import com.quantityandconversion.test.MockWebServerTestClass;

import org.junit.Rule;
import org.junit.Test;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import okhttp3.mockwebserver.MockWebServer;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

import static org.assertj.core.api.Assertions.assertThat;

public class ItemAccessTests {

@Rule
public final MockWebServer mockWebServer = new MockWebServer();
public class ItemAccessTests extends MockWebServerTestClass {

@Test
public void topStories() throws Exception {
new ItemNetworkTestResponses().simpleItemIdList(mockWebServer);
itemNetworkTestResponses.simpleItemIdList(mockWebServer);

final CountDownLatch latch = new CountDownLatch(1);
new ItemAccess().topStories(new Callback<Items>(){
Expand Down
@@ -1,28 +1,23 @@
package com.quantityandconversion.hackernews.network.item.internal;

import com.quantityandconversion.hackernews.network.item.Items;
import com.quantityandconversion.test.MockWebServerTestClass;

import org.junit.Rule;
import org.junit.Test;

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

import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import retrofit2.Call;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

public class ItemNetworkTests {

@Rule
public final MockWebServer mockWebServer = new MockWebServer();
public class ItemNetworkTests extends MockWebServerTestClass {

@Test
public void topStories() throws IOException {
mockWebServer.enqueue(new MockResponse().setResponseCode(HttpURLConnection.HTTP_OK).setBody("[10000,2]"));
itemNetworkTestResponses.simpleItemIdList(mockWebServer);

final Call<Items> topStoriesCall = new ItemNetwork(mockWebServer.url("/")).topStories();
final Items items = topStoriesCall.execute().body();
assertNotNull(items);
Expand Down
@@ -0,0 +1,19 @@
package com.quantityandconversion.test;

import com.quantityandconversion.hackernews.network.item.internal.ItemNetworkTestResponses;

import org.junit.Before;
import org.junit.Rule;

import okhttp3.mockwebserver.MockWebServer;

public class MockWebServerTestClass {
@Rule
public final MockWebServer mockWebServer = new MockWebServer();

protected ItemNetworkTestResponses itemNetworkTestResponses;
@Before
public void setup(){
itemNetworkTestResponses = new ItemNetworkTestResponses();
}
}

0 comments on commit eeb4ece

Please sign in to comment.