package com.jmlb0003.jokes.gradlejokesproject;

import android.app.ProgressDialog;
import android.content.Context;
import android.support.test.annotation.UiThreadTest;
import android.support.test.rule.UiThreadTestRule;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import static android.support.test.InstrumentationRegistry.getTargetContext;
import static junit.framework.Assert.assertFalse;

/**
 * Instrumentation test, which will execute on an Android device.
 *
 * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
 */
@RunWith(AndroidJUnit4.class)
public class JokeAsyncTaskShould implements JokeAsyncTask.JokeAsyncTaskListener {

    @Rule
    public UiThreadTestRule uiThreadTestRule = new UiThreadTestRule();

    private ProgressDialog dialog;
    private JokeAsyncTask task;

    @Before
    public void setUp() throws Throwable {
        final Context context = getTargetContext();

        uiThreadTestRule.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                task = new JokeAsyncTask(context, JokeAsyncTaskShould.this);
                dialog = new ProgressDialog(context);
            }
        });
    }

    @Test
    @UiThreadTest
    public void showDialogWhenExecute() {
        task.execute();
        dialog.show();
    }

    @Test
    @UiThreadTest
    public void returnsJokeSuccessfully() {
        task.execute();
        showAJoke("fakeJoke");
    }

    @Override
    public void showAJoke(final String joke) {
        assertFalse(joke == null);
        assertFalse(joke.isEmpty());
    }

    @Override
    public void thereIsNoJokes() {

    }

}

@@ -64,54 +64,23 @@
 app.
-ProgressDialog;%0Aimport android.content.Context
+Instrumentation
 ;%0Aim
@@ -341,85 +341,8 @@
 h;%0A%0A
-import static android.support.test.InstrumentationRegistry.getTargetContext;%0A
 impo
@@ -611,54 +611,31 @@
 uld 
-implements JokeAsyncTask.JokeAsyncTaskListener
+extends Instrumentation
  %7B%0A%0A
@@ -732,29 +732,26 @@
 ate 
-ProgressDialog dialog
+JokeAsyncTask task
 ;%0A  
@@ -773,21 +773,47 @@
 syncTask
- task
+.JokeAsyncTaskListener listener
 ;%0A%0A    @
@@ -847,136 +847,74 @@
 p() 
-throws Throwable %7B%0A        final Context context = getTargetContext();%0A%0A        uiThreadTestRule.runOnUiThread(new Runnable
+%7B%0A        listener = new JokeAsyncTask.JokeAsyncTaskListener
 () %7B%0A
+%0A
     
@@ -959,90 +959,124 @@
 oid 
-run() %7B%0A                task = new JokeAsyncTask(context, JokeAsyncTaskShould.this
+showAJoke(final String joke) %7B%0A                assertFalse(joke == null);%0A                assertFalse(joke.isEmpty()
 );%0A 
@@ -1073,32 +1073,40 @@
 mpty());%0A       
+     %7D%0A%0A
          dialog 
@@ -1102,45 +1102,64 @@
     
-dialog = new ProgressDialog(context);
+   @Override%0A            public void thereIsNoJokes() %7B%0A
 %0A   
@@ -1169,16 +1169,17 @@
       %7D%0A
+%0A
         
@@ -1179,17 +1179,16 @@
        %7D
-)
 ;%0A    %7D%0A
@@ -1236,159 +1236,79 @@
 oid 
-showDialogWhenExecute() %7B%0A        task.execute();%0A        dialog.show();%0A    %7D%0A%0A    @Test%0A    @UiThreadTest%0A    public void returnsJokeSuccessfully() %7B
+returnsJokeSuccessfully() %7B%0A        task = new JokeAsyncTask(listener);
 %0A   
@@ -1336,16 +1336,25 @@
         
+listener.
 showAJok
@@ -1384,173 +1384,164 @@
    @
-Override%0A    public void showAJoke(final String joke) %7B%0A        assertFalse(joke == null);%0A        assertFalse(joke.isEmpty
+Test%0A    @UiThreadTest%0A    public void notReturnsAnyJokesWhenError() %7B%0A        task = new JokeAsyncTask(listener);%0A        task.execute
 ()
-)
 ;%0A    
-%7D%0A%0A
     
-@Override%0A    public void 
+listener.
 ther
@@ -1548,25 +1548,23 @@
 eIsNoJokes()
- %7B%0A
+;
 %0A    %7D%0A%0A%7D%0A

Create some tests for the asynctask