mirror of
https://github.com/kmitresse/Cards-Rush.git
synced 2026-05-14 01:21:49 +00:00
feat: dev-web - Pojo's tests completed
This commit is contained in:
@@ -44,6 +44,9 @@ public class Card {
|
||||
* @see Value
|
||||
*/
|
||||
public Card(Color color, Value value) {
|
||||
if (color == null || value == null) {
|
||||
throw new IllegalArgumentException("Color cannot be null");
|
||||
}
|
||||
this.color = color;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@@ -80,16 +80,10 @@ public class Game implements Serializable {
|
||||
* @param nbValuesPerColor le nombre de valeurs par couleur
|
||||
*/
|
||||
public Game(Difficulty difficulty, int nbRounds, int nbColors, int nbValuesPerColor) {
|
||||
if (isValidNumberRound(nbRounds, nbColors, nbValuesPerColor)){
|
||||
throw new IllegalArgumentException("Le nombre de tours doit être compris entre 1 et " + nbColors * nbValuesPerColor);
|
||||
}
|
||||
this.difficulty = difficulty;
|
||||
if (nbRounds < 1 || nbRounds > nbColors * nbValuesPerColor){
|
||||
throw new IllegalArgumentException("Le nombre de tours doit être supérieur ou égal à 1");
|
||||
}
|
||||
if (nbColors < 1 || nbColors > Card.Color.values().length) {
|
||||
throw new IllegalArgumentException("Le nombre de couleurs doit être compris entre 1 et " + Card.Color.values().length);
|
||||
}
|
||||
if (nbValuesPerColor < 1 || nbValuesPerColor > Card.Value.values().length) {
|
||||
throw new IllegalArgumentException("Le nombre de valeurs par couleur doit être compris entre 1 et " + Card.Value.values().length);
|
||||
}
|
||||
this.nbRounds = nbRounds;
|
||||
this.nbColors = nbColors;
|
||||
this.nbValuesPerColor = nbValuesPerColor;
|
||||
@@ -109,22 +103,17 @@ public class Game implements Serializable {
|
||||
* @param players les joueurs de la partie
|
||||
*/
|
||||
public Game(BigDecimal id, Date createdAt, Difficulty difficulty, int nbRounds, int nbColors, int nbValuesPerColor, ArrayList<Player> players) {
|
||||
if (isValidNumberRound(nbRounds, nbColors, nbValuesPerColor)){
|
||||
throw new IllegalArgumentException("Le nombre de tours doit être compris entre 1 et " + nbColors * nbValuesPerColor);
|
||||
}
|
||||
this.id = id;
|
||||
this.createdAt = createdAt;
|
||||
this.difficulty = difficulty;
|
||||
if (nbRounds < 1 || nbRounds > nbColors * nbValuesPerColor){
|
||||
throw new IllegalArgumentException("Le nombre de tours doit être compris entre 1 et " + nbColors * nbValuesPerColor);
|
||||
}
|
||||
if (nbColors < 1 || nbColors > Card.Color.values().length) {
|
||||
throw new IllegalArgumentException("Le nombre de couleurs doit être compris entre 1 et " + Card.Color.values().length);
|
||||
}
|
||||
if (nbValuesPerColor < 1 || nbValuesPerColor > Card.Value.values().length) {
|
||||
throw new IllegalArgumentException("Le nombre de valeurs par couleur doit être compris entre 1 et " + Card.Value.values().length);
|
||||
}
|
||||
this.nbRounds = nbRounds;
|
||||
this.nbColors = nbColors;
|
||||
this.nbValuesPerColor = nbValuesPerColor;
|
||||
this.players = players;
|
||||
this.deck = new Deck(nbColors, nbValuesPerColor);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -269,9 +258,20 @@ public class Game implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isValidNumberRound(int nbRounds, int nbColors, int nbValuesPerColor){
|
||||
return nbRounds < 1 || nbRounds > nbColors * nbValuesPerColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("Game{id=%s, createdAt=%s}", id.toString(), createdAt.toString());
|
||||
return String.format("Game{id=%s, createdAt=%s, difficulty=%s, nbRounds=%d, nbColors=%d, nbValuesPerColor=%d}",
|
||||
id != null ? id.toString() : "null",
|
||||
createdAt != null ? createdAt.toString() : "null",
|
||||
difficulty != null ? difficulty.toString() : "null",
|
||||
nbRounds != 0 ? nbRounds : 0,
|
||||
nbColors != 0 ? nbColors : 0,
|
||||
nbValuesPerColor != 0 ? nbValuesPerColor : 0
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -267,7 +267,15 @@ public class Player implements Serializable {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("Player{id=%s, game=%s, user=%s, score=%d, winner=%b, clickCount=%d, rightClickCount=%d, rapidClickCount=%d}", id.toString(), game.toString(), user.toString(), score, winner, clickCount, rightClickCount, rapidClickCount);
|
||||
return String.format("Player{id=%s, game=%s, user=%s, score=%d, winner=%b, clickCount=%d, rightClickCount=%d, rapidClickCount=%d}",
|
||||
id != null ? id.toString() : "null",
|
||||
game != null ? game.toString() : "null",
|
||||
user != null ? user.toString() : "null",
|
||||
score,
|
||||
winner,
|
||||
clickCount,
|
||||
rightClickCount,
|
||||
rapidClickCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -133,12 +133,11 @@ public class RecoveryPasswordToken {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RecoveryPasswordToken{" +
|
||||
"id=" + id +
|
||||
", token='" + token + '\'' +
|
||||
", user=" + user +
|
||||
", expiresAt=" + expiresAt +
|
||||
'}';
|
||||
return String.format("RecoveryPasswordToken{id=%s, token=%s, user=%s, expiresAt=%s}",
|
||||
id != null ? id.toString() : "null",
|
||||
token != null ? token : "null",
|
||||
user != null ? user.toString() : "null",
|
||||
expiresAt != null ? expiresAt.toString() : "null");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -349,10 +349,10 @@ public class User implements Serializable {
|
||||
return String.format(
|
||||
"User{id='%s', username=%s, email=%s, birth='%s', gender='%s'}",
|
||||
id != null ? id.toString() : "null",
|
||||
username,
|
||||
email,
|
||||
birth.toString(),
|
||||
gender.toString()
|
||||
username != null ? username : "null",
|
||||
email != null ? email : "null",
|
||||
birth != null ? birth.toString() : "null",
|
||||
gender != null ? gender.toString() : "null"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user