Compare commits

...

27 Commits

Author SHA1 Message Date
Marcela Ruiz 7817c91546 Feedback Ruiz
Dear Angry Nerds Team. 

Here you are the feedback for your project. BTW: Very good your application offer English and German language!
2022-05-26 20:05:07 +02:00
Roman Schenk 86b57547cf Merge pull request #57 from PM2-IT21bWIN-ruiz-mach-krea/logging_and_docs
Logging and docs
2022-05-13 23:57:50 +02:00
Andrin Fassbind 631ea90225 Merge remote-tracking branch 'origin/main' 2022-05-13 23:57:41 +02:00
Andrin Fassbind 30afecb379 javadoc 2022-05-13 23:57:31 +02:00
Leonardo Brandenberger b52fbb6d55 Merge remote-tracking branch 'origin/main' 2022-05-13 23:56:37 +02:00
Leonardo Brandenberger c11d6f8ef7 Last javadoc and logger implemented 2022-05-13 23:56:26 +02:00
Roman Schenk d23d8cef74 Merge pull request #56 from PM2-IT21bWIN-ruiz-mach-krea/testing
fixed FileIO Test.
2022-05-13 23:54:59 +02:00
schrom01 5ed0f38db6 fixed FileIO Test. 2022-05-13 23:54:27 +02:00
Leonardo Brandenberger 1aa05d6251 Merge remote-tracking branch 'origin/main' 2022-05-13 23:48:38 +02:00
Leonardo Brandenberger 73ba3b3b9e Created Readme 2022-05-13 23:48:13 +02:00
fassband b598eb660b Merge pull request #55 from PM2-IT21bWIN-ruiz-mach-krea/testing
Testing
2022-05-13 23:48:11 +02:00
Andrin Fassbind ec256d40c6 FactoryDecoratorTest 2022-05-13 23:47:06 +02:00
Andrin Fassbind 2a8caf8efd FactoryDecoratorTest 2022-05-13 23:45:49 +02:00
Roman Schenk 186c389bd2 uploaded new ClassDiagram 2022-05-13 23:04:17 +02:00
Roman Schenk 9f745b3198 Merge pull request #54 from PM2-IT21bWIN-ruiz-mach-krea/testing
Testing
2022-05-13 23:03:37 +02:00
Andrin Fassbind 4db2c582e2 merge conflict 2022-05-13 23:03:15 +02:00
Roman Schenk 4392fabc38 Merge branch 'main' into testing 2022-05-13 22:59:35 +02:00
Andrin Fassbind a8a2a0a463 create FactoryTest
merged
2022-05-13 22:56:24 +02:00
Andrin Fassbind 418f583955 Merge remote-tracking branch 'origin/logging_and_docs' into testing
# Conflicts:
#	app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Factory.java
#	app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/FactoryDecorator.java
#	app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/LogConfiguration.java
#	app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/MainWindow.java
#	app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/MainWindowController.java
#	app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/AlertNewSchedule.java
#	app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameController.java
2022-05-13 22:53:30 +02:00
Andrin Fassbind 7f8de3e8f1 create FactoryTest 2022-05-13 22:35:01 +02:00
Andrin Fassbind df3fc5df2d create TeamTest 2022-05-13 22:22:39 +02:00
Andrin Fassbind 2e314497db create PlaceTest 2022-05-13 22:06:58 +02:00
Andrin Fassbind fd06e24e21 create PersonTest 2022-05-13 21:54:21 +02:00
Andrin Fassbind 2ef4c3f584 create PlayerTest 2022-05-13 21:46:31 +02:00
Andrin Fassbind 135ec7e8d5 sync TournamentTest with new changes
create GameTest
2022-05-13 21:11:33 +02:00
Andrin Fassbind c8eff00e33 Merge remote-tracking branch 'origin/main' into testing 2022-05-13 20:54:58 +02:00
Andrin Fassbind c086cf18a4 test game 2022-05-13 19:41:20 +02:00
23 changed files with 429 additions and 41 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 694 KiB

BIN
Feedback_ruiz.pdf Normal file

Binary file not shown.

View File

@ -1 +1,70 @@
# team02-AngryNerds-projekt2-turnierverwaltung # 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)

View File

