getPokemon(@Path("id") String id);
+
+}
diff --git a/app/src/main/java/com/ragdroid/mockstar/base/BaseActivity.java b/app/src/main/java/com/ragdroid/mockstar/base/BaseActivity.java
new file mode 100644
index 0000000..5f5fff0
--- /dev/null
+++ b/app/src/main/java/com/ragdroid/mockstar/base/BaseActivity.java
@@ -0,0 +1,63 @@
+package com.ragdroid.mockstar.base;
+
+import android.os.Bundle;
+import android.support.annotation.Nullable;
+import android.support.v7.app.AppCompatActivity;
+import android.support.v7.widget.Toolbar;
+
+import com.ragdroid.mockstar.MockstarApplication;
+import com.ragdroid.mockstar.R;
+import com.ragdroid.mockstar.dagger.ActivityComponent;
+import com.ragdroid.mockstar.dagger.ActivityModule;
+import com.ragdroid.mockstar.dagger.AppComponent;
+import com.ragdroid.mockstar.dagger.DaggerActivityComponent;
+import com.ragdroid.mockstar.mvp.Presenter;
+import com.ragdroid.mockstar.mvp.Scene;
+
+import javax.inject.Inject;
+
+/**
+ * Created by garimajain on 05/03/17.
+ */
+
+abstract public class BaseActivity extends AppCompatActivity implements Scene {
+
+ @Inject protected P presenter;
+
+ @Override
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(getLayoutId());
+ Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
+ setSupportActionBar(toolbar);
+ AppComponent appComponent = ((MockstarApplication) getApplication()).getAppComponent();
+ ActivityComponent activityComponent = DaggerActivityComponent.builder()
+ .appComponent(appComponent)
+ .activityModule(new ActivityModule())
+ .build();
+ injectFrom(activityComponent);
+ setupActivity(savedInstanceState);
+ }
+
+ protected abstract void setupActivity(Bundle savedInstanceState);
+
+ protected abstract int getLayoutId();
+
+ protected abstract void injectFrom(ActivityComponent activityComponent);
+
+
+ @Override
+ protected void onPause() {
+ presenter.onSceneRemoved();
+ super.onPause();
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ presenter.onSceneAdded(this, getIntent().getExtras());
+ }
+
+
+
+}
diff --git a/app/src/main/java/com/ragdroid/mockstar/base/BasePresenter.java b/app/src/main/java/com/ragdroid/mockstar/base/BasePresenter.java
new file mode 100644
index 0000000..fad00a0
--- /dev/null
+++ b/app/src/main/java/com/ragdroid/mockstar/base/BasePresenter.java
@@ -0,0 +1,35 @@
+package com.ragdroid.mockstar.base;
+
+import android.os.Bundle;
+
+import com.ragdroid.mockstar.mvp.Presenter;
+import com.ragdroid.mockstar.mvp.Scene;
+
+/**
+ * Created by garimajain on 05/03/17.
+ */
+
+public class BasePresenter implements Presenter {
+
+ protected BaseSchedulerProvider provider;
+
+ public BasePresenter(BaseSchedulerProvider provider) {
+ this.provider = provider;
+ }
+
+ protected S getScene() {
+ return scene;
+ }
+
+ private S scene;
+
+ @Override
+ public void onSceneAdded(S scene, Bundle data) {
+ this.scene = scene;
+ }
+
+ @Override
+ public void onSceneRemoved() {
+ this.scene = null;
+ }
+}
diff --git a/app/src/main/java/com/ragdroid/mockstar/base/BaseSchedulerProvider.java b/app/src/main/java/com/ragdroid/mockstar/base/BaseSchedulerProvider.java
new file mode 100644
index 0000000..d0df13b
--- /dev/null
+++ b/app/src/main/java/com/ragdroid/mockstar/base/BaseSchedulerProvider.java
@@ -0,0 +1,22 @@
+package com.ragdroid.mockstar.base;
+
+import android.support.annotation.NonNull;
+
+import io.reactivex.Scheduler;
+
+/**
+ * Created by garimajain on 05/03/17.
+ */
+
+public interface BaseSchedulerProvider {
+
+ @NonNull
+ Scheduler computation();
+
+ @NonNull
+ Scheduler io();
+
+ @NonNull
+ Scheduler ui();
+}
+
diff --git a/app/src/main/java/com/ragdroid/mockstar/contracts/MainPresenter.java b/app/src/main/java/com/ragdroid/mockstar/contracts/MainPresenter.java
new file mode 100644
index 0000000..49f26e7
--- /dev/null
+++ b/app/src/main/java/com/ragdroid/mockstar/contracts/MainPresenter.java
@@ -0,0 +1,10 @@
+package com.ragdroid.mockstar.contracts;
+
+import com.ragdroid.mockstar.mvp.Presenter;
+
+/**
+ * Created by garimajain on 05/03/17.
+ */
+
+public interface MainPresenter extends Presenter {
+}
diff --git a/app/src/main/java/com/ragdroid/mockstar/contracts/MainScene.java b/app/src/main/java/com/ragdroid/mockstar/contracts/MainScene.java
new file mode 100644
index 0000000..02e9de0
--- /dev/null
+++ b/app/src/main/java/com/ragdroid/mockstar/contracts/MainScene.java
@@ -0,0 +1,13 @@
+package com.ragdroid.mockstar.contracts;
+
+import com.ragdroid.mockstar.mvp.Scene;
+
+/**
+ * Created by garimajain on 05/03/17.
+ */
+
+public interface MainScene extends Scene {
+ void setApiText(String id);
+
+ void showErrorDialog(String string);
+}
diff --git a/app/src/main/java/com/ragdroid/mockstar/dagger/ActivityComponent.java b/app/src/main/java/com/ragdroid/mockstar/dagger/ActivityComponent.java
new file mode 100644
index 0000000..26427f9
--- /dev/null
+++ b/app/src/main/java/com/ragdroid/mockstar/dagger/ActivityComponent.java
@@ -0,0 +1,17 @@
+package com.ragdroid.mockstar.dagger;
+
+import com.ragdroid.mockstar.MainActivity;
+
+import dagger.Component;
+
+/**
+ * Created by garimajain on 05/03/17.
+ */
+@Component(dependencies = {AppComponent.class},
+ modules = ActivityModule.class)
+@ActivityScope
+public interface ActivityComponent {
+
+ void inject(MainActivity mainActivity);
+
+}
diff --git a/app/src/main/java/com/ragdroid/mockstar/dagger/ActivityModule.java b/app/src/main/java/com/ragdroid/mockstar/dagger/ActivityModule.java
new file mode 100644
index 0000000..d8b99dd
--- /dev/null
+++ b/app/src/main/java/com/ragdroid/mockstar/dagger/ActivityModule.java
@@ -0,0 +1,22 @@
+package com.ragdroid.mockstar.dagger;
+
+import com.ragdroid.mockstar.MainPresenterImpl;
+import com.ragdroid.mockstar.contracts.MainPresenter;
+
+import dagger.Module;
+import dagger.Provides;
+
+/**
+ * Created by garimajain on 05/03/17.
+ */
+@Module
+@ActivityScope
+public class ActivityModule {
+
+ @ActivityScope
+ @Provides
+ public MainPresenter provideHomePresenter(MainPresenterImpl presenter) {
+ return presenter;
+ }
+
+}
diff --git a/app/src/main/java/com/ragdroid/mockstar/dagger/ActivityScope.java b/app/src/main/java/com/ragdroid/mockstar/dagger/ActivityScope.java
new file mode 100644
index 0000000..ff52eed
--- /dev/null
+++ b/app/src/main/java/com/ragdroid/mockstar/dagger/ActivityScope.java
@@ -0,0 +1,16 @@
+package com.ragdroid.mockstar.dagger;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+import javax.inject.Scope;
+
+/**
+ * Created by garimajain on 05/03/17.
+ */
+@Scope
+@Documented
+@Retention(value = RetentionPolicy.RUNTIME)
+public @interface ActivityScope {
+}
diff --git a/app/src/main/java/com/ragdroid/mockstar/dagger/ApiModule.java b/app/src/main/java/com/ragdroid/mockstar/dagger/ApiModule.java
new file mode 100644
index 0000000..f9eb668
--- /dev/null
+++ b/app/src/main/java/com/ragdroid/mockstar/dagger/ApiModule.java
@@ -0,0 +1,87 @@
+package com.ragdroid.mockstar.dagger;
+
+import com.google.gson.FieldNamingPolicy;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.ragdroid.mockstar.api.PokemonService;
+
+import java.util.concurrent.TimeUnit;
+
+import javax.inject.Singleton;
+
+import dagger.Module;
+import dagger.Provides;
+import okhttp3.OkHttpClient;
+import okhttp3.logging.HttpLoggingInterceptor;
+import retrofit2.Retrofit;
+import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
+import retrofit2.converter.gson.GsonConverterFactory;
+
+/**
+ * Created by garimajain on 05/03/17.
+ */
+
+@Module
+public class ApiModule {
+
+ public ApiModule() {
+
+ }
+
+ @Provides
+ @Singleton
+ public HttpLoggingInterceptor getLoggingInterceptor() {
+ HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
+ loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
+ return loggingInterceptor;
+ }
+
+
+ @Provides
+ @Singleton
+ Gson provideGson() {
+ GsonBuilder gsonBuilder = new GsonBuilder();
+ gsonBuilder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);
+ return gsonBuilder.create();
+ }
+
+ @Provides
+ @Singleton
+ OkHttpClient provideOkHttpClient(HttpLoggingInterceptor loggingInterceptor) {
+ OkHttpClient.Builder builder = new OkHttpClient.Builder()
+ .addInterceptor(loggingInterceptor)
+ .connectTimeout(60, TimeUnit.SECONDS)
+ .readTimeout(60, TimeUnit.SECONDS)
+ .writeTimeout(60, TimeUnit.SECONDS);
+ addOkHttpConfig(builder);
+ return builder
+ .build();
+
+ }
+
+ protected void addOkHttpConfig(OkHttpClient.Builder builder) {
+
+ }
+
+ @Provides
+ @Singleton
+ Retrofit provideRetrofit(Gson gson, OkHttpClient okHttpClient) {
+ return new Retrofit.Builder()
+ .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
+ .addConverterFactory(GsonConverterFactory.create(gson))
+ .baseUrl(getBaseUrl())
+ .client(okHttpClient)
+ .build();
+ }
+
+ protected String getBaseUrl() {
+ return "http://pokeapi.co/api/v2/";
+ }
+
+ @Provides
+ @Singleton
+ public PokemonService providePokemonService(Retrofit retrofit) {
+ return retrofit.create(PokemonService.class);
+ }
+
+}
diff --git a/app/src/main/java/com/ragdroid/mockstar/dagger/AppComponent.java b/app/src/main/java/com/ragdroid/mockstar/dagger/AppComponent.java
new file mode 100644
index 0000000..0ccd6e7
--- /dev/null
+++ b/app/src/main/java/com/ragdroid/mockstar/dagger/AppComponent.java
@@ -0,0 +1,21 @@
+package com.ragdroid.mockstar.dagger;
+
+import com.ragdroid.mockstar.api.PokemonService;
+import com.ragdroid.mockstar.base.BaseSchedulerProvider;
+
+import javax.inject.Singleton;
+
+import dagger.Component;
+
+/**
+ * Created by garimajain on 05/03/17.
+ */
+@Singleton
+@Component(modules = {AppModule.class, ApiModule.class})
+public interface AppComponent {
+
+ BaseSchedulerProvider getSchedulerProvider();
+
+ PokemonService providePokemonService();
+
+}
diff --git a/app/src/main/java/com/ragdroid/mockstar/dagger/AppModule.java b/app/src/main/java/com/ragdroid/mockstar/dagger/AppModule.java
new file mode 100644
index 0000000..f7be794
--- /dev/null
+++ b/app/src/main/java/com/ragdroid/mockstar/dagger/AppModule.java
@@ -0,0 +1,38 @@
+package com.ragdroid.mockstar.dagger;
+
+import android.app.Application;
+
+import com.ragdroid.mockstar.base.BaseSchedulerProvider;
+import com.ragdroid.mockstar.logic.SchedulerProvider;
+
+import javax.inject.Singleton;
+
+import dagger.Module;
+import dagger.Provides;
+
+/**
+ * Created by garimajain on 05/03/17.
+ */
+@Module
+public class AppModule {
+
+ Application application;
+
+ public AppModule(Application application) {
+ this.application = application;
+ }
+
+ @Provides
+ @Singleton
+ Application providesApplication() {
+ return application;
+ }
+
+ @Provides
+ @Singleton
+ BaseSchedulerProvider providerSchedulerProvider(SchedulerProvider provider) {
+ return provider;
+ }
+
+
+}
diff --git a/app/src/main/java/com/ragdroid/mockstar/logic/SchedulerProvider.java b/app/src/main/java/com/ragdroid/mockstar/logic/SchedulerProvider.java
new file mode 100644
index 0000000..0481f7b
--- /dev/null
+++ b/app/src/main/java/com/ragdroid/mockstar/logic/SchedulerProvider.java
@@ -0,0 +1,43 @@
+package com.ragdroid.mockstar.logic;
+
+import android.support.annotation.NonNull;
+
+import com.ragdroid.mockstar.base.BaseSchedulerProvider;
+
+import javax.inject.Inject;
+
+import io.reactivex.Scheduler;
+import io.reactivex.android.schedulers.AndroidSchedulers;
+import io.reactivex.schedulers.Schedulers;
+
+/**
+ * Created by garimajain on 05/03/17.
+ */
+
+public class SchedulerProvider implements BaseSchedulerProvider {
+
+ @Inject
+ public SchedulerProvider() {
+
+ }
+
+ @Override
+ @NonNull
+ public Scheduler computation() {
+ return Schedulers.computation();
+ }
+
+ @Override
+ @NonNull
+ public Scheduler io() {
+ return Schedulers.io();
+ }
+
+ @Override
+ @NonNull
+ public Scheduler ui() {
+ return AndroidSchedulers.mainThread();
+ }
+
+}
+
diff --git a/app/src/main/java/com/ragdroid/mockstar/mvp/Presenter.java b/app/src/main/java/com/ragdroid/mockstar/mvp/Presenter.java
new file mode 100644
index 0000000..fee6e4a
--- /dev/null
+++ b/app/src/main/java/com/ragdroid/mockstar/mvp/Presenter.java
@@ -0,0 +1,14 @@
+package com.ragdroid.mockstar.mvp;
+
+import android.os.Bundle;
+
+/**
+ * Created by garimajain on 05/03/17.
+ */
+
+public interface Presenter {
+
+ void onSceneAdded(T scene, Bundle data);
+ void onSceneRemoved();
+
+}
diff --git a/app/src/main/java/com/ragdroid/mockstar/mvp/Scene.java b/app/src/main/java/com/ragdroid/mockstar/mvp/Scene.java
new file mode 100644
index 0000000..b9bf832
--- /dev/null
+++ b/app/src/main/java/com/ragdroid/mockstar/mvp/Scene.java
@@ -0,0 +1,9 @@
+package com.ragdroid.mockstar.mvp;
+
+/**
+ * Created by garimajain on 05/03/17.
+ */
+
+public interface Scene {
+
+}
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
new file mode 100644
index 0000000..10ba373
--- /dev/null
+++ b/app/src/main/res/layout/activity_main.xml
@@ -0,0 +1,36 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png
new file mode 100644
index 0000000..cde69bc
Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher.png differ
diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png
new file mode 100644
index 0000000..c133a0c
Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher.png differ
diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png
new file mode 100644
index 0000000..bfa42f0
Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ
diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
new file mode 100644
index 0000000..324e72c
Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ
diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
new file mode 100644
index 0000000..aee44e1
Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ
diff --git a/app/src/main/res/values-v21/styles.xml b/app/src/main/res/values-v21/styles.xml
new file mode 100644
index 0000000..0347943
--- /dev/null
+++ b/app/src/main/res/values-v21/styles.xml
@@ -0,0 +1,9 @@
+
+>
+
+
diff --git a/app/src/main/res/values-w820dp/dimens.xml b/app/src/main/res/values-w820dp/dimens.xml
new file mode 100644
index 0000000..63fc816
--- /dev/null
+++ b/app/src/main/res/values-w820dp/dimens.xml
@@ -0,0 +1,6 @@
+
+
+ 64dp
+
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
new file mode 100644
index 0000000..3ab3e9c
--- /dev/null
+++ b/app/src/main/res/values/colors.xml
@@ -0,0 +1,6 @@
+
+
+ #3F51B5
+ #303F9F
+ #FF4081
+
diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml
new file mode 100644
index 0000000..47c8224
--- /dev/null
+++ b/app/src/main/res/values/dimens.xml
@@ -0,0 +1,5 @@
+
+
+ 16dp
+ 16dp
+
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
new file mode 100644
index 0000000..8235bd1
--- /dev/null
+++ b/app/src/main/res/values/strings.xml
@@ -0,0 +1,3 @@
+
+ Mockstar
+
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
new file mode 100644
index 0000000..a29fbbc
--- /dev/null
+++ b/app/src/main/res/values/styles.xml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/test/java/com/ragdroid/mockstar/ExampleUnitTest.java b/app/src/test/java/com/ragdroid/mockstar/ExampleUnitTest.java
new file mode 100644
index 0000000..11e1a85
--- /dev/null
+++ b/app/src/test/java/com/ragdroid/mockstar/ExampleUnitTest.java
@@ -0,0 +1,17 @@
+package com.ragdroid.mockstar;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Example local unit test, which will execute on the development machine (host).
+ *
+ * @see Testing documentation
+ */
+public class ExampleUnitTest {
+ @Test
+ public void addition_isCorrect() throws Exception {
+ assertEquals(4, 2 + 2);
+ }
+}
\ No newline at end of file
diff --git a/app/src/test/java/com/ragdroid/mockstar/MainPresenterImplTest.java b/app/src/test/java/com/ragdroid/mockstar/MainPresenterImplTest.java
new file mode 100644
index 0000000..7943f49
--- /dev/null
+++ b/app/src/test/java/com/ragdroid/mockstar/MainPresenterImplTest.java
@@ -0,0 +1,135 @@
+package com.ragdroid.mockstar;
+
+import com.ragdroid.mockstar.api.PokemonService;
+import com.ragdroid.mockstar.contracts.MainScene;
+import com.ragdroid.mockstar.dagger.BaseLogicTest;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import java.net.HttpURLConnection;
+import java.util.concurrent.TimeUnit;
+
+import javax.inject.Inject;
+
+import okhttp3.mockwebserver.MockResponse;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+/**
+ * Created by garimajain on 05/03/17.
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class MainPresenterImplTest extends BaseLogicTest {
+
+ @Inject PokemonService pokemonService;
+ @Mock MainScene mainSceneMock;
+ private MainPresenterImpl presenter;
+
+ @Override
+ public void setUp() throws Exception {
+ getComponent().inject(this);
+ super.setUp();
+ }
+
+ @Test
+ public void testOnSceneAdded() {
+ presenter = new MainPresenterImpl(schedulersProvider, pokemonService);
+
+ presenter.onSceneAdded(mainSceneMock, null);
+
+ testScheduler.triggerActions();
+
+ ArgumentCaptor captor = ArgumentCaptor.forClass(String.class);
+
+ verify(mainSceneMock).setApiText(captor.capture());
+
+ assertEquals("Id : 12", captor.getValue());
+ }
+
+ @Test
+ public void testDemoResponseError503() {
+ reset(mainSceneMock);
+ MainPresenterImpl presenter = new MainPresenterImpl(schedulersProvider, pokemonService);
+
+ MockResponse response = new MockResponse();
+ response.setResponseCode(HttpURLConnection.HTTP_UNAVAILABLE);
+
+ getErrorMockWebServer().enqueue(response);
+
+ presenter.onSceneAdded(mainSceneMock, null);
+
+ testScheduler.triggerActions();
+
+ verify(mainSceneMock, times(0)).setApiText(anyString());
+ verify(mainSceneMock, times(1)).showErrorDialog("Fire on the Server");
+ }
+
+ @Test
+ public void testDemoResponseError404() {
+ reset(mainSceneMock);
+
+ MainPresenterImpl presenter = new MainPresenterImpl(schedulersProvider, pokemonService);
+
+ MockResponse response = new MockResponse();
+ response.setResponseCode(HttpURLConnection.HTTP_NOT_FOUND);
+
+ getErrorMockWebServer().enqueue(response);
+
+ presenter.onSceneAdded(mainSceneMock, null);
+
+ testScheduler.triggerActions();
+
+ verify(mainSceneMock, times(1)).showErrorDialog("Lost!");
+ verify(mainSceneMock, times(0)).setApiText(anyString());
+ }
+
+ @Test
+ public void testDemoResponseError403() {
+ reset(mainSceneMock);
+
+ MainPresenterImpl presenter = new MainPresenterImpl(schedulersProvider, pokemonService);
+
+ MockResponse response = new MockResponse();
+ response.setResponseCode(HttpURLConnection.HTTP_UNAUTHORIZED);
+
+ getErrorMockWebServer().enqueue(response);
+
+ presenter.onSceneAdded(mainSceneMock, null);
+
+ testScheduler.triggerActions();
+
+ verify(mainSceneMock, times(1)).showErrorDialog("You shall not pass!");
+ verify(mainSceneMock, times(0)).setApiText(anyString());
+ }
+
+
+ @Test
+ public void testDemoResponseErrorSocket() {
+ reset(mainSceneMock);
+
+ MainPresenterImpl presenter = new MainPresenterImpl(schedulersProvider, pokemonService);
+
+ MockResponse response = new MockResponse();
+ response.setBody("\"message\":\"Hello\"").throttleBody(1, 2, TimeUnit.SECONDS);
+
+ getErrorMockWebServer().enqueue(response);
+
+ presenter.onSceneAdded(mainSceneMock, null);
+
+ testScheduler.triggerActions();
+
+ verify(mainSceneMock, times(1)).showErrorDialog(anyString());
+ verify(mainSceneMock, times(0)).setApiText(anyString());
+ }
+
+
+
+}
diff --git a/app/src/test/java/com/ragdroid/mockstar/dagger/BaseLogicTest.java b/app/src/test/java/com/ragdroid/mockstar/dagger/BaseLogicTest.java
new file mode 100644
index 0000000..86444a4
--- /dev/null
+++ b/app/src/test/java/com/ragdroid/mockstar/dagger/BaseLogicTest.java
@@ -0,0 +1,89 @@
+package com.ragdroid.mockstar.dagger;
+
+import android.support.annotation.NonNull;
+
+import com.ragdroid.mockstar.base.BaseSchedulerProvider;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.runner.RunWith;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import javax.inject.Inject;
+
+import io.reactivex.Scheduler;
+import io.reactivex.schedulers.TestScheduler;
+import okhttp3.mockwebserver.Dispatcher;
+import okhttp3.mockwebserver.MockWebServer;
+import okhttp3.mockwebserver.QueueDispatcher;
+
+/**
+ * Created by garimajain on 27/02/17.
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class BaseLogicTest {
+
+ private LogicTestComponent component;
+
+ @Inject MockWebServer mockWebServer;
+ @Inject Dispatcher dispatcher;
+
+
+ protected MockWebServer getErrorMockWebServer() {
+ mockWebServer.setDispatcher(new QueueDispatcher());
+ return mockWebServer;
+ }
+
+ protected MockWebServer getMockWebServer() {
+ return mockWebServer;
+ }
+
+
+
+ protected TestScheduler testScheduler = new TestScheduler();
+
+ protected BaseSchedulerProvider schedulersProvider = new BaseSchedulerProvider() {
+
+ @NonNull
+ @Override
+ public Scheduler io() {
+ return testScheduler;
+ }
+
+ @NonNull
+ @Override
+ public Scheduler ui() {
+ return testScheduler;
+ }
+
+ @NonNull
+ @Override
+ public Scheduler computation() {
+ return testScheduler;
+ }
+
+ };
+
+
+ @Before
+ public void setUp() throws Exception {
+
+ }
+
+ protected LogicTestComponent getComponent() {
+ if (component == null) {
+ component = DaggerLogicTestComponent.builder()
+ .logicTestModule(new LogicTestModule())
+ .build();
+ }
+
+ return component;
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ mockWebServer.setDispatcher(dispatcher);
+ mockWebServer.shutdown();
+ }
+
+}
diff --git a/app/src/test/java/com/ragdroid/mockstar/dagger/LogicTestComponent.java b/app/src/test/java/com/ragdroid/mockstar/dagger/LogicTestComponent.java
new file mode 100644
index 0000000..68cf04e
--- /dev/null
+++ b/app/src/test/java/com/ragdroid/mockstar/dagger/LogicTestComponent.java
@@ -0,0 +1,18 @@
+package com.ragdroid.mockstar.dagger;
+
+import com.ragdroid.mockstar.MainPresenterImplTest;
+
+import javax.inject.Singleton;
+
+import dagger.Component;
+
+/**
+ * Created by garimajain on 27/02/17.
+ */
+
+@Singleton
+@Component(modules = {LogicTestModule.class})
+public interface LogicTestComponent {
+
+ void inject(MainPresenterImplTest mainPresenterImplTest);
+}
\ No newline at end of file
diff --git a/app/src/test/java/com/ragdroid/mockstar/dagger/LogicTestModule.java b/app/src/test/java/com/ragdroid/mockstar/dagger/LogicTestModule.java
new file mode 100644
index 0000000..f6a5bf9
--- /dev/null
+++ b/app/src/test/java/com/ragdroid/mockstar/dagger/LogicTestModule.java
@@ -0,0 +1,61 @@
+package com.ragdroid.mockstar.dagger;
+
+
+import android.support.annotation.NonNull;
+
+import com.ragdroid.mockstar.api.LocalResponseDispatcher;
+
+
+import java.util.concurrent.TimeUnit;
+
+import javax.inject.Singleton;
+
+import dagger.Module;
+import dagger.Provides;
+import okhttp3.OkHttpClient;
+import okhttp3.mockwebserver.Dispatcher;
+import okhttp3.mockwebserver.MockWebServer;
+
+/**
+ * Created by garimajain on 27/02/17.
+ */
+@Module
+public class LogicTestModule extends ApiModule {
+ @Override
+ protected void addOkHttpConfig(OkHttpClient.Builder builder) {
+ builder.readTimeout(2, TimeUnit.SECONDS);
+ }
+
+ private final LocalResponseDispatcher dispatcher;
+ private final MockWebServer mockWebServer;
+
+ public LogicTestModule() {
+ dispatcher = new LocalResponseDispatcher();
+ this.mockWebServer = getMockWebServer(dispatcher);
+ }
+
+ @Override
+ protected String getBaseUrl() {
+ return mockWebServer.url("/").toString();
+ }
+
+ @Provides
+ @Singleton
+ public MockWebServer provideDefaultMockWebServer(Dispatcher dispatcher) {
+ return mockWebServer;
+ }
+
+ @NonNull
+ private MockWebServer getMockWebServer(Dispatcher dispatcher) {
+ MockWebServer mockWebServer = new MockWebServer();
+ mockWebServer.setDispatcher(dispatcher);
+ return mockWebServer;
+ }
+
+
+ @Provides
+ @Singleton
+ public Dispatcher getTestDispatcher() {
+ return dispatcher;
+ }
+}
diff --git a/build.gradle b/build.gradle
new file mode 100644
index 0000000..74b2ab0
--- /dev/null
+++ b/build.gradle
@@ -0,0 +1,23 @@
+// Top-level build file where you can add configuration options common to all sub-projects/modules.
+
+buildscript {
+ repositories {
+ jcenter()
+ }
+ dependencies {
+ classpath 'com.android.tools.build:gradle:2.2.3'
+
+ // NOTE: Do not place your application dependencies here; they belong
+ // in the individual module build.gradle files
+ }
+}
+
+allprojects {
+ repositories {
+ jcenter()
+ }
+}
+
+task clean(type: Delete) {
+ delete rootProject.buildDir
+}
diff --git a/gradle.properties b/gradle.properties
new file mode 100644
index 0000000..aac7c9b
--- /dev/null
+++ b/gradle.properties
@@ -0,0 +1,17 @@
+# Project-wide Gradle settings.
+
+# IDE (e.g. Android Studio) users:
+# Gradle settings configured through the IDE *will override*
+# any settings specified in this file.
+
+# For more details on how to configure your build environment visit
+# http://www.gradle.org/docs/current/userguide/build_environment.html
+
+# Specifies the JVM arguments used for the daemon process.
+# The setting is particularly useful for tweaking memory settings.
+org.gradle.jvmargs=-Xmx1536m
+
+# When configured, Gradle will run in incubating parallel mode.
+# This option should only be used with decoupled projects. More details, visit
+# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
+# org.gradle.parallel=true
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 0000000..13372ae
Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000..04e285f
--- /dev/null
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Mon Dec 28 10:00:20 PST 2015
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
diff --git a/gradlew b/gradlew
new file mode 100755
index 0000000..9d82f78
--- /dev/null
+++ b/gradlew
@@ -0,0 +1,160 @@
+#!/usr/bin/env bash
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+ echo "$*"
+}
+
+die ( ) {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+esac
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >/dev/null
+APP_HOME="`pwd -P`"
+cd "$SAVED" >/dev/null
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+ JAVACMD=`cygpath --unix "$JAVACMD"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=$((i+1))
+ done
+ case $i in
+ (0) set -- ;;
+ (1) set -- "$args0" ;;
+ (2) set -- "$args0" "$args1" ;;
+ (3) set -- "$args0" "$args1" "$args2" ;;
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
+function splitJvmOpts() {
+ JVM_OPTS=("$@")
+}
+eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
diff --git a/gradlew.bat b/gradlew.bat
new file mode 100644
index 0000000..aec9973
--- /dev/null
+++ b/gradlew.bat
@@ -0,0 +1,90 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windowz variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+if "%@eval[2+2]" == "4" goto 4NT_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+goto execute
+
+:4NT_args
+@rem Get arguments from the 4NT Shell from JP Software
+set CMD_LINE_ARGS=%$
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/mocks/.gitignore b/mocks/.gitignore
new file mode 100644
index 0000000..796b96d
--- /dev/null
+++ b/mocks/.gitignore
@@ -0,0 +1 @@
+/build
diff --git a/mocks/build.gradle b/mocks/build.gradle
new file mode 100644
index 0000000..6ace9f9
--- /dev/null
+++ b/mocks/build.gradle
@@ -0,0 +1,16 @@
+apply plugin: 'java'
+
+task copyTestResources(type: Copy) {
+ from "${projectDir}/src/main/resources"
+ into "${buildDir}/classes/test"
+}
+processTestResources.dependsOn copyTestResources
+
+dependencies {
+ compile fileTree(dir: 'libs', include: ['*.jar'])
+}
+
+compileJava {
+ sourceCompatibility = JavaVersion.VERSION_1_7
+ targetCompatibility = JavaVersion.VERSION_1_7
+}
diff --git a/mocks/src/main/resources/get_pokemon_12.json b/mocks/src/main/resources/get_pokemon_12.json
new file mode 100644
index 0000000..179a0a3
--- /dev/null
+++ b/mocks/src/main/resources/get_pokemon_12.json
@@ -0,0 +1,88 @@
+{
+ "id": 12,
+ "name": "butterfree",
+ "base_experience": 178,
+ "height": 11,
+ "is_default": true,
+ "order": 16,
+ "weight": 320,
+ "abilities": [{
+ "is_hidden": true,
+ "slot": 3,
+ "ability": {
+ "name": "tinted-lens",
+ "url": "http://pokeapi.co/api/v2/ability/110/"
+ }
+ }],
+ "forms": [{
+ "name": "butterfree",
+ "url": "http://pokeapi.co/api/v2/pokemon-form/12/"
+ }],
+ "game_indices": [{
+ "game_index": 12,
+ "version": {
+ "name": "white-2",
+ "url": "http://pokeapi.co/api/v2/version/22/"
+ }
+ }],
+ "held_items": [{
+ "item": {
+ "name": "silver-powder",
+ "url": "http://pokeapi.co/api/v2/item/199/"
+ },
+ "version_details": [{
+ "rarity": 5,
+ "version": {
+ "name": "y",
+ "url": "http://pokeapi.co/api/v2/version/24/"
+ }
+ }]
+ }],
+ "location_area_encounters": "\/api\/v2\/pokemon\/12\/encounters",
+ "moves": [{
+ "move": {
+ "name": "flash",
+ "url": "http://pokeapi.co/api/v2/move/148/"
+ },
+ "version_group_details": [{
+ "level_learned_at": 0,
+ "version_group": {
+ "name": "x-y",
+ "url": "http://pokeapi.co/api/v2/version-group/15/"
+ },
+ "move_learn_method": {
+ "name": "machine",
+ "url": "http://pokeapi.co/api/v2/move-learn-method/4/"
+ }
+ }]
+ }],
+ "species": {
+ "name": "butterfree",
+ "url": "http://pokeapi.co/api/v2/pokemon-species/12/"
+ },
+ "sprites": {
+ "back_female": "http://pokeapi.co/media/sprites/pokemon/back/female/12.png",
+ "back_shiny_female": "http://pokeapi.co/media/sprites/pokemon/back/shiny/female/12.png",
+ "back_default": "http://pokeapi.co/media/sprites/pokemon/back/12.png",
+ "front_female": "http://pokeapi.co/media/sprites/pokemon/female/12.png",
+ "front_shiny_female": "http://pokeapi.co/media/sprites/pokemon/shiny/female/12.png",
+ "back_shiny": "http://pokeapi.co/media/sprites/pokemon/back/shiny/12.png",
+ "front_default": "http://pokeapi.co/media/sprites/pokemon/12.png",
+ "front_shiny": "http://pokeapi.co/media/sprites/pokemon/shiny/12.png"
+ },
+ "stats": [{
+ "base_stat": 70,
+ "effort": 0,
+ "stat": {
+ "name": "speed",
+ "url": "http://pokeapi.co/api/v2/stat/6/"
+ }
+ }],
+ "types": [{
+ "slot": 2,
+ "type": {
+ "name": "flying",
+ "url": "http://pokeapi.co/api/v2/type/3/"
+ }
+ }]
+}
diff --git a/settings.gradle b/settings.gradle
new file mode 100644
index 0000000..f5439ec
--- /dev/null
+++ b/settings.gradle
@@ -0,0 +1 @@
+include ':app', ':mocks'