Yiupang 9 anni fa
parent
commit
f5057f4e0d

+ 1 - 1
app/src/test/java/com/example/yiupang/freefoodfinder/TestHttpCall.java

@@ -7,7 +7,7 @@ import org.junit.Test;
  * Created by yiupang on 6/1/2017.
  *
  */
-class TestHttpCall
+public class TestHttpCall
 {
 
 }

+ 18 - 2
app/src/test/java/com/example/yiupang/freefoodfinder/TestHttpRequest.java

@@ -1,19 +1,35 @@
 package com.example.yiupang.freefoodfinder;
 
+import android.widget.ListView;
+
 import org.junit.Test;
 import static org.junit.Assert.assertEquals;
 import org.junit.Test;
 
+import java.util.List;
+
 /**
  * Created by yiupang on 6/1/2017.
  *
  */
-class TestHttpRequest
+public class TestHttpRequest
 {
     @Test
-    public void testParingDataString()
+    public void testGetCall()
     {
+        final String expected = "200";
 
+        HttpCall httpCall = new HttpCall();
+        httpCall.setMethodType(HttpCall.GET);
+        httpCall.setUrl("http://free-food-finder.herokuapp.com/events");
+        new HttpRequest(){
+            @Override
+            public void onResponse(Object response, int code)
+            {
+                super.onResponse(response, code);
+                assertEquals(expected, Integer.toString(code));
+            }
+        }.execute(httpCall);
     }
 
     @Test

+ 34 - 0
app/src/test/java/com/example/yiupang/freefoodfinder/TestMainActivity.java

@@ -0,0 +1,34 @@
+package com.example.yiupang.freefoodfinder;
+
+import org.junit.Test;
+
+import java.lang.reflect.Method;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Created by yiupang on 6/4/2017.
+ *
+ */
+public class TestMainActivity
+{
+    @Test
+    public void TestSwitchFragment()
+    {
+        AboutUsScreen expected = new AboutUsScreen();
+        try
+        {
+            MainActivity m = new MainActivity();
+            Method m1 = m.getClass().getDeclaredMethod("getSelectedFragement", int.class);
+            m1.setAccessible(true);
+            Object o = m1.invoke(m, 1);
+            assertThat(expected, instanceOf(o.getClass()));
+        }
+        catch (Exception e)
+        {
+            System.out.println(e);
+        }
+    }
+}