get_all_user method, sign_in_up methods fixed and get_all_user method successfully tested
parent
8016e9848e
commit
75b3b597c1
|
@ -53,17 +53,15 @@ public class System {
|
|||
return Base64.encodeBase64String(binary_data);
|
||||
}
|
||||
|
||||
public HashSet<User> get_all_user() throws FileNotFoundException, IOException{
|
||||
public HashSet<User> get_all_user() {
|
||||
HashSet<User> all_users = new HashSet<>();
|
||||
File file = new File("/user_data.csv");
|
||||
String[] fileString = new String[8];
|
||||
|
||||
if(file.exists() && file.isFile()){
|
||||
FileReader fileReader = new FileReader(file);
|
||||
BufferedReader bufferedReader = new BufferedReader(fileReader);
|
||||
InputStream inputStream = System.class.getResourceAsStream("/user_data.csv");
|
||||
String path;
|
||||
|
||||
while((path = bufferedReader.readLine()) != null){
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
|
||||
while ((path = reader.readLine()) != null) {
|
||||
fileString = path.split(";");
|
||||
fileString[1] = encoding(fileString[1]);
|
||||
all_users.add(new User(fileString[0], fileString[1], fileString[2],
|
||||
|
@ -72,6 +70,7 @@ public class System {
|
|||
Double.parseDouble(fileString[6]),
|
||||
Double.parseDouble(fileString[7])));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return all_users;
|
||||
}
|
||||
|
@ -80,7 +79,7 @@ public class System {
|
|||
ArrayList<User> mem = new ArrayList<>(get_all_user());
|
||||
|
||||
for (User user : mem) {
|
||||
if(user.getUsername().equals(username) && user.getPassword().equals(password)){
|
||||
if (user.getUsername().equals(username) && decoding(user.getPassword()).equals(password)) {
|
||||
current_user = new User(user.getUsername(), user.getPassword(),
|
||||
user.getHometown(), user.getZip(), user.getCar_name(),
|
||||
user.getCar_l_100km(), user.getCar_avg_kmh(), user.getBike_avg_kmh());
|
||||
|
@ -123,7 +122,8 @@ public class System {
|
|||
bufferedWriter.newLine();
|
||||
}
|
||||
bufferedWriter.close();
|
||||
} catch (IOException e) {}
|
||||
} catch (IOException e) {
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -155,7 +155,8 @@ public class System {
|
|||
zip_set.add(line);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
return new ArrayList<>(zip_set);
|
||||
}
|
||||
|
@ -226,7 +227,8 @@ public class System {
|
|||
JSONObject json = new JSONObject(((String) get_response.body()).substring(0, ((String) get_response.body()).length()));
|
||||
weather = json.getJSONArray("weather").getJSONObject(0).getString("description");
|
||||
temperature = json.getJSONObject("main").getDouble("temp");
|
||||
} catch (Exception e){}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
if (weather.equals(""))
|
||||
return "Es ist ein Fehler aufgetreten!";
|
||||
|
@ -299,7 +301,8 @@ public class System {
|
|||
temperature_day_3_3 = json.getJSONArray("list").getJSONObject(28).getJSONObject("main").getDouble("temp");
|
||||
temperature_day_3_4 = json.getJSONArray("list").getJSONObject(30).getJSONObject("main").getDouble("temp");
|
||||
|
||||
} catch (Exception e){}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
temperature_day_1.add(temperature_day_1_1);
|
||||
temperature_day_1.add(temperature_day_1_2);
|
||||
|
@ -357,7 +360,8 @@ public class System {
|
|||
lat1 = Double.parseDouble(line.split(";")[3]);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
if (lon1 == -1 || lon2 == -1 || lat1 == -1 || lat2 == -1)
|
||||
return "Es ist ein Fehler aufgetreten!";
|
||||
|
@ -389,7 +393,8 @@ public class System {
|
|||
this.distances.add(line.split(";")[0] + ";" + line.split(";")[1] + ";" + Double.parseDouble(distance(line.split(";")[0]).replace(" km", "")));
|
||||
|
||||
}
|
||||
} catch (Exception e) {}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
public String[] travel_time(String destination_zip) {
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Daniel;1401Daniel;Mannheim;68305;BMW;1.5;50.4;40.2
|
|
|
@ -3,6 +3,7 @@ package de.hs_mannheim.domain;
|
|||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -86,4 +87,13 @@ public class SystemTest {
|
|||
assertEquals(true, Double.parseDouble(current_system.distance(current_system.random_destinations_bike().get(0).split(";")[0]).replace(" km", "")) < 100);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void get_all_user() {
|
||||
assertEquals(1, current_system.get_all_user().size());
|
||||
|
||||
ArrayList<User> list = new ArrayList<>(current_system.get_all_user());
|
||||
assertEquals(true, list.get(0).getPassword().equals("MTQwMURhbmllbA=="));
|
||||
//Passwort unkodiert: 1401Daniel
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Daniel;1401Daniel;Mannheim;68305;BMW;1.5;50.4;40.2
|
|
Loading…
Reference in New Issue