Tournament list #11
|
@ -4,6 +4,7 @@ import javafx.collections.FXCollections;
|
|||
import javafx.collections.ObservableList;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Tournament implements Serializable {
|
||||
private String name;
|
||||
|
@ -11,10 +12,13 @@ public class Tournament implements Serializable {
|
|||
|
||||
|
||||
|
||||
public Tournament(String name, Type type) throws InvalidNameException {
|
||||
public Tournament(String name, Type type) throws InvalidNameException, InvalidTypeException {
|
||||
if(!name.matches("[\\w]{1,20}")){
|
||||
throw new Tournament.InvalidNameException("Invalid Name entered"); //TODO handle en logging.
|
||||
} else if(!Arrays.asList(Type.values()).contains(type)){
|
||||
throw new InvalidTypeException("Invalid Type selected"); //TODO handle en logging.
|
||||
}
|
||||
|
||||
setName(name);
|
||||
setType(type);
|
||||
}
|
||||
|
@ -67,5 +71,16 @@ public class Tournament implements Serializable {
|
|||
|
||||
}
|
||||
|
||||
public class InvalidTypeException extends Exception {
|
||||
public InvalidTypeException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public InvalidTypeException(String errorMessage) {
|
||||
super(errorMessage);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -64,8 +64,11 @@ public class TournamentListController extends FXController {
|
|||
Tournament tournament = new Tournament(tournamentNameField.getText(), modusChoiceBox.getValue());
|
||||
getFileIO().saveTournament(tournament);
|
||||
loadContent();
|
||||
tournamentNameField.clear();
|
||||
} catch (Tournament.InvalidNameException e) {
|
||||
e.printStackTrace(); //TODO handle and logging
|
||||
} catch (Tournament.InvalidTypeException e) {
|
||||
e.printStackTrace(); //TODO handle and logging
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace(); //TODO handle and logging
|
||||
}
|
||||
|
@ -92,6 +95,7 @@ public class TournamentListController extends FXController {
|
|||
if(alert.showAndGetResult()){
|
||||
try {
|
||||
getFileIO().deleteTournament(tournamentFile);
|
||||
loadContent();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace(); //TODO handle and logging
|
||||
}
|
||||
|
|
|
@ -108,20 +108,14 @@ class FileIOTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
void saveTournament() throws IOException {
|
||||
void saveTournament() throws IOException, Tournament.InvalidNameException, Tournament.InvalidTypeException {
|
||||
Tournament tournament = null;
|
||||
try {
|
||||
tournament = new Tournament("test1", Tournament.Type.KO);
|
||||
} catch (Tournament.InvalidNameException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
io.saveTournament(tournament);
|
||||
File file = new File(mainDir + "/saves/test1.txt");
|
||||
if(file.exists()){
|
||||
file.delete();
|
||||
} else {
|
||||
fail();
|
||||
}
|
||||
assertTrue(file.exists());
|
||||
assertTrue(file.delete());
|
||||
assertFalse(file.exists());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue