change_user_password method implemented and tested successful
parent
7df63b10ed
commit
a2e432119e
|
@ -212,6 +212,30 @@ public class System {
|
|||
|
||||
}
|
||||
|
||||
public boolean change_user_password(String old_password, String new_password, String new_password_authentication){
|
||||
if(!this.current_user.getPassword().equals(old_password))
|
||||
return false;
|
||||
|
||||
if(!new_password.equals(new_password_authentication))
|
||||
return false;
|
||||
|
||||
for(int i = 0; i< this.all_user.size(); i++)
|
||||
if(this.all_user.get(i).getUsername().equals(current_user.getUsername()))
|
||||
this.all_user.remove(i);
|
||||
|
||||
write_to_file(all_user_toString(), "src/main/resources/user_data.csv");
|
||||
write_to_file(all_user_toString(), "src/test/resources/user_data.csv");
|
||||
|
||||
this.current_user.setPassword(new_password);
|
||||
this.all_user.add(current_user);
|
||||
|
||||
write_to_file(all_user_toString(), "src/main/resources/user_data.csv");
|
||||
write_to_file(all_user_toString(), "src/test/resources/user_data.csv");
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public void write_to_file(ArrayList<String> lines, String file) {
|
||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) {
|
||||
for (int i = 0; i < lines.size() - 1; i++) {
|
||||
|
|
|
@ -30,6 +30,10 @@ public class Application {
|
|||
return running_system.change_user_details(username, password, hometown, zip, car_name, car_co2_km, car_avg_kmh, bike_avg_kmh);
|
||||
}
|
||||
|
||||
public boolean change_user_password(String old_password, String new_password, String new_password_authentication){
|
||||
return running_system.change_user_password(old_password, new_password, new_password_authentication);
|
||||
}
|
||||
|
||||
public ArrayList<String> search(String hometown_or_zip){
|
||||
return running_system.search(hometown_or_zip);
|
||||
}
|
||||
|
|
|
@ -139,11 +139,24 @@ public class SystemTest {
|
|||
public void change_user_details(){
|
||||
|
||||
current_system.sign_in_user("David", "123Esel");
|
||||
current_system.change_user_details("Enes", "Penis123", "Mannheim", "68161", "", "", "", "");
|
||||
current_system.change_user_details("Enes", "123Esel", "Mannheim", "68161", "", "", "", "");
|
||||
assertEquals("Enes", current_system.getDetails()[0]);
|
||||
current_system.change_user_details("David", "123Esel", "Mannheim", "68161", "AMG", "10", "100", "20");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void change_user_password(){
|
||||
|
||||
current_system.sign_in_user("David", "123Esel");
|
||||
assertEquals(true, current_system.change_user_password("123Esel", "Pizza69", "Pizza69"));
|
||||
assertEquals(true, current_system.change_user_password("Pizza69", "123Esel", "123Esel"));
|
||||
assertEquals(true, current_system.change_user_details("Enes", "123Esel", "Mannheim", "68161", "", "", "", ""));
|
||||
current_system.change_user_details("David", "123Esel", "Mannheim", "68161", "AMG", "10", "100", "20");
|
||||
|
||||
;
|
||||
|
||||
}
|
||||
/*
|
||||
Tests auf Basis von user_data.csv:
|
||||
Daniel;MTQwMURhbmllbA==;Mannheim;68305;BMW;1.5;50.4;40.2
|
||||
|
|
Loading…
Reference in New Issue