Changed some unit test usernames to randomized string

This commit is contained in:
Mary Tran 2018-10-08 18:16:08 -04:00
parent a80c6d37dc
commit 555932b877

View file

@ -1,8 +1,8 @@
package com.uottawa.olympus.olympusservices; package com.uottawa.olympus.olympusservices;
import android.content.Context; //import android.content.Context;
import android.database.DatabaseUtils; //import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteDatabase; //import android.database.sqlite.SQLiteDatabase;
import org.junit.Test; import org.junit.Test;
@ -21,11 +21,11 @@ public class DBUnitTest {
@Test @Test
public void testAddAndDeleteUser(){ public void testAddAndDeleteUser(){
UserType originalUser, dbUser; UserType originalUser, dbUser;
boolean deleted; boolean deleted, addedOne, addedTwo;
originalUser = new User("mgarzon", "soccer", "Miguel", "Garzon"); originalUser = new User("mgarzon", "soccer", "Miguel", "Garzon");
dbHelper.addUser(originalUser); addedOne = dbHelper.addUser(originalUser);
dbUser = dbHelper.findUserByUsername("mgarzon"); dbUser = dbHelper.findUserByUsername("mgarzon");
assertEquals("User", dbUser.getClass().getSimpleName()); assertEquals("User", dbUser.getClass().getSimpleName());
@ -35,22 +35,25 @@ public class DBUnitTest {
assertEquals("Garzon", dbUser.getLastname()); assertEquals("Garzon", dbUser.getLastname());
originalUser = new ServiceProvider("jguzman", "seg2105", "Juan", "Guzman"); originalUser = new ServiceProvider("jbO4aBF4dC", "seg2105", "Juan", "Guzman");
dbHelper.addUser(originalUser); addedTwo = dbHelper.addUser(originalUser);
dbUser = dbHelper.findUserByUsername("jguzman"); dbUser = dbHelper.findUserByUsername("jbO4aBF4dC");
assertEquals("ServiceProvider", dbUser.getClass().getSimpleName()); assertEquals("ServiceProvider", dbUser.getClass().getSimpleName());
assertEquals("jguzman", dbUser.getUsername()); assertEquals("jbO4aBF4dC", dbUser.getUsername());
assertEquals("seg2105", dbUser.getPassword()); assertEquals("seg2105", dbUser.getPassword());
assertEquals("Juan", dbUser.getFirstname()); assertEquals("Juan", dbUser.getFirstname());
assertEquals("Guzman", dbUser.getLastname()); assertEquals("Guzman", dbUser.getLastname());
if (addedOne) {
deleted = dbHelper.deleteUser("mgarzon"); deleted = dbHelper.deleteUser("mgarzon");
assertTrue(deleted); assertTrue(deleted);
}
deleted = dbHelper.deleteUser("jguzman"); if (addedTwo) {
deleted = dbHelper.deleteUser("jbO4aBF4dC");
assertTrue(deleted); assertTrue(deleted);
}
} }
@ -59,14 +62,14 @@ public class DBUnitTest {
public void testAddDuplicateUsers(){ public void testAddDuplicateUsers(){
boolean added; boolean added;
added = dbHelper.addUser(new User("mgarzon", "soccer", "Miguel", "Garzon")); added = dbHelper.addUser(new User("jbO4aBF4dC", "soccer", "Miguel", "Garzon"));
assertTrue(added); assertTrue(added);
added = dbHelper.addUser(new User("mgarzon", "seg2105", "Miguel", "Garzon")); added = dbHelper.addUser(new User("jbO4aBF4dC", "seg2105", "Miguel", "Garzon"));
assertTrue(!added); assertTrue(!added);
added = dbHelper.addUser(new ServiceProvider("mgarzon", "seg2105", "Juan", "Guzman")); added = dbHelper.addUser(new ServiceProvider("jbO4aBF4dC", "seg2105", "Juan", "Guzman"));
assertTrue(!added); assertTrue(!added);
dbHelper.deleteUser("mgarzon"); dbHelper.deleteUser("jbO4aBF4dC");
} }
@Test @Test
@ -74,21 +77,22 @@ public class DBUnitTest {
boolean updated; boolean updated;
UserType dbUser; UserType dbUser;
dbHelper.addUser(new User("mgarzon", "soccer", "Miguel", "Garzon")); dbHelper.addUser(new User("jbO4aBF4dC", "soccer", "Miguel", "Garzon"));
updated = dbHelper.updateUserInfo("mgarzon", "soccer", "Juan", "Guzman"); updated = dbHelper.updateUserInfo("jbO4aBF4dC", "soccer", "Juan", "Guzman");
assertTrue(updated); assertTrue(updated);
dbUser = dbHelper.findUserByUsername("mgarzon"); dbUser = dbHelper.findUserByUsername("jbO4aBF4dC");
assertEquals("mgarzon", dbUser.getUsername()); assertEquals("jbO4aBF4dC", dbUser.getUsername());
assertEquals("soccer", dbUser.getPassword()); assertEquals("soccer", dbUser.getPassword());
assertEquals("Juan", dbUser.getFirstname()); assertEquals("Juan", dbUser.getFirstname());
assertEquals("Guzman", dbUser.getLastname()); assertEquals("Guzman", dbUser.getLastname());
updated = dbHelper.updateUserInfo("jguzman", "seg2105", "Juan", "Guzman"); //changed on character of username. Everything is case sensitive!
updated = dbHelper.updateUserInfo("JbO4aBF4dC", "seg2105", "Juan", "Guzman");
assertTrue(!updated); assertTrue(!updated);
dbHelper.deleteUser("mgarzon"); dbHelper.deleteUser("jbO4aBF4dC");
} }
} }