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..476a481 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) { + // } } @@ -110,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; @@ -128,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; @@ -170,7 +174,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) @@ -208,6 +215,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++) { @@ -215,7 +246,9 @@ public class System { writer.newLine(); } writer.write(lines.getLast()); - } catch (IOException e) {} + } catch (IOException e) { + // + } } public void sign_out_user() { @@ -223,8 +256,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())}; @@ -244,6 +277,7 @@ public class System { zip_set.add(line); } } catch (Exception e) { + // } return new ArrayList<>(zip_set); @@ -316,6 +350,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 +425,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 +485,7 @@ public class System { } } } catch (Exception e) { + // } InputStream inputStream2 = System.class.getResourceAsStream("/zip.csv"); @@ -471,12 +508,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 +530,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"; } } diff --git a/src/main/java/de/hs_mannheim/facade/Application.java b/src/main/java/de/hs_mannheim/facade/Application.java index f93622d..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(){ @@ -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/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..31fe19a 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 @@ -129,29 +123,44 @@ 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(); assertEquals("",current_system.getDetails()[0]); + assertEquals(true, current_system.sign_in_user("Lukas","123Esel")); } @Test 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 -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