From f381a292741c6df25ca33c26e3cc3bd751f535b4 Mon Sep 17 00:00:00 2001 From: Robin Koedood Date: Tue, 5 Jan 2021 16:04:25 +0100 Subject: [PATCH 1/3] [ADD] DirectionsStep test --- .../a1/nextlocation/DirectionsStepTest.java | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 app/src/test/java/com/a1/nextlocation/DirectionsStepTest.java diff --git a/app/src/test/java/com/a1/nextlocation/DirectionsStepTest.java b/app/src/test/java/com/a1/nextlocation/DirectionsStepTest.java new file mode 100644 index 0000000..d719f4e --- /dev/null +++ b/app/src/test/java/com/a1/nextlocation/DirectionsStepTest.java @@ -0,0 +1,69 @@ +package com.a1.nextlocation; + +import com.a1.nextlocation.json.DirectionsStep; + +import org.junit.Before; +import org.junit.Test; +import org.osmdroid.util.GeoPoint; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertEquals; + +public class DirectionsStepTest { + private DirectionsStep directionsStep; + @Before + public void init(){ + directionsStep = new DirectionsStep(); + } + + @Test + public void testDistance(){ + directionsStep.setDistance(432.56); + double expected = 432.56; + assertEquals(expected, directionsStep.getDistance(), 0.01); + } + + @Test + public void testDuration(){ + directionsStep.setDuration(531.89); + double expected = 531.89; + assertEquals(expected, directionsStep.getDuration(), 0.01); + } + + @Test + public void testInstuction(){ + directionsStep.setInstruction("TESTINGINSTUCTION"); + String expected = "TESTINGINSTUCTION"; + assertEquals(expected, directionsStep.getInstruction()); + } + + @Test + public void testName(){ + directionsStep.setName("TESTINGNAME"); + String expected = "TESTINGNAME"; + assertEquals(expected, directionsStep.getName()); + } + + @Test + public void testWay_Points(){ + ArrayList expected = new ArrayList<>(); + expected.add(56); + expected.add(1123); + expected.add(23); + expected.add(73); + directionsStep.setWay_points(expected); + + assertEquals(expected, directionsStep.getWay_points()); + } + + @Test + public void testWayPoints(){ + GeoPoint[] expected = {new GeoPoint(5.1658, 4.163), new GeoPoint(2.0896, 7.158), + new GeoPoint(4.0168, 6.1450), new GeoPoint(7.1498, 9.1586), }; + directionsStep.setWaypoints(expected); + + assertEquals(expected, directionsStep.getWaypoints()); + } +} From e71c1955731e69c12a836a99ef0b5994e02440e4 Mon Sep 17 00:00:00 2001 From: Robin Koedood Date: Tue, 5 Jan 2021 16:11:19 +0100 Subject: [PATCH 2/3] [ADD] DirectionResultTest --- .../a1/nextlocation/DirectionsResultTest.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 app/src/test/java/com/a1/nextlocation/DirectionsResultTest.java diff --git a/app/src/test/java/com/a1/nextlocation/DirectionsResultTest.java b/app/src/test/java/com/a1/nextlocation/DirectionsResultTest.java new file mode 100644 index 0000000..ad4588f --- /dev/null +++ b/app/src/test/java/com/a1/nextlocation/DirectionsResultTest.java @@ -0,0 +1,50 @@ +package com.a1.nextlocation; + +import com.a1.nextlocation.json.DirectionsResult; +import com.a1.nextlocation.json.DirectionsStep; + +import org.junit.Before; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertEquals; + +public class DirectionsResultTest { + private DirectionsResult directionsResult; + + @Before + public void init(){ + directionsResult = new DirectionsResult(); + } + + @Test + public void testDistance(){ + directionsResult.setDistance(45.32); + double expected = 45.32; + + assertEquals(expected, directionsResult.getDistance(), 0.01); + } + + @Test + public void testDuration(){ + directionsResult.setDuration(95.123); + double expected = 95.123; + + assertEquals(expected, directionsResult.getDuration(), 0.01); + } + + @Test + public void testSteps(){ + List expected = new ArrayList<>(); + directionsResult.addStep(new DirectionsStep()); + directionsResult.addStep(new DirectionsStep()); + directionsResult.addStep(new DirectionsStep()); + directionsResult.setSteps(expected); + + assertEquals(expected, directionsResult.getSteps()); + } + + +} From 20c09c3458867ebf695ad5a489a52442442cc32c Mon Sep 17 00:00:00 2001 From: Robin Koedood Date: Tue, 5 Jan 2021 16:52:48 +0100 Subject: [PATCH 3/3] [TRIED] MainActivity Test --- .../com/a1/nextlocation/MainActivityTest.java | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 app/src/androidTest/java/com/a1/nextlocation/MainActivityTest.java diff --git a/app/src/androidTest/java/com/a1/nextlocation/MainActivityTest.java b/app/src/androidTest/java/com/a1/nextlocation/MainActivityTest.java new file mode 100644 index 0000000..b0fa343 --- /dev/null +++ b/app/src/androidTest/java/com/a1/nextlocation/MainActivityTest.java @@ -0,0 +1,64 @@ +package com.a1.nextlocation; + +import android.app.LauncherActivity; +import android.widget.Button; + +import androidx.test.espresso.contrib.NavigationViewActions; +import androidx.test.espresso.contrib.RecyclerViewActions; +import androidx.test.espresso.matcher.RootMatchers; +import androidx.test.rule.ActivityTestRule; + +import com.a1.nextlocation.fragments.CouponFragment; +import com.google.android.material.bottomnavigation.BottomNavigationItemView; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static androidx.test.espresso.Espresso.onView; +import static androidx.test.espresso.action.ViewActions.click; +import static androidx.test.espresso.assertion.ViewAssertions.matches; +import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; +import static androidx.test.espresso.matcher.ViewMatchers.withId; +import static androidx.test.espresso.matcher.ViewMatchers.withText; + +public class MainActivityTest { + + + + @Rule + public ActivityTestRule mActivityTestRule = new ActivityTestRule<>(MainActivity.class); + + @Test + public void clickLocationsNavBar() throws Exception{ + //Here we click the back button and then we check if the statisticsFragment is shown + mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().commit(); + onView(withId(R.id.locations)).perform(click()); + onView(withId(R.id.homeFragment)).check(matches(isDisplayed())); + } + + @Test + public void clickRouteNavBar() throws Exception{ + //Here we click the back button and then we check if the statisticsFragment is shown + mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().commit(); + onView(withId(R.id.routes)).perform(NavigationViewActions.navigateTo(R.id.routes)); + onView(withId(R.id.routeFragment)).check(matches(isDisplayed())); + } + + @Test + public void clickStatisticsNavBar() throws Exception{ + //Here we click the back button and then we check if the statisticsFragment is shown + mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().commit(); + onView(withId(R.id.statistics)).perform(click()); + onView(withId(R.id.statisticsFragment)).check(matches(isDisplayed())); + } + + @Test + public void clickSettingNavBar() throws Exception{ + //Here we click the back button and then we check if the statisticsFragment is shown + mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().commit(); + onView(withId(R.id.settings)).perform(click()); + onView(withId(R.id.settingFragment)).check(matches(isDisplayed())); + } + +}