Merge branch 'develop' of https://github.com/SemvdH/Next-Location into develop

This commit is contained in:
Sem van der Hoeven
2021-01-06 19:25:15 +01:00
19 changed files with 125 additions and 275 deletions

View File

@@ -41,8 +41,8 @@ public class CouponFragmentTest {
//the button "Klaar" is shown then the test works
mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.mainActivity, new CouponFragment()).commit();
onView(withId(R.id.coupon_recyclerview)).perform(RecyclerViewActions.actionOnItemAtPosition(1, click()));
onView(withText("activeren")).inRoot(RootMatchers.isDialog()).perform(click());
onView(withText("Klaar")).inRoot(RootMatchers.isDialog()).check(matches(isDisplayed()));
onView(withId(R.string.activate)).inRoot(RootMatchers.isDialog()).perform(click());
onView(withId(R.string.done)).inRoot(RootMatchers.isDialog()).check(matches(isDisplayed()));
}

View File

@@ -55,16 +55,13 @@ public class SettingsFragmentTest {
public void buttonTest(){
mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.mainActivity, new SettingsFragment()).commit();
onView(withId(R.id.settingsImperialButton)).check(matches(isClickable()));
onView(withId(R.id.settingsOldButton)).check(matches(isClickable()));
onView(withId(R.id.settingsEyesButton)).check(matches(isClickable()));
onView(withId(R.id.BigFont)).check(matches(isClickable()));
onView(withId(R.id.settingsImperialButton)).perform(click());
onView(withId(R.id.settingsImperialButton)).check(matches(isChecked()));
onView(withId(R.id.settingsOldButton)).perform(click());
onView(withId(R.id.settingsOldButton)).check(matches(isChecked()));
onView(withId(R.id.settingsEyesButton)).perform(click());
onView(withId(R.id.settingsEyesButton)).check(matches(isChecked()));
onView(withId(R.id.BigFont)).perform(click());
onView(withId(R.id.BigFont)).check(matches(isChecked()));
}
}

View File

