Merge branch 'Tests' of https://github.com/SemvdH/Next-Location into Tests
This commit is contained in:
@@ -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<MainActivity> 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()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<DirectionsStep> expected = new ArrayList<>();
|
||||
directionsResult.addStep(new DirectionsStep());
|
||||
directionsResult.addStep(new DirectionsStep());
|
||||
directionsResult.addStep(new DirectionsStep());
|
||||
directionsResult.setSteps(expected);
|
||||
|
||||
assertEquals(expected, directionsResult.getSteps());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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<Integer> 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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user