Everything works fine for now tests all successful

selims_dev_branch
Selim Eser 2024-06-11 15:53:54 +02:00
parent 4a811935d2
commit 0cd0be5fe9
4 changed files with 38 additions and 20 deletions

View File

@ -56,6 +56,20 @@ public class System {
return Base64.encodeBase64String(binary_data); return Base64.encodeBase64String(binary_data);
} }
public static int parseInt(String s) throws NumberFormatException{
if(s.equals(""))
return 0;
else
return Integer.parseInt(s);
}
public static double parseDouble(String s) throws NumberFormatException {
if(s.equals(""))
return 0;
else
return Double.parseDouble(s);
}
public void get_all_user() { public void get_all_user() {
String[] fileString = new String[8]; String[] fileString = new String[8];
@ -109,10 +123,10 @@ public class System {
double bike_avg_kmh; double bike_avg_kmh;
try{ try{
zip = Integer.parseInt(zipS); zip = parseInt(zipS);
car_l_100km = Double.parseDouble(car_l_100kmS); car_l_100km = parseDouble(car_l_100kmS);
car_avg_kmh = Double.parseDouble(car_avg_kmhS); car_avg_kmh = parseDouble(car_avg_kmhS);
bike_avg_kmh = Double.parseDouble(bike_avg_kmhS); bike_avg_kmh = parseDouble(bike_avg_kmhS);
} catch (NumberFormatException n){ } catch (NumberFormatException n){
return false; return false;
} }
@ -145,7 +159,7 @@ public class System {
return true; return true;
} }
public boolean change_user_details(String username, String password, String hometown, String zipS, public boolean change_user_details(String username, String password, String hometown, String zipS,
String car_name, String car_l_100kmS, String car_avg_kmhS, String bike_avg_kmhS){ String car_name, String car_l_100kmS, String car_avg_kmhS, String bike_avg_kmhS){
@ -155,10 +169,10 @@ public class System {
double bike_avg_kmh; double bike_avg_kmh;
try{ try{
zip = Integer.parseInt(zipS); zip = parseInt(zipS);
car_l_100km = Double.parseDouble(car_l_100kmS); car_l_100km = parseDouble(car_l_100kmS);
car_avg_kmh = Double.parseDouble(car_avg_kmhS); car_avg_kmh = parseDouble(car_avg_kmhS);
bike_avg_kmh = Double.parseDouble(bike_avg_kmhS); bike_avg_kmh = parseDouble(bike_avg_kmhS);
} catch (NumberFormatException n){ } catch (NumberFormatException n){
return false; return false;
} }
@ -182,12 +196,15 @@ public class System {
if(!bool) if(!bool)
return false; return false;
this.all_user.remove(this.current_user);
this.current_user = new User(username, password, hometown, zip, car_name, car_l_100km, car_avg_kmh, bike_avg_kmh); 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/main/resources/user_data.csv");
write_to_file(all_user_toString(), "src/test/resources/user_data.csv"); write_to_file(all_user_toString(), "src/test/resources/user_data.csv");
this.current_user = new User(username, password, hometown, zip, car_name, car_l_100km, car_avg_kmh, bike_avg_kmh);
this.all_user.add(current_user); 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/main/resources/user_data.csv");

View File

@ -1,2 +1,2 @@
Daniel;MTQwMURhbmllbA==;Mannheim;68305;BMW;1.5;50.4;40.2 Daniel;MTQwMURhbmllbA==;Mannheim;68305;BMW;1.5;50.4;40.2
David;MTIzRXNlbA==;Mannheim;68305;BMW;1.5;50.4;40.2 David;MTIzRXNlbA==;Mannheim;68161;AMG;10.0;300.0;20.0
1 Daniel MTQwMURhbmllbA== Mannheim 68305 BMW 1.5 50.4 40.2
2 David MTIzRXNlbA== Mannheim 68305 68161 BMW AMG 1.5 10.0 50.4 300.0 40.2 20.0

View File

@ -122,7 +122,7 @@ public class SystemTest {
} }
/*@Test @Test
public void sign_up_user(){ public void sign_up_user(){
// Username darf nicht doppelt vorkommen! // Username darf nicht doppelt vorkommen!
assertEquals(false, current_system.sign_up_user("David","123Esel","Mannheim","68161","AMG","10","300","20")); assertEquals(false, current_system.sign_up_user("David","123Esel","Mannheim","68161","AMG","10","300","20"));
@ -134,19 +134,20 @@ public class SystemTest {
assertEquals("Lukas",current_system.getDetails()[0]); assertEquals("Lukas",current_system.getDetails()[0]);
current_system.sign_out_user(); current_system.sign_out_user();
assertEquals("",current_system.getDetails()[0]); assertEquals("",current_system.getDetails()[0]);
}*/ }
@Test @Test
public void change_user_details(){ public void change_user_details(){
current_system.sign_in_user("David", "123Esel"); current_system.sign_in_user("David", "123Esel");
current_system.change_user_details(null, null, null, null, null, null, null, null); current_system.change_user_details("Enes", "Penis123", "Mannheim", "68161", "", "", "", "");
assertEquals(current_system, STR); assertEquals("Enes", current_system.getDetails()[0]);
} }
/*
Tests auf Basis von user_data.csv: Daniel;MTQwMURhbmllbA==;Mannheim;68305;BMW;1.5;50.4;40.2
David;MTIzRXNlbA==;Mannheim;68161;AMG;10.0;300.0;20.0
*/
} }

View File

@ -1,2 +1,2 @@
Daniel;MTQwMURhbmllbA==;Mannheim;68305;BMW;1.5;50.4;40.2 Daniel;MTQwMURhbmllbA==;Mannheim;68305;BMW;1.5;50.4;40.2
David;MTIzRXNlbA==;Mannheim;68305;BMW;1.5;50.4;40.2 David;MTIzRXNlbA==;Mannheim;68161;AMG;10.0;300.0;20.0
1 Daniel MTQwMURhbmllbA== Mannheim 68305 BMW 1.5 50.4 40.2
2 David MTIzRXNlbA== Mannheim 68305 68161 BMW AMG 1.5 10.0 50.4 300.0 40.2 20.0