@ -8,7 +8,6 @@ import javafx.scene.control.Label;
import javafx.scene.layout.*; import javafx.scene.layout.*;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import javafx.scene.text.Font; import javafx.scene.text.Font;
import java.io.IOException; import java.io.IOException;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -175,8 +174,6 @@ public class Factory {
innerVbox.getChildren().add(label); innerVbox.getChildren().add(label);
} }
} }
/** /**

View File

@ -109,6 +109,7 @@ public class FactoryDecorator implements IsObservable {
logger.warning("Failed to open tournament file Error: " + e); logger.warning("Failed to open tournament file Error: " + e);
printMessageToFooter("Fehler beim lesen der Datei.", true); printMessageToFooter("Fehler beim lesen der Datei.", true);
String msg = factory.getLanguageConfigurator().getSelectedLanguage("IOException"); String msg = factory.getLanguageConfigurator().getSelectedLanguage("IOException");
logger.warning("Failed to open tournament file Error: " + e);
printMessageToFooter(msg, true); printMessageToFooter(msg, true);
} }
} }

View File

@ -2,7 +2,6 @@ package ch.zhaw.projekt2.turnierverwaltung;
import javafx.scene.control.Labeled; import javafx.scene.control.Labeled;
import javafx.scene.control.MenuItem; import javafx.scene.control.MenuItem;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -103,11 +102,9 @@ public class LanguageConfigurator {
englishDictionary.put("participantNotExist","Participant does not exist"); englishDictionary.put("participantNotExist","Participant does not exist");
germanDictionary.put("placeNotExist","Teilnehmer existiert nicht"); germanDictionary.put("placeNotExist","Teilnehmer existiert nicht");
englishDictionary.put("placeNotExist","Participant does not exist"); englishDictionary.put("placeNotExist","Participant does not exist");
//SaveMsg //SaveMsg
germanDictionary.put("save","Zuletzt gespeichert: "); germanDictionary.put("save","Zuletzt gespeichert: ");
englishDictionary.put("save","Last saved: "); englishDictionary.put("save","Last saved: ");
//Alert //Alert
germanDictionary.put("yes","Ja"); germanDictionary.put("yes","Ja");
englishDictionary.put("yes","Yes"); englishDictionary.put("yes","Yes");
@ -119,7 +116,6 @@ public class LanguageConfigurator {
englishDictionary.put("headerDelete","Delete Tournament?"); 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."); 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."); 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"); germanDictionary.put("titleSchedule","Neu erstellen");
englishDictionary.put("titleSchedule","Create new"); englishDictionary.put("titleSchedule","Create new");
germanDictionary.put("headerSchedule","Spielplan neu erstellen?"); germanDictionary.put("headerSchedule","Spielplan neu erstellen?");

View File

@ -4,7 +4,6 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.logging.Logger; import java.util.logging.Logger;
/** /**
* Class Team represents a team that can be added to a tournament * Class Team represents a team that can be added to a tournament
* (in the prototype there is no functionality for the team) * (in the prototype there is no functionality for the team)
@ -22,7 +21,7 @@ public class Team implements Participant {
* @param name the new name to be set * @param name the new name to be set
*/ */
public Team(String name) { 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); setName(name);
players = new ArrayList<>(); players = new ArrayList<>();
} }

View File

@ -1,7 +1,6 @@
package ch.zhaw.projekt2.turnierverwaltung; package ch.zhaw.projekt2.turnierverwaltung;
import javafx.application.Platform; import javafx.application.Platform;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;

View File

