diff --git a/ClassDiagram.png b/ClassDiagram.png index b31d979..79eaa8a 100644 Binary files a/ClassDiagram.png and b/ClassDiagram.png differ diff --git a/README.md b/README.md index b648163..447ade4 100644 --- a/README.md +++ b/README.md @@ -1,70 +1 @@ -# team02-AngryNerds-projekt2-turnierverwaltung - -## Tournament administration -### Documentation - -> Our Tournament Administration Tool is available in german and english, -> to change the language click on start in the top left corner and then select your -> desired language under 'Sprache' or 'Language' (documentation is only provided in english). - -Once you start the Programm you will be presented with the possibility to either create a new tournament or load one if one has already been saved. - ->To create a new tournament simply type in the name of it and press create - ->To load a tournament select the tournament on the list and click open - ->You can also delete a tournament by selecting it and then clicking delete - -Once a tournament has been created you will be sent to the tournament screen. -Your next step should be adding a place or players you can do so vie Edit Participants or Edit Locations. - -Once you have enough Players(min 4 and only number that are 2^n e.g. 4, 8, 16...), you can click the Create game schedule button and the schedule will be created - -you can then input the location where a game takes place and as well the points a team scored -the winning team will then automatically advance in the tree. - -The Programm automatically saves, so no worries you won't lose your progress. - -# Startup and Testing -To Start the Programm use the command ->./gradlew run - -To run the tests use the command ->./gradlew test - -# Branching Model -We used a simple branching model, for each new functionality or working step a new branch would be created, once a segment was finished the branch would then be reviewed by peers and be pushed into the main branch via a pull request, no direct work is usually done in the main branch. - -# Class Diagramm -Our class Diagramm can be found [here](https://github.zhaw.ch/PM2-IT21bWIN-ruiz-mach-krea/team02-AngryNerds-projekt2-turnierverwaltung/blob/main/ClassDiagram.png) -# Architecture - -Our Model View Pattern has been set, so that the class Tournament acts as the Model. -Each View has its own unique controller assigned -For Comprehensive Reasons all Controller Classes inherit from the abstract super class FX Controller. - -The Class Tournament decorator has the purpose of communication of the controller classes with the Model of the tournament, the same Decorator also communicates with the FileIO and inherits the task of saving or importing save files into the program. - -The Class Tournament Decorator always stores the Tournament that is opened in a data field. -The Factory and its associated Factory Decorators are responsible to load all the views if application is started. And to switch between the views while using the application. - -The Factory decorator is placed between the controllers and the factory to enable the communication. - -The Model tournament saves a List of all participants, all places and all games. Participants are implemented as an interface, since we want to be able to save a team or a single player as participant (in the prototype it is not possible to create a team). - -To refresh the view of the tournament tree, each game has its own game decorator with a list of listeners. - -To realize the tree there are listeners placed in the game decorators of the previous round to gather the winner and calculate the new participants of a game. Listeners are only placed - -Loggers are implemented in all relevant classes -Each class creates its own logger a root logger is created in the LogConfiguration class and two Handlers are specified for use, one File Handler and one Console Handler. -The setting of those handlers can be set in the file log.properties. - -We choose this architecture since it gives us the advantage to add more views without having any more code duplication. -We also think it is an advantage that the saving automatically takes place and the user does not have to take into consideration to save from time to time. -It also closely resembles what we learned already in lectures we had previously, so we were able to implement it accordingly. - -# Notable Pullrequests -[Number 1](https://github.zhaw.ch/PM2-IT21bWIN-ruiz-mach-krea/team02-AngryNerds-projekt2-turnierverwaltung/pull/22) -[Number 2](https://github.zhaw.ch/PM2-IT21bWIN-ruiz-mach-krea/team02-AngryNerds-projekt2-turnierverwaltung/pull/20) - +# team02-AngryNerds-projekt2-turnierverwaltung \ No newline at end of file diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Factory.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Factory.java index 6f5d23a..f58213e 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Factory.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Factory.java @@ -8,6 +8,7 @@ import javafx.scene.control.Label; import javafx.scene.layout.*; import javafx.scene.paint.Color; import javafx.scene.text.Font; + import java.io.IOException; import java.util.logging.Logger; @@ -69,7 +70,7 @@ public class Factory { view.loadView(tournamentDecorator, fileIO, factoryDecorator, pane); } catch (IOException e) { e.printStackTrace(); - //TODO Handle and logging. + logger.warning("failed to load views."); } } } @@ -81,6 +82,7 @@ public class Factory { public void showTournamentList(BorderPane pane) { tournamentDecorator.setTournament(null); setCenterOfBorderPane(pane, View.tournamentList); + logger.fine("showing Tournament List"); } /** @@ -89,6 +91,7 @@ public class Factory { */ public void showParticipantFormular(BorderPane pane) { setCenterOfBorderPane(pane, View.participantFormular); + logger.fine("showing Participant Formular"); } /** @@ -97,6 +100,7 @@ public class Factory { */ public void showPlacesFormular(BorderPane pane) { setCenterOfBorderPane(pane, View.placesFormular); + logger.fine("showing Places Formular"); } /** @@ -105,6 +109,7 @@ public class Factory { */ public void showGameScheduler(BorderPane pane) { setCenterOfBorderPane(pane, View.gameScheduler); + logger.fine("showing Game Scheduler"); } /** @@ -131,6 +136,7 @@ public class Factory { box.getChildren().add(loader.load()); GameController controller = loader.getController(); controller.setup(tournamentDecorator, fileIO, factoryDecorator, box, gameDecorator, languageConfigurator); + logger.fine("loaded game view"); return controller; } catch (IOException e) { logger.warning("Fatal error program can not continue after this: " + e ); @@ -146,6 +152,7 @@ public class Factory { * @param error true if it's a error message. */ public void printMessageToFooter(BorderPane pane, String msg, boolean error) { + logger.fine("message is printed to footer of window."); VBox bottom = (VBox) pane.getBottom(); Label label = new Label(); VBox innerVbox; @@ -168,6 +175,8 @@ public class Factory { innerVbox.getChildren().add(label); } + + } /** @@ -176,6 +185,7 @@ public class Factory { * @param error true if the error message should be cleared. */ public void resetFooter(BorderPane pane,boolean error) { + logger.fine("messages are removed from footer of window."); VBox bottom = (VBox) pane.getBottom(); VBox vBox; if (error) { diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FactoryDecorator.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FactoryDecorator.java index 0c4baac..c59b8dd 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FactoryDecorator.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FactoryDecorator.java @@ -109,7 +109,6 @@ public class FactoryDecorator implements IsObservable { logger.warning("Failed to open tournament file Error: " + e); printMessageToFooter("Fehler beim lesen der Datei.", true); String msg = factory.getLanguageConfigurator().getSelectedLanguage("IOException"); - logger.warning("Failed to open tournament file Error: " + e); printMessageToFooter(msg, true); } } @@ -141,11 +140,20 @@ public class FactoryDecorator implements IsObservable { informListener(); } + /** + * Initializes the view of gameSchedule + */ public void openScheduleView() { factory.showGameScheduler((BorderPane) pane); informListener(); } + /** + * Method to load all game views to show. + * @param hBoxCenter the box where the games should be shown. + * @param tournamentDecorator the tournamentDecorator to communicate to tournament + * @param treeView true if the games should be arranged like a tree. + */ public void loadGameList(HBox hBoxCenter, TournamentDecorator tournamentDecorator, boolean treeView) { hBoxCenter.getChildren().clear(); @@ -195,6 +203,13 @@ public class FactoryDecorator implements IsObservable { } } + /** + * Method to draw the lines between the game views in the tree view. + * @param gameVBox the box with the games where lines should be drawn. + * @param gameBoxHeight the heigth of a single game box. + * @param lineLength the length of the horizontal lines. + * @return a box which contains the drawn lines. + */ public VBox drawLines(VBox gameVBox, double gameBoxHeight, double lineLength) { VBox completeLineVBox = new VBox(); completeLineVBox.setAlignment(Pos.CENTER_LEFT); @@ -228,8 +243,8 @@ public class FactoryDecorator implements IsObservable { /** * Method Initializes the Game View, in order to do that a vbox is needed and the gameDecorator * @param vBox used for display - * @param gameDecorator - * @return + * @param gameDecorator the gameDecorator Object to communicate with game + * @return the controller of the loaded game view. */ public GameController openGameView(VBox vBox, GameDecorator gameDecorator) { @@ -256,9 +271,10 @@ public class FactoryDecorator implements IsObservable { factory.resetFooter((BorderPane) pane, error); } - - - + /** + * getter Method of languageConfigurator + * @return the languageConfigurator object. + */ public LanguageConfigurator getLanguageConfigurator() { return factory.getLanguageConfigurator(); } diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/LanguageConfigurator.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/LanguageConfigurator.java index beb00c7..396fa7c 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/LanguageConfigurator.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/LanguageConfigurator.java @@ -2,6 +2,7 @@ package ch.zhaw.projekt2.turnierverwaltung; import javafx.scene.control.Labeled; import javafx.scene.control.MenuItem; + import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -102,9 +103,11 @@ public class LanguageConfigurator { englishDictionary.put("participantNotExist","Participant does not exist"); germanDictionary.put("placeNotExist","Teilnehmer existiert nicht"); englishDictionary.put("placeNotExist","Participant does not exist"); + //SaveMsg germanDictionary.put("save","Zuletzt gespeichert: "); englishDictionary.put("save","Last saved: "); + //Alert germanDictionary.put("yes","Ja"); englishDictionary.put("yes","Yes"); @@ -116,6 +119,7 @@ public class LanguageConfigurator { englishDictionary.put("headerDelete","Delete Tournament?"); germanDictionary.put("contentDelete","Sind Sie sicher, dass sie das Turnier entfernen wollen?\nNach diesem Vorgang kann es nicht wiederhergestellt werden."); englishDictionary.put("contentDelete","Are you shure you want to delete the tournament?\nAfter that there is no way to restore."); + germanDictionary.put("titleSchedule","Neu erstellen"); englishDictionary.put("titleSchedule","Create new"); germanDictionary.put("headerSchedule","Spielplan neu erstellen?"); diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Team.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Team.java index 22fe1e7..4247526 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Team.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Team.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.List; import java.util.logging.Logger; + /** * Class Team represents a team that can be added to a tournament * (in the prototype there is no functionality for the team) @@ -21,7 +22,7 @@ public class Team implements Participant { * @param name the new name to be set */ public Team(String name) { - logger.fine("Setting the new name of the team as: " + name); + logger.fine("Setting the new name of the team as: " + name); setName(name); players = new ArrayList<>(); } diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/TournamentDecorator.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/TournamentDecorator.java index 45c3f38..955949f 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/TournamentDecorator.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/TournamentDecorator.java @@ -1,6 +1,7 @@ package ch.zhaw.projekt2.turnierverwaltung; import javafx.application.Platform; + import java.io.IOException; import java.util.ArrayList; import java.util.Date; @@ -8,6 +9,8 @@ import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; +import java.util.logging.Logger; + public class TournamentDecorator implements IsObservable{ private Tournament tournament; @@ -16,48 +19,84 @@ public class TournamentDecorator implements IsObservable{ private ExecutorService executorService; private FactoryDecorator factoryDecorator; + private static final Logger logger = Logger.getLogger(TournamentDecorator.class.getCanonicalName()); + + /** + * Constructor to initialize TournamentDecorator + * adds a listener to save the tournament every time if something is changed. + * creates a executer service to do the saving process in separate thread for better performance. + * @param fileIO + */ public TournamentDecorator(FileIO fileIO){ + logger.fine("initializing TournamentDecorator"); setFileIO(fileIO); addListener(new IsObserver() { @Override public void update() { if(tournament != null){ - saveTournament(); + logger.fine("listener to save tournament was added"); } } }); executorService = Executors.newFixedThreadPool(1); } + /** + * Setter method of FactoryDecorator + * @param factoryDecorator the factory decorator to load different views. + */ public void setFactoryDecorator(FactoryDecorator factoryDecorator) { this.factoryDecorator = factoryDecorator; } + /** + * Setter Method of FileIO + * @param fileIO the fileIO object to read and save to files. + */ public void setFileIO(FileIO fileIO) { this.fileIO = fileIO; } + /** + * setter Method of Tournament + * @param tournament the new Tournament Object which was selected by user. + */ public void setTournament(Tournament tournament) { this.tournament = tournament; } + /** + * getter Method of Tournament + * @return the actual tournament which is open. + */ public Tournament getTournament() { return tournament; } + /** + * Method to add a listener in list. + * @param observer the observer object which should be informed. + */ @Override public void addListener(IsObserver observer) { listener.add(observer); } + /** + * Method to remove a listener from list. + * @param observer the object to remove. + */ @Override public void removeListener(IsObserver observer) { listener.remove(observer); } - + /** + * Method to save the actual tournament to files. + */ public void saveTournament(){ + logger.fine("Saving Tournament to File."); executorService.execute(new saveTask()); factoryDecorator.clearMessage(false); String msg = factoryDecorator.getLanguageConfigurator().getSelectedLanguage("save"); @@ -65,40 +104,49 @@ public class TournamentDecorator implements IsObservable{ } - + /** + * Method to create a new Tournament. It checks if the name is valid, creates a new instance of Tournament and calls + * FileIO to save the new Tournament. + * @param name The name which was entered by the user. + * @param type The type of Tournament + */ public void createTournament(String name, Tournament.Type type){ - try { if(fileIO.tournamentExists(name)){ - //TODO:Logger + logger.warning("a tournament with name " + name + "exists already."); String msg = factoryDecorator.getLanguageConfigurator().getSelectedLanguage("tournamentExists"); factoryDecorator.printMessageToFooter(msg, true); return; } Tournament tournament = new Tournament(name, type); + logger.fine("new tournament instance was created."); fileIO.saveTournament(tournament); + logger.fine("new Tournament File is saved."); factoryDecorator.clearMessage(true); informListener(); } catch (InvalidNameException e) { e.printStackTrace(); - //TODO: Logger + logger.warning("The name which was entered is invalid."); String msg = factoryDecorator.getLanguageConfigurator().getSelectedLanguage("invalidName"); factoryDecorator.printMessageToFooter(msg, true); } catch (Tournament.InvalidTypeException e) { e.printStackTrace(); - //TODO: Logger + logger.warning("The selected type of tournament is not valid."); String msg = factoryDecorator.getLanguageConfigurator().getSelectedLanguage("invalidMode"); factoryDecorator.printMessageToFooter(msg, true); - } catch (IOException e) { e.printStackTrace(); - //TODO: Logger + logger.warning("Creating a new Tournament File was failed."); String msg = factoryDecorator.getLanguageConfigurator().getSelectedLanguage("IOException"); factoryDecorator.printMessageToFooter(msg, true); } } + /** + * Method to delete a Tournament File + * @param tournamentFile The File which should be deleted. + */ public void deleteTournament(FileIO.TournamentFile tournamentFile){ try { fileIO.deleteTournament(tournamentFile); @@ -111,8 +159,11 @@ public class TournamentDecorator implements IsObservable{ } } + /** + * Method to create the list of games. The participants are entered in random order. + */ public void createNewGameSchedule() { - //TODO: logging + logger.fine("Creating new Game Schedule"); try { tournament.createGameSchedule(); factoryDecorator.clearMessage(true); @@ -120,6 +171,7 @@ public class TournamentDecorator implements IsObservable{ e.printStackTrace(); String msg = factoryDecorator.getLanguageConfigurator().getSelectedLanguage("numberParticipant"); factoryDecorator.printMessageToFooter(msg, true); + logger.warning("Failed to create Game Schedule. The number of Participants is invalid."); } informListener(); } diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/MainWindow.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/MainWindow.java index 8355b81..ab4af82 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/MainWindow.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/MainWindow.java @@ -21,6 +21,7 @@ public class MainWindow extends Application { private Factory factory = new Factory(fileIO, tournamentDecorator, languageConfigurator); private static final Logger logger = Logger.getLogger(FileIO.class.getCanonicalName()); + /** * Start method used to initialize the main window and load it's needed component * Also sets the scene and set some values like min width and height diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/MainWindowController.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/MainWindowController.java index 2a9c96c..1931fa9 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/MainWindowController.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/MainWindowController.java @@ -7,7 +7,6 @@ import javafx.fxml.FXML; import javafx.scene.control.Label; import javafx.scene.control.Menu; import javafx.scene.control.MenuItem; -import java.util.logging.Logger; import java.util.logging.Logger; @@ -31,19 +30,17 @@ public class MainWindowController extends FXController { @FXML private Menu menuItemLanguage; - /** + /** * Method changes the language Setting to german */ @FXML void changeLangToGerman() { getLanguageConfigurator().changeLanguage(LanguageConfigurator.Language.GERMAN); - logger.fine("language setting changed to german"); } @FXML void changeLangToEnglish() { getLanguageConfigurator().changeLanguage(LanguageConfigurator.Language.ENGLISH); - logger.fine("language setting changed to english"); } /** @@ -66,9 +63,7 @@ public class MainWindowController extends FXController { } - /** - * There is no content to load - */ + @Override public void loadContent() { } diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/AlertNewSchedule.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/AlertNewSchedule.java index 19c4b49..f7c5760 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/AlertNewSchedule.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/AlertNewSchedule.java @@ -6,9 +6,6 @@ import ch.zhaw.projekt2.turnierverwaltung.LanguageConfigurator; import javafx.scene.control.Alert; import javafx.scene.control.ButtonBar; import javafx.scene.control.ButtonType; -/** - * Class that is used to display the popup window to confirm a sensitive action of the user. - */ import java.util.logging.Logger; @@ -26,9 +23,6 @@ public class AlertNewSchedule extends Alert { private String headerDelete; private String contentDelete; - /** - * Popup to ask the user if he is sure that he wants to reshuffle the game board. - */ public AlertNewSchedule(LanguageConfigurator languageConfigurator){ super(Alert.AlertType.WARNING); yes = languageConfigurator.getSelectedLanguage("yes"); diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameController.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameController.java index e4b9838..87ae69b 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameController.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameController.java @@ -45,7 +45,7 @@ public class GameController extends FXController{ } @FXML - void saveGameResult() { + void saveGameResult(Event event) { gameDecorator.saveGameResult(pointsTeamOne.getText(), pointsTeamTwo.getText()); } diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/participantAddFormular/ParticipantFormularController.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/participantAddFormular/ParticipantFormularController.java index b6562e3..64a010b 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/participantAddFormular/ParticipantFormularController.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/participantAddFormular/ParticipantFormularController.java @@ -14,11 +14,6 @@ import javafx.scene.input.MouseEvent; import javafx.scene.layout.GridPane; import javafx.scene.layout.VBox; -import java.util.logging.Logger; - -/** - * Controller of Participant - */ public class ParticipantFormularController extends FXController { @FXML @@ -73,14 +68,8 @@ public class ParticipantFormularController extends FXController { @FXML private Button saveBtn; - private static final Logger logger = Logger.getLogger(ParticipantFormularController.class.getCanonicalName()); - - /** - * Shares GUI Elements with the LanguageConfigurator - */ @Override public void shareGUIElementWithLanguageConfigurator() { - logger.fine("sharing GUI Elements"); getLanguageConfigurator().recieveLabel(participantListTitle); getLanguageConfigurator().recieveLabel(closeBtn); getLanguageConfigurator().recieveLabel(deleteBtn); @@ -92,11 +81,8 @@ public class ParticipantFormularController extends FXController { getLanguageConfigurator().recieveLabel(saveBtn); } - /** - * Changes the current selection - */ @FXML - void changedSelection(){ + void changedSelection(MouseEvent event){ Player participant = (Player) participantListView.getSelectionModel().getSelectedItems().get(0); participantNameTextField.setText(participant.getName()); firstNameTextField.setText(participant.getFirstName()); @@ -104,18 +90,12 @@ public class ParticipantFormularController extends FXController { birthDateTextField.setText(participant.getFormattedDateOfBirth()); } - /** - * Saves a new Participant and clears form - */ @FXML - void saveParticipant() { + void saveParticipant(ActionEvent event) { getTournamentDecorator().savePlayer(firstNameTextField.getText(), participantNameTextField.getText(), phoneNumberTextField.getText(), birthDateTextField.getText()); clearFormular(); } - /** - * Clears current form - */ private void clearFormular() { firstNameTextField.clear(); participantNameTextField.clear(); @@ -123,30 +103,19 @@ public class ParticipantFormularController extends FXController { birthDateTextField.clear(); } - /** - * Deletes the selected participant. - */ @FXML - void delete() { + void delete(ActionEvent event) { Participant participant = participantListView.getSelectionModel().getSelectedItems().get(0); - logger.fine("deleting participant:" + participant); getTournamentDecorator().deleteParticipant(participant); } - /** - * Closes the participant form - */ @FXML - void close() { + void close(ActionEvent event) { getFactoryDecorator().openScheduleView(); } - /** - * Loads the previously saved content and puts it in the list - */ @Override public void loadContent() { - logger.fine("loading and placing it into the list"); Tournament tournament = getTournamentDecorator().getTournament(); if(tournament != null){ participantListView.setItems(tournament.getParticipants()); diff --git a/app/src/test/java/ch/zhaw/projekt2/turnierverwaltung/FactoryDecoratorTest.java b/app/src/test/java/ch/zhaw/projekt2/turnierverwaltung/FactoryDecoratorTest.java deleted file mode 100644 index 000d4ba..0000000 --- a/app/src/test/java/ch/zhaw/projekt2/turnierverwaltung/FactoryDecoratorTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package ch.zhaw.projekt2.turnierverwaltung; - -import javafx.scene.layout.BorderPane; -import javafx.scene.layout.Pane; -import org.junit.jupiter.api.Test; -import org.mockito.InOrder; -import org.mockito.Mockito; -import java.io.IOException; - -import static org.junit.jupiter.api.Assertions.fail; -import static org.mockito.Mockito.inOrder; - -public class FactoryDecoratorTest { - - private FactoryDecorator factoryDecorator; - - @Test - void test() { - FileIO io = Mockito.mock(FileIO.class); - Factory fc = Mockito.mock(Factory.class); - Pane pn = Mockito.mock(BorderPane.class); - FileIO.TournamentFile tf = Mockito.mock(FileIO.TournamentFile.class); - - factoryDecorator = new FactoryDecorator(io,fc,pn); - factoryDecorator.openTournament(tf); - - InOrder order = inOrder(io,fc,pn); - - try { - order.verify(fc).setTournament(io.loadTournament(tf)); - order.verify(fc).showGameScheduler((BorderPane) pn); - - } catch (IOException | ClassNotFoundException e) { - e.printStackTrace(); - fail(); - } - } -} diff --git a/app/src/test/java/ch/zhaw/projekt2/turnierverwaltung/GameTest.java b/app/src/test/java/ch/zhaw/projekt2/turnierverwaltung/GameTest.java deleted file mode 100644 index a72332a..0000000 --- a/app/src/test/java/ch/zhaw/projekt2/turnierverwaltung/GameTest.java +++ /dev/null @@ -1,41 +0,0 @@ -package ch.zhaw.projekt2.turnierverwaltung; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.mockito.Mockito; - -public class GameTest { - - private Game game; - - @Test - @DisplayName("TestWinner") - void testWinnerFunction() { - Participant one = Mockito.mock(Player.class); - Participant two = Mockito.mock(Player.class); - game = new Game(one,two); - game.setPoints1(1); - Assertions.assertEquals(one,game.getWinner()); - game.setPoints2(2); - Assertions.assertEquals(two,game.getWinner()); - } - - @Test - @DisplayName("Test refresh Participant") - void refreshTest() { - Participant one = Mockito.mock(Player.class); - Participant two = Mockito.mock(Player.class); - Game game1 = new Game(one,two); - Game game2 = new Game(one,two); - game = new Game(game1,game2); - game1.setPoints1(2); - game2.setPoints2(2); - Assertions.assertNull(game.getParticipant1()); - Assertions.assertNull(game.getParticipant2()); - game.refreshParticipants(); - Assertions.assertEquals(one,game.getParticipant1()); - Assertions.assertEquals(two,game.getParticipant2()); - - } -} diff --git a/app/src/test/java/ch/zhaw/projekt2/turnierverwaltung/LanguageTest.java b/app/src/test/java/ch/zhaw/projekt2/turnierverwaltung/LanguageTest.java deleted file mode 100644 index e5dfdb8..0000000 --- a/app/src/test/java/ch/zhaw/projekt2/turnierverwaltung/LanguageTest.java +++ /dev/null @@ -1,18 +0,0 @@ -package ch.zhaw.projekt2.turnierverwaltung; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - -public class LanguageTest { - - @Test - @DisplayName("Test Dictionary") - void test() { - LanguageConfigurator languageConfigurator = new LanguageConfigurator(); - Assertions.assertEquals("Ja",languageConfigurator.getSelectedLanguage("yes")); - languageConfigurator.changeLanguage(LanguageConfigurator.Language.ENGLISH); - Assertions.assertEquals("Yes",languageConfigurator.getSelectedLanguage("yes")); - - } -} diff --git a/app/src/test/java/ch/zhaw/projekt2/turnierverwaltung/PersonTest.java b/app/src/test/java/ch/zhaw/projekt2/turnierverwaltung/PersonTest.java deleted file mode 100644 index 4a462db..0000000 --- a/app/src/test/java/ch/zhaw/projekt2/turnierverwaltung/PersonTest.java +++ /dev/null @@ -1,25 +0,0 @@ -package ch.zhaw.projekt2.turnierverwaltung; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; - -public class PersonTest { - private Person person; - - @Test - @DisplayName("Test invalid Parameter") - void invalidParams() { - try { - assertThrows(Person.InvalidPhoneNumberException.class,()->new Person("A","a",".sad")); - person = new Person("A","A",""); - assertEquals("A", person.getFirstName()); - assertEquals("A", person.getName()); - assertEquals("", person.getPhoneNumber()); - } catch (InvalidNameException | Person.InvalidPhoneNumberException e) { - fail(); - } - } - -} diff --git a/app/src/test/java/ch/zhaw/projekt2/turnierverwaltung/PlaceTest.java b/app/src/test/java/ch/zhaw/projekt2/turnierverwaltung/PlaceTest.java deleted file mode 100644 index 81e6ba6..0000000 --- a/app/src/test/java/ch/zhaw/projekt2/turnierverwaltung/PlaceTest.java +++ /dev/null @@ -1,36 +0,0 @@ -package ch.zhaw.projekt2.turnierverwaltung; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; - -public class PlaceTest { - private Place place; - - @Test - @DisplayName("Test Params") - void paramTest() { - Assertions.assertThrows(InvalidNameException.class, () -> new Place("*")); - try { - place = new Place("placeA"); - assertEquals("placeA", place.getName()); - } catch (InvalidNameException e) { - fail(); - } - } - - @Test - @DisplayName("Place Equals Test") - void testEqual() { - try { - place = new Place("placeA"); - assertTrue(place.equals(place)); - assertTrue(place.equals(new Place("placeA"))); - assertFalse(place.equals(new Place("nads"))); - } catch (InvalidNameException e) { - fail(); - } - } -} diff --git a/app/src/test/java/ch/zhaw/projekt2/turnierverwaltung/PlayerTest.java b/app/src/test/java/ch/zhaw/projekt2/turnierverwaltung/PlayerTest.java deleted file mode 100644 index 9b22d6d..0000000 --- a/app/src/test/java/ch/zhaw/projekt2/turnierverwaltung/PlayerTest.java +++ /dev/null @@ -1,39 +0,0 @@ -package ch.zhaw.projekt2.turnierverwaltung; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; - -public class PlayerTest { - private Player player; - - @Test - @DisplayName("Test invalid Parameter") - void invalidParams() { - try { - assertThrows(Person.InvalidPhoneNumberException.class,()->new Player("A","a",".sad","")); - assertThrows(Player.InvalidDateException.class,()->new Player("A","a","","a")); - player = new Player("A","A","",""); - assertEquals("A",player.getFirstName()); - assertEquals("A",player.getName()); - assertEquals("",player.getPhoneNumber()); - assertNull(player.getDateOfBirth()); - } catch (InvalidNameException | Person.InvalidPhoneNumberException | Player.InvalidDateException e) { - fail(); - } - } - - @Test - @DisplayName("Test equals") - void equalsTest() { - try { - player = new Player("A","A","",""); - assertTrue(player.equals(player)); - assertFalse(player.equals(new Player("B", "D", "", ""))); - assertTrue(player.equals(new Player("A", "A", "", ""))); - } catch (InvalidNameException | Person.InvalidPhoneNumberException | Player.InvalidDateException e) { - e.printStackTrace(); - } - } -} diff --git a/app/src/test/java/ch/zhaw/projekt2/turnierverwaltung/TeamTest.java b/app/src/test/java/ch/zhaw/projekt2/turnierverwaltung/TeamTest.java deleted file mode 100644 index 2e53a38..0000000 --- a/app/src/test/java/ch/zhaw/projekt2/turnierverwaltung/TeamTest.java +++ /dev/null @@ -1,31 +0,0 @@ -package ch.zhaw.projekt2.turnierverwaltung; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.mockito.Mockito; - -public class TeamTest { - - private Team team; - - @Test - @DisplayName("Team Params") - void testParams() { - Player player = Mockito.mock(Player.class); - team = new Team("Team1"); - for (int i = 0; i < 3; i++) { - Assertions.assertEquals(i,team.getPlayers().size()); - team.addPlayer(player); - } - } - - @Test - @DisplayName("Team Equals") - void equalTeam() { - team = new Team("A"); - Assertions.assertTrue(team.equals(team)); - Assertions.assertTrue(team.equals(new Team("A"))); - Assertions.assertFalse(team.equals(new Team("B"))); - } -} diff --git a/app/src/test/java/ch/zhaw/projekt2/turnierverwaltung/TournamentTest.java b/app/src/test/java/ch/zhaw/projekt2/turnierverwaltung/TournamentTest.java index 75e98d4..3acc30c 100644 --- a/app/src/test/java/ch/zhaw/projekt2/turnierverwaltung/TournamentTest.java +++ b/app/src/test/java/ch/zhaw/projekt2/turnierverwaltung/TournamentTest.java @@ -44,21 +44,20 @@ public class TournamentTest { //Checks if one Participant gets added Participant participantOne = Mockito.mock(Player.class); when(participantOne.equals(any(Participant.class))).thenReturn(false); - try { - assertEquals(0, tournament.getParticipants().size()); - tournament.saveParticipant(participantOne); - assertEquals(1, tournament.getParticipants().size()); - //Checks if a second Participant gets added - Participant participantTwo = Mockito.mock(Player.class); - tournament.saveParticipant(participantTwo); - assertEquals(2, tournament.getParticipants().size()); - //Checks if a allready added Particpant does not get added - when(participantOne.equals(any(Participant.class))).thenReturn(true); - tournament.saveParticipant(participantTwo); - assertEquals(2, tournament.getParticipants().size()); - } catch (Person.InvalidPhoneNumberException e) { - fail(); - } + + assertEquals(0, tournament.getParticipants().size()); + tournament.saveParticipant(participantOne); + assertEquals(1, tournament.getParticipants().size()); + + //Checks if a second Participant gets added + Participant participantTwo = Mockito.mock(Player.class); + tournament.saveParticipant(participantTwo); + assertEquals(2, tournament.getParticipants().size()); + + //Checks if a allready added Particpant does not get added + when(participantOne.equals(any(Participant.class))).thenReturn(true); + tournament.saveParticipant(participantTwo); + assertEquals(2, tournament.getParticipants().size()); } @@ -70,13 +69,13 @@ public class TournamentTest { //Checks if Error is thrown if Participant not in list assertThrows(Tournament.ParticipantNotExistsException.class, () -> tournament.removeParticipant(participant)); + //Checks if participant gets removed + tournament.saveParticipant(participant); + assertEquals(1, tournament.getParticipants().size()); try { - //Checks if participant gets removed - tournament.saveParticipant(participant); - assertEquals(1, tournament.getParticipants().size()); tournament.removeParticipant(participant); assertEquals(0, tournament.getParticipants().size()); - } catch (Tournament.ParticipantNotExistsException | Person.InvalidPhoneNumberException e) { + } catch (Tournament.ParticipantNotExistsException e) { fail(); } } @@ -127,18 +126,13 @@ public class TournamentTest { tournament.createGameSchedule(); assertEquals(2, tournament.getGameList().size()); tournament.saveParticipant(participant); - } catch (Tournament.NumberOfParticipantInvalidException | Person.InvalidPhoneNumberException e) { + } catch (Tournament.NumberOfParticipantInvalidException e) { fail(); } } else { - assertThrows(Tournament.NumberOfParticipantInvalidException.class, () -> tournament.createGameSchedule()); - try { - tournament.saveParticipant(participant); - } catch (Person.InvalidPhoneNumberException e) { - e.printStackTrace(); - } + tournament.saveParticipant(participant); } } try { diff --git a/app/src/test/resources/ch/zhaw/projekt2/turnierverwaltung/FileIORead/saves/test1.txt b/app/src/test/resources/ch/zhaw/projekt2/turnierverwaltung/FileIORead/saves/test1.txt index 61c16d2..0e0f438 100644 Binary files a/app/src/test/resources/ch/zhaw/projekt2/turnierverwaltung/FileIORead/saves/test1.txt and b/app/src/test/resources/ch/zhaw/projekt2/turnierverwaltung/FileIORead/saves/test1.txt differ