@@ -113,10 +113,10 @@ public class MainActivity extends AppCompatActivity implements Refreshable {
* refreshes bottom navigation
*/
@Override
public void refresh() {
public void refreshAndNavigateTo(int id) {
bottomNav.getMenu().clear();
bottomNav.inflateMenu(R.menu.navmenu);
bottomNav.setSelectedItemId(R.id.settings);
bottomNav.setSelectedItemId(id);
}
private View.OnClickListener onInfoClickListener = new View.OnClickListener() {

View File

@@ -26,7 +26,7 @@ public class CouponFragment extends Fragment {
private RecyclerView.LayoutManager layoutManager;
private List<Coupon> couponList;
private CouponAdapter couponAdapter;
private ImageButton imageButton;
private ImageButton backButton;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -37,18 +37,22 @@ public class CouponFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_coupon, container, false);
//Makes the recyclerview
this.couponRecyclerView = view.findViewById(R.id.coupon_recyclerview);
this.couponRecyclerView.setHasFixedSize(true);
this.layoutManager = new LinearLayoutManager(this.getContext());
//Loads the couponList
CouponListManager.INSTANCE.setContext(this.getContext());
CouponListManager.INSTANCE.load();
this.couponList = CouponListManager.INSTANCE.getCouponList();
this.couponAdapter = new CouponAdapter(this.getContext(), this.couponList, clickedPosition -> showPopup(this.couponList.get(clickedPosition)));
this.imageButton = view.findViewById(R.id.coupon_back_button);
this.imageButton.setOnClickListener(v -> {
//Initialises the back button
this.backButton = view.findViewById(R.id.coupon_back_button);
this.backButton.setOnClickListener(v -> {
StatisticFragment statisticFragment = new StatisticFragment();
((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, statisticFragment).addToBackStack(null).commit();
});
@@ -58,6 +62,10 @@ public class CouponFragment extends Fragment {
return view;
}
/**
* shows the popup of a coupon
* @param coupon the coupon that will be displayed
*/
private void showPopup(Coupon coupon) {
AlertDialog.Builder activateBuilder = new AlertDialog.Builder(getContext());
AlertDialog.Builder couponCodeBuilder = new AlertDialog.Builder(getContext());

View File

@@ -1,7 +1,6 @@
package com.a1.nextlocation.fragments;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
@@ -22,14 +21,13 @@ import com.a1.nextlocation.recyclerview.LocationListManager;
public class LocationDetailFragment extends Fragment {
private static final String TAG = LocationDetailFragment.class.getCanonicalName();
private ImageButton imageButton;
private ImageButton backButton;
private Location location;
private TextView titelText;
private TextView detailText;
private ImageView locationImage;
public LocationDetailFragment() {
}
public LocationDetailFragment(Location location) {
@@ -52,12 +50,14 @@ public class LocationDetailFragment extends Fragment {
this.detailText = view.findViewById(R.id.detail_location_text);
this.detailText.setText(location.getDescription());
this.imageButton = view.findViewById(R.id.detail_location_back_button);
this.imageButton.setOnClickListener(v -> {
//Initialises the back button
this.backButton = view.findViewById(R.id.detail_location_back_button);
this.backButton.setOnClickListener(v -> {
LocationFragment locationFragment = new LocationFragment();
((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, locationFragment).addToBackStack(null).commit();
});
//Logs the location
if (location != null) {
Log.d(TAG, "onCreateView: the location has a name of: " + location.getName());
}
@@ -71,8 +71,4 @@ public class LocationDetailFragment extends Fragment {
return view;
}
public void setLocation(Location location) {
this.location = location;
}
}

View File

@@ -1,6 +1,5 @@
package com.a1.nextlocation.fragments;
import android.media.Image;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
@@ -25,7 +24,7 @@ public class LocationFragment extends Fragment {
private LocationAdapter locationAdapter;
private RecyclerView.LayoutManager layoutManager;
private List<Location> locationList;
private ImageButton imageButton;
private ImageButton backButton;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -41,22 +40,24 @@ public class LocationFragment extends Fragment {
this.locationRecyclerView.setHasFixedSize(true);
this.layoutManager = new LinearLayoutManager(this.getContext());
this.imageButton = view.findViewById(R.id.location_back_button);
this.imageButton.setOnClickListener(v -> {
//Initialised the back button
this.backButton = view.findViewById(R.id.location_back_button);
this.backButton.setOnClickListener(v -> {
HomeFragment homeFragment = new HomeFragment();
((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, homeFragment).addToBackStack(null).commit();
});
//Loads the location list
LocationListManager.INSTANCE.setContext(this.getContext());
LocationListManager.INSTANCE.load();
this.locationList = LocationListManager.INSTANCE.getLocationList();
//Initialises the adapter
this.locationAdapter = new LocationAdapter(this.getContext(), this.locationList, clickedPosition -> {
LocationDetailFragment locationDetailFragment = new LocationDetailFragment();
locationDetailFragment.setLocation(this.locationList.get(clickedPosition));
LocationDetailFragment locationDetailFragment = new LocationDetailFragment(this.locationList.get(clickedPosition));
Bundle locationBundle = new Bundle();
//Gives the clicked location to the adapter
locationBundle.putParcelable("location", this.locationList.get(clickedPosition));
locationDetailFragment.setLocation(this.locationList.get(clickedPosition));
locationDetailFragment.setArguments(locationBundle);
((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, locationDetailFragment).addToBackStack(null).commit();
});

View File

@@ -1,5 +1,5 @@
package com.a1.nextlocation.fragments;
public interface Refreshable {
void refresh();
void refreshAndNavigateTo(int id);
}

View File

@@ -22,14 +22,22 @@ import com.a1.nextlocation.data.Route;
import com.a1.nextlocation.data.RouteHandler;
import com.a1.nextlocation.network.ApiHandler;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
public class RouteDetailFragment extends Fragment {
private Route route;
private ImageView imageView;
private Refreshable refreshable;
@Override
public void onAttach(@NotNull Context context) {
super.onAttach(context);
if (context instanceof Refreshable)
this.refreshable = (Refreshable) context;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -44,10 +52,11 @@ public class RouteDetailFragment extends Fragment {
this.route = getArguments().getParcelable("route");
}
this.imageView = view.findViewById(R.id.route_detail_image);
Context context = this.imageView.getContext();
//Sets the image of the RouteDetail
ImageView imageView = view.findViewById(R.id.route_detail_image);
Context context = imageView.getContext();
int id = context.getResources().getIdentifier(this.route.getImageURL(), "drawable", context.getPackageName());
this.imageView.setImageResource(id);
imageView.setImageResource(id);
TextView routeName = view.findViewById(R.id.route_title);
routeName.setText(this.route.getName());
@@ -59,8 +68,9 @@ public class RouteDetailFragment extends Fragment {
String distance_tekst = getResources().getString(R.string.total_distance_route);
totalDistance.setText(distance_tekst + " " + calculateRoute(this.route.getLocations()) + "m");
ImageButton imageButton = view.findViewById(R.id.route_detail_back_button);
imageButton.setOnClickListener(v -> {
//Initialises the back button
ImageButton backButton = view.findViewById(R.id.route_detail_back_button);
backButton.setOnClickListener(v -> {
RouteFragment routeFragment = new RouteFragment();
((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, routeFragment).addToBackStack(null).commit();
});
@@ -79,7 +89,8 @@ public class RouteDetailFragment extends Fragment {
ApiHandler.INSTANCE.getDirections(route);
RouteHandler.INSTANCE.followRoute(route);
Toast.makeText(requireContext(),"Route started!",Toast.LENGTH_SHORT).show();
((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, new HomeFragment()).addToBackStack(null).commit();
// navigates to the HomeFragment and refreshes the BottomNavigation
refreshable.refreshAndNavigateTo(R.id.locations);
}
/**

View File

@@ -30,11 +30,7 @@ import com.a1.nextlocation.network.DirectionsListener;
public class RouteFragment extends Fragment {
private static final String TAG = RouteFragment.class.getCanonicalName();
private RecyclerView routeRecyclerView;
private RecyclerView.LayoutManager layoutManager;
private List<Route> routeList;
private RouteAdapter routeAdapter;
private ImageButton imageButton;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -46,15 +42,16 @@ public class RouteFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_route, container, false);
this.routeRecyclerView = view.findViewById(R.id.route_recyclerview);
this.routeRecyclerView.setHasFixedSize(true);
this.layoutManager = new LinearLayoutManager(this.getContext());
RecyclerView routeRecyclerView = view.findViewById(R.id.route_recyclerview);
routeRecyclerView.setHasFixedSize(true);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this.getContext());
RouteListManager.INSTANCE.setContext(this.getContext());
RouteListManager.INSTANCE.load();
this.routeList = RouteListManager.INSTANCE.getRouteList();
this.routeAdapter = new RouteAdapter(this.getContext(), this.routeList, clickedPosition -> {
//Sets the adapter for the route
RouteAdapter routeAdapter = new RouteAdapter(this.getContext(), this.routeList, clickedPosition -> {
RouteDetailFragment routeDetailFragment = new RouteDetailFragment();
Bundle routeBundle = new Bundle();
routeBundle.putParcelable("route", this.routeList.get(clickedPosition));
@@ -62,31 +59,19 @@ public class RouteFragment extends Fragment {
((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, routeDetailFragment).addToBackStack(null).commit();
});
this.imageButton = view.findViewById(R.id.route_back_button);
this.imageButton.setOnClickListener(v -> {
ImageButton backButton = view.findViewById(R.id.route_back_button);
backButton.setOnClickListener(v -> {
HomeFragment homeFragment = new HomeFragment();
((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, homeFragment).addToBackStack(null).commit();
});
this.routeRecyclerView.setLayoutManager(this.layoutManager);
this.routeRecyclerView.setAdapter(this.routeAdapter);
routeRecyclerView.setLayoutManager(layoutManager);
routeRecyclerView.setAdapter(routeAdapter);
return view;
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// ApiHandler.INSTANCE.getDirections(51.49017262451581, 4.289038164073164,51.47337383133509, 4.303535222390562);
// Route r = new Route("test");
// r.addLocation(new Location("test",51.574473766034046, 4.7628379328055175,"route",null));
// r.addLocation(new Location("test",51.577354223919876, 4.771120593941968,"route",null));
// r.addLocation(new Location("test",51.573033468635174, 4.782750651807139,"route",null));
// r.addLocation(new Location("test",51.56519104881196, 4.748246716295709,"route",null));
// r.addLocation(new Location("test",51.57367360644676, 4.74404101271347,"route",null));
// r.addLocation(new Location("test",51.57852769146427, 4.739878224473907,"route",null));
//// r.addLocation(new Location("test",51.489063681658145, 4.289596063527951,"route",null));
//// r.addLocation(new Location("test",51.483012677667766, 4.28003245468457,"route",null));
// ApiHandler.INSTANCE.getDirections(r);
}
}

View File

@@ -1,5 +1,6 @@
package com.a1.nextlocation.fragments;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
@@ -27,7 +28,6 @@ import java.util.Locale;
public class SettingsFragment extends Fragment {
private SharedPreferences.Editor editor;
private ImageView imageButton;
SwitchCompat fontChanger;
private Refreshable refreshable;
@@ -37,6 +37,7 @@ public class SettingsFragment extends Fragment {
refreshable = (Refreshable) context;
}
@SuppressLint("CommitPrefEdits")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -51,14 +52,14 @@ public class SettingsFragment extends Fragment {
initializeLanguageDropdown(view);
this.imageButton = view.findViewById(R.id.settings_back_button);
this.imageButton.setOnClickListener(v -> {
//Initialises back button
ImageView backButton = view.findViewById(R.id.settings_back_button);
backButton.setOnClickListener(v -> {
HomeFragment homeFragment = new HomeFragment();
((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, homeFragment).addToBackStack(null).commit();
});
fontChanger = view.findViewById(R.id.BigFont);
this.fontChanger = view.findViewById(R.id.BigFont);
SharedPreferences sharedPreferences = requireActivity().getSharedPreferences("com.a1.nextlocation",0);
SharedPreferences.Editor editor = sharedPreferences.edit();
@@ -158,7 +159,7 @@ public class SettingsFragment extends Fragment {
fragmentTransaction.attach(currentFragment);
fragmentTransaction.commit();
refreshable.refresh();
refreshable.refreshAndNavigateTo(R.id.settings);
}
/**

View File

@@ -1,5 +1,6 @@
package com.a1.nextlocation.fragments;
import android.annotation.SuppressLint;
import android.os.Bundle;
import androidx.constraintlayout.widget.ConstraintLayout;
@@ -22,16 +23,12 @@ import java.util.List;
public class StatisticFragment extends Fragment {
private List<Coupon> couponList;
private ImageView imageButton;
private ImageView couponButton;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@SuppressLint({"DefaultLocale", "SetTextI18n"})
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_statistic, container, false);
@@ -51,24 +48,27 @@ public class StatisticFragment extends Fragment {
timeText.setText(p2 + ":" + p3 + ":" + p1);
this.couponList = CouponListManager.INSTANCE.getCouponList();
CouponAdapter adapter = new CouponAdapter(this.getContext(), this.couponList);
//loads the couponList
List<Coupon> couponList = CouponListManager.INSTANCE.getCouponList();
CouponAdapter adapter = new CouponAdapter(this.getContext(), couponList);
TextView couponNumber = view.findViewById(R.id.couponAmount);
couponNumber.setText(String.valueOf(adapter.getItemCount()));
this.imageButton = view.findViewById(R.id.statistics_back_button);
this.imageButton.setOnClickListener(v -> {
//Initialises the back button
ImageView backButton = view.findViewById(R.id.statistics_back_button);
backButton.setOnClickListener(v -> {
HomeFragment homeFragment = new HomeFragment();
((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, homeFragment).addToBackStack(null).commit();
});
this.couponButton = view.findViewById(R.id.coupon_button);
this.couponButton.setOnClickListener(v -> {
//Initialises the coupon button
ImageView couponButton = view.findViewById(R.id.coupon_button);
couponButton.setOnClickListener(v -> {
CouponFragment couponFragment = new CouponFragment();
((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, couponFragment).addToBackStack(null).commit();
});
//Makes the constraintlayout clickable and opens the same layout as the coupon button
ConstraintLayout constraintLayout = view.findViewById(R.id.Box4);
constraintLayout.setOnClickListener(v -> {
CouponFragment couponFragment = new CouponFragment();

View File

@@ -27,17 +27,19 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView
class CouponViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
private TextView couponCode;
private TextView couponReward;
public CouponViewHolder(@NonNull View itemView) {
super(itemView);
itemView.setOnClickListener(this);
}
/**
* Sets the text of the coupon
* @param text the text that will be set
*/
public void setTextViewName(String text){
this.couponReward = itemView.findViewById(R.id.coupon_name);
this.couponReward.setText(text);
TextView couponReward = itemView.findViewById(R.id.coupon_name);
couponReward.setText(text);
}
@Override

View File

@@ -22,10 +22,9 @@ public enum CouponListManager {
return couponList;
}
public Coupon getCoupon(int place) {
return couponList.get(place);
}
/**
* Prepares the list for loading
*/
public void load(){
CouponLoader couponLoader = new CouponLoader(this.context);
this.couponList = couponLoader.load();

View File

@@ -18,6 +18,10 @@ public class CouponLoader implements Loader<List<Coupon>> {
this.context = context;
}
/**
* Loads the Arraylist of coupons out of the JSON
* @return Arraylist of coupons
*/
@Override
public ArrayList<Coupon> load() {
FileIO<ArrayList<Coupon>> fileIO = new FileIO<>();

View File

@@ -1,42 +0,0 @@
package com.a1.nextlocation.recyclerview;
import android.graphics.Point;
import android.graphics.drawable.Drawable;
import org.osmdroid.api.IMapView;
import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.ItemizedOverlay;
import org.osmdroid.views.overlay.OverlayItem;
import java.util.ArrayList;
public class CustomOverlay extends ItemizedOverlay<OverlayItem> {
private final MapView mapView;
private ArrayList<OverlayItem> overlayItems = new ArrayList<>();
public CustomOverlay(Drawable pDefaultMarker, MapView mapView) {
super(pDefaultMarker);
this.mapView = mapView;
}
public void addOverlayItem(OverlayItem item) {
overlayItems.add(item);
populate();
}
@Override
protected OverlayItem createItem(int i) {
return overlayItems.get(i);
}
@Override
public int size() {
return overlayItems.size();
}
@Override
public boolean onSnapToItem(int x, int y, Point snapPoint, IMapView mapView) {
return true;
}
}

View File

@@ -42,11 +42,19 @@ public class LocationAdapter extends RecyclerView.Adapter<LocationAdapter.Locati
clickListener.onItemClick(getAdapterPosition());
}
/**
* Sets the text of the location name
* @param text the text that will be set
*/
public void setTextViewText(String text){
this.locationName = itemView.findViewById(R.id.location_name);
locationName.setText(text);
this.locationName.setText(text);
}
/**
* Sets the image of the locatoin
* @param text the text of the image filename
*/
public void setImageViewImage(String text){
this.locationImage = itemView.findViewById(R.id.location_image);
Context context = locationImage.getContext();

View File

@@ -132,7 +132,7 @@
android:layout_height="70dp"
android:layout_marginHorizontal="20dp"
android:background="@color/secondaryColour"
app:layout_constraintBottom_toTopOf="@id/Box4"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/Box2"
@@ -171,52 +171,4 @@
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/Box4"
android:layout_width="match_parent"
android:layout_height="70dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/Box3"
android:background="@color/secondaryColour"
android:layout_marginHorizontal="20dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/colorblind"
android:textColor="@color/black"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@id/Balk4"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/Balk4"
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/black"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/settingsEyesButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@id/Balk4"
app:layout_constraintTop_toTopOf="parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -11,39 +11,48 @@ import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotSame;
public class DataTest {
private Data Data;
private Data data;
@Before
public void init(){
Data = Data.INSTANCE;
data = Data.INSTANCE;
}
@Test
public void testDistance(){
Data.addDistance(2356.234);
data.addDistance(2356.234);
double expected = 2356.234;
assertEquals(expected, Data.getDistanceTraveled(), 0.01);
Data.addDistance(234342.1);
assertNotEquals(expected, Data.getDistanceTraveled());
assertEquals(expected, data.getDistanceTraveled(), 0.01);
data.addDistance(234342.1);
assertNotEquals(expected, data.getDistanceTraveled());
}
@Test
public void testTimeWalked(){
Data.addTimeWalked(3456);
data.addTimeWalked(3456);
long expected = 3456;
assertEquals(expected, Data.getTimeWalked());
Data.addTimeWalked(3445);
assertNotEquals(expected, Data.getTimeWalked());
assertEquals(expected, data.getTotalTime());
data.addTimeWalked(3445);
assertNotEquals(expected, data.getTotalTime());
}
@Test
public void testVisitedLocation(){
Location testLocation = new Location("test", "test", "test", "test");
Data.visitLocation(testLocation);
data.visitLocation(testLocation);
int expected = 1;
assertEquals(expected, Data.getLocationsVisited());
Data.visitLocation(new Location("TESTFORFALSE", "TESTFORFALSE", "TESTFORFALSE", "TESTFORFALSE"));
assertNotEquals(expected, Data.getLocationsVisited());
assertEquals(expected, data.getLocationsVisited());
data.visitLocation(new Location("TESTFORFALSE", "TESTFORFALSE", "TESTFORFALSE", "TESTFORFALSE"));
assertNotEquals(expected, data.getLocationsVisited());
}
@Test
public void testZoom(){
data.setZoom(234.63);
double expected = 234.63;
assertEquals(expected, data.getZoom(), 0.01);
data.setZoom(342.55);
assertNotEquals(expected, data.getZoom());
}
}

View File

@@ -1,81 +0,0 @@
package com.a1.nextlocation;
import com.a1.nextlocation.data.Coupon;
import com.a1.nextlocation.data.Data;
import com.a1.nextlocation.data.Location;
import com.a1.nextlocation.data.Route;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.List;
public class DataTestClass {
private Data data;
@Before
public void init(){
data = new Data();
}
@Test
public void testSetDistanceTraveled() {
data.setDistanceTraveled(100);
int expected = 100;
assertEquals(expected, data.getDistanceTraveled(), 0.1);
}
@Test
public void testSetLocationsVisited() {
data.setLocationsVisited(16);
int expected = 16;
assertEquals(expected, data.getLocationsVisited());
}
@Test
public void testSetTotalTime() {
data.setTotalTime(120);
int expected = 120;
assertEquals(expected, data.getTotalTime());
}
@Test
public void testSetCouponList() {
List<Coupon> expected = new ArrayList<>();
expected.add(new Coupon("CODE1", "REWARD1"));
expected.add(new Coupon("CODE2", "REWARD2"));
expected.add(new Coupon("CODE3", "REWARD3"));
data.setCouponList(expected);
assertEquals(expected, data.getCouponList());
}
@Test
public void testNextLocation() {
Location expected = new Location("name1", "cord1", "desc1", null);
data.setNextLocation(expected);
assertEquals(expected, data.getNextLocation());
}
@Test
public void testLastLocation() {
Location expected = new Location("name2", "cord2", "desc2", null);
data.setLastLocation(expected);
assertEquals(expected, data.getLastLocation());
}
@Test
public void testCurrentRoute() {
Route expected = new Route("testRoute1");
data.setCurrentRoute(expected);
assertEquals(expected, data.getCurrentRoute());
}
}