@ -21,7 +21,6 @@ public class MainWindow extends Application {
private Factory factory = new Factory(fileIO, tournamentDecorator, languageConfigurator); private Factory factory = new Factory(fileIO, tournamentDecorator, languageConfigurator);
private static final Logger logger = Logger.getLogger(FileIO.class.getCanonicalName()); private static final Logger logger = Logger.getLogger(FileIO.class.getCanonicalName());
/** /**
* Start method used to initialize the main window and load it's needed component * 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 * Also sets the scene and set some values like min width and height

View File

@ -7,6 +7,7 @@ import javafx.fxml.FXML;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.control.Menu; import javafx.scene.control.Menu;
import javafx.scene.control.MenuItem; import javafx.scene.control.MenuItem;
import java.util.logging.Logger;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -30,17 +31,19 @@ public class MainWindowController extends FXController {
@FXML @FXML
private Menu menuItemLanguage; private Menu menuItemLanguage;
/** /**
* Method changes the language Setting to german * Method changes the language Setting to german
*/ */
@FXML @FXML
void changeLangToGerman() { void changeLangToGerman() {
getLanguageConfigurator().changeLanguage(LanguageConfigurator.Language.GERMAN); getLanguageConfigurator().changeLanguage(LanguageConfigurator.Language.GERMAN);
logger.fine("language setting changed to german");
} }
@FXML @FXML
void changeLangToEnglish() { void changeLangToEnglish() {
getLanguageConfigurator().changeLanguage(LanguageConfigurator.Language.ENGLISH); getLanguageConfigurator().changeLanguage(LanguageConfigurator.Language.ENGLISH);
logger.fine("language setting changed to english");
} }
/** /**
@ -63,7 +66,9 @@ public class MainWindowController extends FXController {
} }
/**
* There is no content to load
*/
@Override @Override
public void loadContent() { public void loadContent() {
} }

View File

@ -6,6 +6,9 @@ import ch.zhaw.projekt2.turnierverwaltung.LanguageConfigurator;
import javafx.scene.control.Alert; import javafx.scene.control.Alert;
import javafx.scene.control.ButtonBar; import javafx.scene.control.ButtonBar;
import javafx.scene.control.ButtonType; 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; import java.util.logging.Logger;
@ -23,6 +26,9 @@ public class AlertNewSchedule extends Alert {
private String headerDelete; private String headerDelete;
private String contentDelete; private String contentDelete;
/**
* Popup to ask the user if he is sure that he wants to reshuffle the game board.
*/
public AlertNewSchedule(LanguageConfigurator languageConfigurator){ public AlertNewSchedule(LanguageConfigurator languageConfigurator){
super(Alert.AlertType.WARNING); super(Alert.AlertType.WARNING);
yes = languageConfigurator.getSelectedLanguage("yes"); yes = languageConfigurator.getSelectedLanguage("yes");

View File

@ -45,7 +45,7 @@ public class GameController extends FXController{
} }
@FXML @FXML
void saveGameResult(Event event) { void saveGameResult() {
gameDecorator.saveGameResult(pointsTeamOne.getText(), pointsTeamTwo.getText()); gameDecorator.saveGameResult(pointsTeamOne.getText(), pointsTeamTwo.getText());
} }

View File

@ -1,29 +1,51 @@
package ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView; package ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView;
import ch.zhaw.projekt2.turnierverwaltung.*; import ch.zhaw.projekt2.turnierverwaltung.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/**
* This Class is used by the GameController for additional functionality and holds the listeners and the Model Game
*/
public class GameDecorator implements IsObservable{ public class GameDecorator implements IsObservable{
private Game game; private Game game;
private List<IsObserver> listener = new ArrayList<>(); private List<IsObserver> listener = new ArrayList<>();
/**
* Setup the GameDecorator
*
* @param game Model for the Controller
*/
public GameDecorator (Game game) { public GameDecorator (Game game) {
this.game = game; this.game = game;
} }
/**
* Method adds a new Listener to the listener list
*
* @param observer that is being added to the Listener List
*/
@Override @Override
public void addListener(IsObserver observer) { public void addListener(IsObserver observer) {
listener.add(observer); listener.add(observer);
} }
/**
* Removes a Listener from the Listener List
*
* @param observer the Listener to be removed
*/
@Override @Override
public void removeListener(IsObserver observer) { public void removeListener(IsObserver observer) {
listener.remove(observer); listener.remove(observer);
} }
/**
* Saves the Gameresult in the model
*
* @param points1 points achieved in textfield one
* @param points2 points achieved in textfield two
*/
public void saveGameResult(String points1, String points2){ public void saveGameResult(String points1, String points2){
if(points1.length() > 0){ if(points1.length() > 0){
game.setPoints1(Integer.parseInt(points1)); game.setPoints1(Integer.parseInt(points1));
@ -38,19 +60,35 @@ public class GameDecorator implements IsObservable{
informListener(); informListener();
} }
/**
* Saves the Place in the Model
*
* @param place
*/
public void saveGamePlace(Place place){ public void saveGamePlace(Place place){
game.setPlace(place); game.setPlace(place);
informListener(); informListener();
} }
/**
* @return game points from player one
*/
public String getPoints1() { public String getPoints1() {
return String.valueOf(game.getPoints1()); return String.valueOf(game.getPoints1());
} }
/**
*
*@return game points from player two
*/
public String getPoints2() { public String getPoints2() {
return String.valueOf(game.getPoints2()); return String.valueOf(game.getPoints2());
} }
/**
*
* @return returns Gameparticipant one
*/
public String getParticipantOne() { public String getParticipantOne() {
if (game.getParticipant1() != null) { if (game.getParticipant1() != null) {
return game.getParticipant1().toString(); return game.getParticipant1().toString();
@ -58,6 +96,10 @@ public class GameDecorator implements IsObservable{
return "1"; return "1";
} }
/**
*
* @return returns Gameparticipant two
*/
public String getParticipantTwo() { public String getParticipantTwo() {
if (game.getParticipant2() != null) { if (game.getParticipant2() != null) {
return game.getParticipant2().toString(); return game.getParticipant2().toString();
@ -65,15 +107,25 @@ public class GameDecorator implements IsObservable{
return "2"; return "2";
} }
/**
* calls method in model to refresh participant
*/
public void refreshParticipants(){ public void refreshParticipants(){
game.refreshParticipants(); game.refreshParticipants();
informListener(); informListener();
} }
/**
*
* @return place
*/
public Place getPlace() { public Place getPlace() {
return game.getPlace(); return game.getPlace();
} }
/**
* Method that informs all listeners of an update.
*/
public void informListener() { public void informListener() {
for(IsObserver observer : listener) { for(IsObserver observer : listener) {
observer.update(); observer.update();

View File

@ -14,6 +14,11 @@ import javafx.scene.input.MouseEvent;
import javafx.scene.layout.GridPane; import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import java.util.logging.Logger;
/**
* Controller of Participant
*/
public class ParticipantFormularController extends FXController { public class ParticipantFormularController extends FXController {
@FXML @FXML
@ -68,8 +73,14 @@ public class ParticipantFormularController extends FXController {
@FXML @FXML
private Button saveBtn; private Button saveBtn;
private static final Logger logger = Logger.getLogger(ParticipantFormularController.class.getCanonicalName());
/**
* Shares GUI Elements with the LanguageConfigurator
*/
@Override @Override
public void shareGUIElementWithLanguageConfigurator() { public void shareGUIElementWithLanguageConfigurator() {
logger.fine("sharing GUI Elements");
getLanguageConfigurator().recieveLabel(participantListTitle); getLanguageConfigurator().recieveLabel(participantListTitle);
getLanguageConfigurator().recieveLabel(closeBtn); getLanguageConfigurator().recieveLabel(closeBtn);
getLanguageConfigurator().recieveLabel(deleteBtn); getLanguageConfigurator().recieveLabel(deleteBtn);
@ -81,8 +92,11 @@ public class ParticipantFormularController extends FXController {
getLanguageConfigurator().recieveLabel(saveBtn); getLanguageConfigurator().recieveLabel(saveBtn);
} }
/**
* Changes the current selection
*/
@FXML @FXML
void changedSelection(MouseEvent event){ void changedSelection(){
Player participant = (Player) participantListView.getSelectionModel().getSelectedItems().get(0); Player participant = (Player) participantListView.getSelectionModel().getSelectedItems().get(0);
participantNameTextField.setText(participant.getName()); participantNameTextField.setText(participant.getName());
firstNameTextField.setText(participant.getFirstName()); firstNameTextField.setText(participant.getFirstName());
@ -90,12 +104,18 @@ public class ParticipantFormularController extends FXController {
birthDateTextField.setText(participant.getFormattedDateOfBirth()); birthDateTextField.setText(participant.getFormattedDateOfBirth());
} }
/**
* Saves a new Participant and clears form
*/
@FXML @FXML
void saveParticipant(ActionEvent event) { void saveParticipant() {
getTournamentDecorator().savePlayer(firstNameTextField.getText(), participantNameTextField.getText(), phoneNumberTextField.getText(), birthDateTextField.getText()); getTournamentDecorator().savePlayer(firstNameTextField.getText(), participantNameTextField.getText(), phoneNumberTextField.getText(), birthDateTextField.getText());
clearFormular(); clearFormular();
} }
/**
* Clears current form
*/
private void clearFormular() { private void clearFormular() {
firstNameTextField.clear(); firstNameTextField.clear();
participantNameTextField.clear(); participantNameTextField.clear();
@ -103,19 +123,30 @@ public class ParticipantFormularController extends FXController {
birthDateTextField.clear(); birthDateTextField.clear();
} }
/**
* Deletes the selected participant.
*/
@FXML @FXML
void delete(ActionEvent event) { void delete() {
Participant participant = participantListView.getSelectionModel().getSelectedItems().get(0); Participant participant = participantListView.getSelectionModel().getSelectedItems().get(0);
logger.fine("deleting participant:" + participant);
getTournamentDecorator().deleteParticipant(participant); getTournamentDecorator().deleteParticipant(participant);
} }
/**
* Closes the participant form
*/
@FXML @FXML
void close(ActionEvent event) { void close() {
getFactoryDecorator().openScheduleView(); getFactoryDecorator().openScheduleView();
} }
/**
* Loads the previously saved content and puts it in the list
*/
@Override @Override
public void loadContent() { public void loadContent() {
logger.fine("loading and placing it into the list");
Tournament tournament = getTournamentDecorator().getTournament(); Tournament tournament = getTournamentDecorator().getTournament();
if(tournament != null){ if(tournament != null){
participantListView.setItems(tournament.getParticipants()); participantListView.setItems(tournament.getParticipants());

View File

@ -0,0 +1,38 @@
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();
}
}
}

View File

@ -0,0 +1,41 @@
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());
}
}

View File

@ -0,0 +1,18 @@
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"));
}
}

View File

@ -0,0 +1,25 @@
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();
}
}
}

View File

@ -0,0 +1,36 @@
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();
}
}
}

View File

@ -0,0 +1,39 @@
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();
}
}
}

View File

@ -0,0 +1,31 @@
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")));
}
}

View File

@ -44,20 +44,21 @@ public class TournamentTest {
//Checks if one Participant gets added //Checks if one Participant gets added
Participant participantOne = Mockito.mock(Player.class); Participant participantOne = Mockito.mock(Player.class);
when(participantOne.equals(any(Participant.class))).thenReturn(false); when(participantOne.equals(any(Participant.class))).thenReturn(false);
try {
assertEquals(0, tournament.getParticipants().size()); assertEquals(0, tournament.getParticipants().size());
tournament.saveParticipant(participantOne); tournament.saveParticipant(participantOne);
assertEquals(1, tournament.getParticipants().size()); assertEquals(1, tournament.getParticipants().size());
//Checks if a second Participant gets added
//Checks if a second Participant gets added Participant participantTwo = Mockito.mock(Player.class);
Participant participantTwo = Mockito.mock(Player.class); tournament.saveParticipant(participantTwo);
tournament.saveParticipant(participantTwo); assertEquals(2, tournament.getParticipants().size());
assertEquals(2, tournament.getParticipants().size()); //Checks if a allready added Particpant does not get added
when(participantOne.equals(any(Participant.class))).thenReturn(true);
//Checks if a allready added Particpant does not get added tournament.saveParticipant(participantTwo);
when(participantOne.equals(any(Participant.class))).thenReturn(true); assertEquals(2, tournament.getParticipants().size());
tournament.saveParticipant(participantTwo); } catch (Person.InvalidPhoneNumberException e) {
assertEquals(2, tournament.getParticipants().size()); fail();
}
} }
@ -69,13 +70,13 @@ public class TournamentTest {
//Checks if Error is thrown if Participant not in list //Checks if Error is thrown if Participant not in list
assertThrows(Tournament.ParticipantNotExistsException.class, () -> tournament.removeParticipant(participant)); assertThrows(Tournament.ParticipantNotExistsException.class, () -> tournament.removeParticipant(participant));
//Checks if participant gets removed
tournament.saveParticipant(participant);
assertEquals(1, tournament.getParticipants().size());
try { try {
//Checks if participant gets removed
tournament.saveParticipant(participant);
assertEquals(1, tournament.getParticipants().size());
tournament.removeParticipant(participant); tournament.removeParticipant(participant);
assertEquals(0, tournament.getParticipants().size()); assertEquals(0, tournament.getParticipants().size());
} catch (Tournament.ParticipantNotExistsException e) { } catch (Tournament.ParticipantNotExistsException | Person.InvalidPhoneNumberException e) {
fail(); fail();
} }
} }
@ -126,13 +127,18 @@ public class TournamentTest {
tournament.createGameSchedule(); tournament.createGameSchedule();
assertEquals(2, tournament.getGameList().size()); assertEquals(2, tournament.getGameList().size());
tournament.saveParticipant(participant); tournament.saveParticipant(participant);
} catch (Tournament.NumberOfParticipantInvalidException e) { } catch (Tournament.NumberOfParticipantInvalidException | Person.InvalidPhoneNumberException e) {
fail(); fail();
} }
} else { } else {
assertThrows(Tournament.NumberOfParticipantInvalidException.class, () -> tournament.createGameSchedule()); assertThrows(Tournament.NumberOfParticipantInvalidException.class, () -> tournament.createGameSchedule());
tournament.saveParticipant(participant); try {
tournament.saveParticipant(participant);
} catch (Person.InvalidPhoneNumberException e) {
e.printStackTrace();
}
} }
} }
try { try {