Test class #42

Merged
fassband merged 6 commits from testClass into main 2022-05-13 15:16:05 +02:00
3 changed files with 28 additions and 7 deletions
Showing only changes of commit 03c9da13a5 - Show all commits

View File

@ -51,10 +51,10 @@ public class FactoryDecorator implements IsObservable{
try {
factory.setTournament(fileIO.loadTournament(tournamentFile));
openScheduleView();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
clearMessage(false);
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
printMessageToFooter("Fehler beim lesen der Datei.", true);
} //TODO handle and logging
}

View File

@ -9,7 +9,7 @@ public class Player extends Person implements Participant{
private LocalDate dateOfBirth;
public Player(String firstName, String name, String phoneNumber, String dateOfBirth) throws InvalidNameException, InvalidPhoneNumberException {
public Player(String firstName, String name, String phoneNumber, String dateOfBirth) throws InvalidNameException, InvalidPhoneNumberException, InvalidDateException {
super(firstName, name, phoneNumber);
setDateOfBirth(dateOfBirth);
}
@ -28,10 +28,16 @@ public class Player extends Person implements Participant{
}
}
public void setDateOfBirth(String dateOfBirth) {
public void setDateOfBirth(String dateOfBirth) throws InvalidDateException {
if(dateOfBirth.length() > 0) {
String[] date = dateOfBirth.split("\\.");
try{
this.dateOfBirth = LocalDate.of(Integer.valueOf(date[2]), Integer.valueOf(date[1]), Integer.valueOf(date[0]));
} catch (NumberFormatException | IndexOutOfBoundsException e) {
e.printStackTrace();
throw new InvalidDateException("Date invalid");
}
} else {
dateOfBirth = null;
}
@ -52,4 +58,16 @@ public class Player extends Person implements Participant{
setDateOfBirth(player.getDateOfBirth());
setPhoneNumber(player.getPhoneNumber());
}
public class InvalidDateException extends Exception {
public InvalidDateException() {
super();
}
public InvalidDateException(String errorMessage) {
super(errorMessage);
}
}
}

View File

@ -128,6 +128,9 @@ public class TournamentDecorator implements IsObservable{
} catch (Person.InvalidPhoneNumberException e) {
e.printStackTrace(); //TODO handle and logging
factoryDecorator.printMessageToFooter("Invalide Telefonnummer",true);
} catch (Player.InvalidDateException e) {
e.printStackTrace();
factoryDecorator.printMessageToFooter("Ungültiges Geburtsdatum", true);
}
}