Skip to content

Commit

Permalink
Story 6 Task 3 #43 (#85)
Browse files Browse the repository at this point in the history
* Add BDD test for story 6

* Fix tests
  • Loading branch information
vs2961 committed Mar 17, 2023
1 parent 5cca505 commit 4c7f3dd
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
Expand Up @@ -394,4 +394,7 @@ public LocationView addLocationView(ConstraintLayout cl, User user) {
cl.addView(inflater);
return userView;
}
public Map<String, LocationView> getLocationsViews() {
return locationsViews;
}
}
@@ -1,6 +1,7 @@
package com.team34.cse_110_project_team_34;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import android.content.Context;
import android.widget.Button;
Expand All @@ -10,14 +11,20 @@
import androidx.test.core.app.ActivityScenario;
import androidx.test.core.app.ApplicationProvider;

import org.checkerframework.checker.units.qual.C;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;

import java.util.Map;

import database.Database;
import database.UserAPI;
import database.UserDao;
import database.UserRepository;
import model.User;
import view.LocationView;


/**
Expand All @@ -29,11 +36,14 @@ public class NewFriendTest {
ActivityScenario<NewFriendActivity> scenario;
UserRepository repo;

UserAPI api;

@Before
public void preTest() {
Context context = ApplicationProvider.getApplicationContext();
UserDao dao = Database.getInstance(context).getUserDao();
repo = new UserRepository(dao);
api = new UserAPI();
Database.getInstance(context).clearAllTables();

scenario = ActivityScenario.launch(NewFriendActivity.class);
Expand Down Expand Up @@ -69,4 +79,27 @@ public void testAddValidID() {
assertEquals(repo.existsLocal("point-nemo"), true);
});
}

/**
* Given that I have my friends and family’s unique IDs
* When I input these unique IDs into the app
* Then it should show all their names, even when I leave the app.
*/
@Test
public void testAddMultipleFriends() {
User user1 = new User("User 1", "pub_1", 0, 0);
User user2 = new User("User 2", "pub_2", 0, 0);
User user3 = new User("User 3", "pub_3", 0, 0);
repo.upsertLocal(user1);
repo.upsertLocal(user2);
repo.upsertLocal(user3);
ActivityScenario<CompassActivity> new_scenario = ActivityScenario.launch(CompassActivity.class);;
new_scenario.onActivity(activity -> {
Map<String, LocationView> location_views = activity.getLocationsViews();
assertEquals(location_views.size(), 3);
assertNotNull(location_views.get("pub_1"));
assertNotNull(location_views.get("pub_2"));
assertNotNull(location_views.get("pub_3"));
});
}
}

0 comments on commit 4c7f3dd

Please sign in to comment.