From a38c77533a6471d81473713cf8504d565c4012e4 Mon Sep 17 00:00:00 2001 From: Selim Eser <2211482@stud.hs-mannheim.de> Date: Wed, 12 Jun 2024 00:08:30 +0200 Subject: [PATCH 1/7] Tests fixed to automatically correcting user_data.csv --- src/main/resources/user_data.csv | 2 +- src/test/java/de/hs_mannheim/domain/SystemTest.java | 5 +++-- src/test/resources/user_data.csv | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/resources/user_data.csv b/src/main/resources/user_data.csv index 912c767..064684c 100644 --- a/src/main/resources/user_data.csv +++ b/src/main/resources/user_data.csv @@ -1,2 +1,2 @@ Daniel;MTQwMURhbmllbA==;Mannheim;68305;BMW;1.5;50.4;40.2 -David;MTIzRXNlbA==;Mannheim;68161;AMG;10.0;300.0;20.0 \ No newline at end of file +David;MTIzRXNlbA==;Mannheim;68161;AMG;10.0;100.0;20.0 \ No newline at end of file diff --git a/src/test/java/de/hs_mannheim/domain/SystemTest.java b/src/test/java/de/hs_mannheim/domain/SystemTest.java index 3059507..ff0b147 100644 --- a/src/test/java/de/hs_mannheim/domain/SystemTest.java +++ b/src/test/java/de/hs_mannheim/domain/SystemTest.java @@ -146,12 +146,13 @@ public class SystemTest { current_system.sign_in_user("David", "123Esel"); current_system.change_user_details("Enes", "Penis123", "Mannheim", "68161", "", "", "", ""); assertEquals("Enes", current_system.getDetails()[0]); - + 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 -David;MTIzRXNlbA==;Mannheim;68161;AMG;10.0;300.0;20.0 +David;MTIzRXNlbA==;Mannheim;68161;AMG;10.0;100.0;20.0 */ diff --git a/src/test/resources/user_data.csv b/src/test/resources/user_data.csv index 912c767..064684c 100644 --- a/src/test/resources/user_data.csv +++ b/src/test/resources/user_data.csv @@ -1,2 +1,2 @@ Daniel;MTQwMURhbmllbA==;Mannheim;68305;BMW;1.5;50.4;40.2 -David;MTIzRXNlbA==;Mannheim;68161;AMG;10.0;300.0;20.0 \ No newline at end of file +David;MTIzRXNlbA==;Mannheim;68161;AMG;10.0;100.0;20.0 \ No newline at end of file From f90eeb68415a805a088204186b97c1f4cd0d685d Mon Sep 17 00:00:00 2001 From: Selim Eser <2211482@stud.hs-mannheim.de> Date: Wed, 12 Jun 2024 00:16:46 +0200 Subject: [PATCH 2/7] Removed unnecessary code in tests --- src/test/java/de/hs_mannheim/domain/SystemTest.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/test/java/de/hs_mannheim/domain/SystemTest.java b/src/test/java/de/hs_mannheim/domain/SystemTest.java index ff0b147..8a47749 100644 --- a/src/test/java/de/hs_mannheim/domain/SystemTest.java +++ b/src/test/java/de/hs_mannheim/domain/SystemTest.java @@ -51,9 +51,6 @@ public class SystemTest { current_system.sign_in_user("David","123Esel"); - current_system.set_current_user_car_avg_kmh(100); - current_system.set_current_user_bike_avg_kmh(20); - assertEquals("0.885 h", current_system.travel_time("60306")[0]); // Frankfurt mit Auto assertEquals("4.423 h", current_system.travel_time("60306")[1]); // Frankfurt mit Fahrrad @@ -66,9 +63,6 @@ public class SystemTest { current_system.sign_in_user("David","123Esel"); - current_system.set_current_user_car_avg_kmh(100); - current_system.set_current_user_car_l_100km(10); - assertEquals("8.846 l", current_system.calc_l_consumption("60306")); // Kraftstoffverbrauch nach Frankfurt assertEquals("58.111 l", current_system.calc_l_consumption("20095")); // Kraftstoffverbrauch nach Hamburg assertEquals("60.361 l", current_system.calc_l_consumption("10115")); // Kraftstoffverbrauch nach Berlin @@ -138,6 +132,7 @@ public class SystemTest { assertEquals("Lukas",current_system.getDetails()[0]); current_system.sign_out_user(); assertEquals("",current_system.getDetails()[0]); + assertEquals(true, current_system.sign_in_user("Lukas","123Esel")); } @Test From ed2acc006527f1cdcf731a9991c921fc8b1001f4 Mon Sep 17 00:00:00 2001 From: Selim Eser <2211482@stud.hs-mannheim.de> Date: Wed, 12 Jun 2024 01:30:09 +0200 Subject: [PATCH 3/7] Fixed some pmd violations and made the build successful after checking the rest --- pom.xml | 3 +++ .../java/de/hs_mannheim/domain/System.java | 18 +++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 78cbbe7..dd60249 100644 --- a/pom.xml +++ b/pom.xml @@ -100,6 +100,9 @@ org.apache.maven.plugins maven-pmd-plugin 3.22.0 + + false + verify diff --git a/src/main/java/de/hs_mannheim/domain/System.java b/src/main/java/de/hs_mannheim/domain/System.java index ca4b468..2233efa 100644 --- a/src/main/java/de/hs_mannheim/domain/System.java +++ b/src/main/java/de/hs_mannheim/domain/System.java @@ -81,6 +81,7 @@ public class System { Double.parseDouble(fileString[7]))); } } catch (Exception e) { + // } } @@ -215,7 +216,9 @@ public class System { writer.newLine(); } writer.write(lines.getLast()); - } catch (IOException e) {} + } catch (IOException e) { + // + } } public void sign_out_user() { @@ -244,6 +247,7 @@ public class System { zip_set.add(line); } } catch (Exception e) { + // } return new ArrayList<>(zip_set); @@ -316,6 +320,7 @@ public class System { weather = json.getJSONArray("weather").getJSONObject(0).getString("description"); temperature = json.getJSONObject("main").getDouble("temp"); } catch (Exception e) { + // } if (weather.equals("")) @@ -390,6 +395,7 @@ public class System { temperature_day_3_4 = json.getJSONArray("list").getJSONObject(30).getJSONObject("main").getDouble("temp"); } catch (Exception e) { + // } temperature_day_1.add(temperature_day_1_1); @@ -449,6 +455,7 @@ public class System { } } } catch (Exception e) { + // } InputStream inputStream2 = System.class.getResourceAsStream("/zip.csv"); @@ -471,12 +478,13 @@ public class System { distance = 6378.388 * 2.0 * Math.atan2(Math.sqrt(a), Math.sqrt(1.0 - a)); - result = Math.round((distance * 1.25) * 1000) / 1000.0; + result = Math.round(distance * 1.25 * 1000) / 1000.0; this.all_destinations.put(line.split(";")[0],new Destination(line.split(";")[1],line.split(";")[0], result)); } } catch (Exception e) { + // } return true; @@ -492,15 +500,15 @@ public class System { String[] result = new String[2]; - result[0] = "" + (Math.round(((Double.parseDouble(distance(destination_zip).replace(" km", "")) / current_user.getCar_avg_kmh())) * 1000) / 1000.0) + " h"; - result[1] = "" + (Math.round(((Double.parseDouble(distance(destination_zip).replace(" km", "")) / current_user.getBike_avg_kmh())) * 1000) / 1000.0) + " h"; + result[0] = "" + (Math.round(Double.parseDouble(distance(destination_zip).replace(" km", "")) / current_user.getCar_avg_kmh() * 1000) / 1000.0) + " h"; + result[1] = "" + (Math.round(Double.parseDouble(distance(destination_zip).replace(" km", "")) / current_user.getBike_avg_kmh() * 1000) / 1000.0) + " h"; return result; } public String calc_l_consumption(String destination_zip) { - return "" + (Math.round((Double.parseDouble(distance(destination_zip).replace(" km", "")) * (current_user.getCar_l_100km() / 100.0)) * 1000) / 1000.0) + " l"; + return "" + (Math.round(Double.parseDouble(distance(destination_zip).replace(" km", "")) * current_user.getCar_l_100km() / 100.0 * 1000) / 1000.0) + " l"; } } From b71f9c090a66d55288d0bde8f558f03cece2525c Mon Sep 17 00:00:00 2001 From: Selim Eser <2211482@stud.hs-mannheim.de> Date: Thu, 13 Jun 2024 12:21:08 +0200 Subject: [PATCH 4/7] getDetails method shouldnt return password fix --- src/main/java/de/hs_mannheim/domain/System.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/hs_mannheim/domain/System.java b/src/main/java/de/hs_mannheim/domain/System.java index 2233efa..66cec2a 100644 --- a/src/main/java/de/hs_mannheim/domain/System.java +++ b/src/main/java/de/hs_mannheim/domain/System.java @@ -226,8 +226,8 @@ public class System { } public String[] getDetails(){ - return new String[]{current_user.getUsername(), current_user.getPassword(), - current_user.getHometown(), current_user.getZip(), current_user.getCar_name(), + return new String[]{current_user.getUsername(), current_user.getHometown(), + current_user.getZip(), current_user.getCar_name(), current_user.getCar_l_100km()==0?"":String.valueOf(current_user.getCar_l_100km()), current_user.getCar_avg_kmh()==0?"":String.valueOf(current_user.getCar_avg_kmh()), current_user.getBike_avg_kmh()==0?"":String.valueOf(current_user.getBike_avg_kmh())}; From 7df63b10edfb015f7cd4863ca5cf9b8e3b3b0e3a Mon Sep 17 00:00:00 2001 From: Selim Eser <2211482@stud.hs-mannheim.de> Date: Thu, 13 Jun 2024 12:23:56 +0200 Subject: [PATCH 5/7] change_user_details require correct password input in order to change --- src/main/java/de/hs_mannheim/domain/System.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/hs_mannheim/domain/System.java b/src/main/java/de/hs_mannheim/domain/System.java index 66cec2a..3494cd1 100644 --- a/src/main/java/de/hs_mannheim/domain/System.java +++ b/src/main/java/de/hs_mannheim/domain/System.java @@ -171,7 +171,10 @@ public class System { return false; } - if(username.equals("")||password.equals("")||hometown.equals("")||zip.equals("")) + if(!current_user.getPassword().equals(password)) + return false; + + if(username.equals("")||hometown.equals("")||zip.equals("")) return false; for(User user: this.all_user) From a2e432119e52506472bc68bde81e806b8aea7983 Mon Sep 17 00:00:00 2001 From: Selim Eser <2211482@stud.hs-mannheim.de> Date: Thu, 13 Jun 2024 12:48:33 +0200 Subject: [PATCH 6/7] change_user_password method implemented and tested successful --- .../java/de/hs_mannheim/domain/System.java | 24 +++++++++++++++++++ .../de/hs_mannheim/facade/Application.java | 4 ++++ .../de/hs_mannheim/domain/SystemTest.java | 15 +++++++++++- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/hs_mannheim/domain/System.java b/src/main/java/de/hs_mannheim/domain/System.java index 3494cd1..02f4dd0 100644 --- a/src/main/java/de/hs_mannheim/domain/System.java +++ b/src/main/java/de/hs_mannheim/domain/System.java @@ -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 lines, String file) { try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) { for (int i = 0; i < lines.size() - 1; i++) { diff --git a/src/main/java/de/hs_mannheim/facade/Application.java b/src/main/java/de/hs_mannheim/facade/Application.java index f93622d..015597b 100644 --- a/src/main/java/de/hs_mannheim/facade/Application.java +++ b/src/main/java/de/hs_mannheim/facade/Application.java @@ -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 search(String hometown_or_zip){ return running_system.search(hometown_or_zip); } diff --git a/src/test/java/de/hs_mannheim/domain/SystemTest.java b/src/test/java/de/hs_mannheim/domain/SystemTest.java index 8a47749..24344b0 100644 --- a/src/test/java/de/hs_mannheim/domain/SystemTest.java +++ b/src/test/java/de/hs_mannheim/domain/SystemTest.java @@ -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 From b66b2314d8e94a0d4e502f262ccfca9dcb14433c Mon Sep 17 00:00:00 2001 From: Selim Eser <2211482@stud.hs-mannheim.de> Date: Thu, 13 Jun 2024 12:54:33 +0200 Subject: [PATCH 7/7] sign_up_user method now requires password authentication --- src/main/java/de/hs_mannheim/domain/System.java | 5 ++++- src/main/java/de/hs_mannheim/facade/Application.java | 4 ++-- src/test/java/de/hs_mannheim/domain/SystemTest.java | 8 ++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/de/hs_mannheim/domain/System.java b/src/main/java/de/hs_mannheim/domain/System.java index 02f4dd0..476a481 100644 --- a/src/main/java/de/hs_mannheim/domain/System.java +++ b/src/main/java/de/hs_mannheim/domain/System.java @@ -111,7 +111,7 @@ public class System { return false; } - public boolean sign_up_user(String username, String password, String hometown, String zip, + public boolean sign_up_user(String username, String password, String password_authentication, String hometown, String zip, String car_name, String car_l_100kmS, String car_avg_kmhS, String bike_avg_kmhS){ double car_l_100km; @@ -129,6 +129,9 @@ public class System { if(username.equals("")||password.equals("")||hometown.equals("")||zip.equals("")) return false; + if(!password.equals(password_authentication)) + return false; + for(User user: this.all_user) if(user.getUsername().equals(username)) return false; diff --git a/src/main/java/de/hs_mannheim/facade/Application.java b/src/main/java/de/hs_mannheim/facade/Application.java index 015597b..d771bde 100644 --- a/src/main/java/de/hs_mannheim/facade/Application.java +++ b/src/main/java/de/hs_mannheim/facade/Application.java @@ -16,9 +16,9 @@ public class Application { return running_system.sign_in_user(username, password); } - public boolean sign_up_user(String username, String password, String hometown, String zip, + public boolean sign_up_user(String username, String password, String password_authentication, String hometown, String zip, String car_name, String car_co2_km, String car_avg_kmh, String bike_avg_kmh){ - return running_system.sign_up_user(username, password, hometown, zip, car_name, car_co2_km, car_avg_kmh, bike_avg_kmh); + return running_system.sign_up_user(username, password, password_authentication, hometown, zip, car_name, car_co2_km, car_avg_kmh, bike_avg_kmh); } public void sign_out_user(){ diff --git a/src/test/java/de/hs_mannheim/domain/SystemTest.java b/src/test/java/de/hs_mannheim/domain/SystemTest.java index 24344b0..31fe19a 100644 --- a/src/test/java/de/hs_mannheim/domain/SystemTest.java +++ b/src/test/java/de/hs_mannheim/domain/SystemTest.java @@ -123,11 +123,11 @@ public class SystemTest { @Test public void sign_up_user(){ // Username darf nicht doppelt vorkommen! - assertEquals(false, current_system.sign_up_user("David","123Esel","Mannheim","68161","AMG","10","300","20")); - assertEquals(true, current_system.sign_up_user("Selim","Penis69","Mannheim","68161","AMG","10","300","20")); + assertEquals(false, current_system.sign_up_user("David","123Esel","123Esel","Mannheim","68161","AMG","10","300","20")); + assertEquals(true, current_system.sign_up_user("Selim","Penis69","Penis69","Mannheim","68161","AMG","10","300","20")); // PLZ muss mit Stadt übereinstimmen - assertEquals(false, current_system.sign_up_user("Lukas","123Esel","Mannheim","11105","AMG","10","300","20")); - assertEquals(true, current_system.sign_up_user("Lukas","123Esel","Mannheim","68305","AMG","10","300","20")); + assertEquals(false, current_system.sign_up_user("Lukas","123Esel","123Esel","Mannheim","11105","AMG","10","300","20")); + assertEquals(true, current_system.sign_up_user("Lukas","123Esel","123Esel","Mannheim","68305","AMG","10","300","20")); assertEquals("Lukas",current_system.getDetails()[0]); current_system.sign_out_user();