Commit 598b029d authored by Kevin Roy's avatar Kevin Roy

Add method getAllUser() Implement : #29

Add the method getAllUser, return a list of all the person.
Add the test method in UserManagerTest
parent 307fa609
......@@ -5,8 +5,7 @@ import fr.unantes.software.construction.people.Person;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
public class UserManager {
......@@ -52,6 +51,22 @@ public class UserManager {
return namesToUsers.containsKey(person.getName());
}
/**
* Give all users.
* @return return a list of all users.
*/
public List<Person> getAllUser(){
List<Person> allUser = new ArrayList<>();
for (Map.Entry<String, Person> entry : namesToUsers.entrySet()) {
allUser.add(entry.getValue());
}
return allUser;
}
/**
* Add a new user to the manager
* @param person - User to add
......@@ -112,4 +127,5 @@ public class UserManager {
}
package fr.unantes.software.construction.security;
import fr.unantes.software.construction.people.Admin;
import fr.unantes.software.construction.people.Agent;
import fr.unantes.software.construction.people.Person;
import org.junit.jupiter.api.AfterEach;
......@@ -24,17 +25,35 @@ class UserManagerTest {
@Test
void testHasUserAndAddUser(){
Person agent1 =new Agent("je_suis_agent1");
Person agent1 =new Agent("je_suis_agent1");
userManager_test.addUser(agent1,"je_suis_mdp1");
assertTrue(userManager_test.hasUser(agent1));
}
@Test
void testIfGetAllUserReturnAListOfAllUser(){
Person agent1 =new Agent("je_suis_agent1");
userManager_test.addUser(agent1,"je_suis_mdp1");
Person admin1 =new Admin("je_suis_admin1");
userManager_test.addUser(admin1,"je_suis_mdp2");
//Test if the size is the good one.
assertTrue(2==userManager_test.getAllUser().size());
//Test if the agent1 is in the list
assertTrue(userManager_test.getAllUser().contains(agent1));
//Test if the admin1 is in the
assertTrue(userManager_test.getAllUser().contains(admin1));
}
@AfterEach
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment