Browse Source

Refactoring: change remove Constructor to Setter

main
fdai7736 11 months ago
parent
commit
39beb4acc6
  1. 21
      src/main/java/de/hsfulda/onses/models/Card.java
  2. 12
      src/test/java/de/hsfulda/onses/CardTest.java

21
src/main/java/de/hsfulda/onses/models/Card.java

@ -1,6 +1,9 @@
package de.hsfulda.onses.models; package de.hsfulda.onses.models;
public class Card { public class Card {
private int id;
private Color color;
private evalue value;
public enum Color { public enum Color {
RED, BLUE, GREEN, YELLOW, BLACK; RED, BLUE, GREEN, YELLOW, BLACK;
@ -14,18 +17,20 @@ public class Card {
} }
}; };
private final int id;
private final Color color;
private final evalue value;
public Card(int id, Color color, evalue value)
{
public Card setId(int id) {
this.id = id; this.id = id;
return this;
}
public Card setColor(Color color) {
this.color = color; this.color = color;
this.value = value;
return this;
} }
public Card setValue(evalue value) {
this.value = value;
return this;
}
public int getId() { public int getId() {
return this.id; return this.id;

12
src/test/java/de/hsfulda/onses/CardTest.java

@ -17,7 +17,7 @@ public class CardTest {
int expected = 5; int expected = 5;
int ID = 5; int ID = 5;
// act // act
Card testcard = new Card(ID, Card.Color.BLACK, Card.evalue.FIVE);
Card testcard = new Card().setId(ID).setColor(Card.Color.BLACK).setValue(Card.evalue.FIVE);
int answer = testcard.getId(); int answer = testcard.getId();
// assert // assert
assertEquals(expected, answer); assertEquals(expected, answer);
@ -31,7 +31,7 @@ public class CardTest {
int expected = 112; int expected = 112;
int ID = 112; int ID = 112;
// act // act
Card testcard = new Card(ID, Card.Color.BLUE, Card.evalue.CHOOSEDRAW);
Card testcard = new Card().setId(ID).setColor(Card.Color.BLUE).setValue(Card.evalue.CHOOSEDRAW);
int answer = testcard.getId(); int answer = testcard.getId();
// assert // assert
assertEquals(expected, answer); assertEquals(expected, answer);
@ -46,7 +46,7 @@ public class CardTest {
Card.Color expected = Card.Color.BLUE; Card.Color expected = Card.Color.BLUE;
Card.Color color = Card.Color.BLUE; Card.Color color = Card.Color.BLUE;
// act // act
Card testcard = new Card(9, color, Card.evalue.FIVE);
Card testcard = new Card().setId(9).setColor(color).setValue(Card.evalue.FIVE);
Card.Color answer = testcard.getColor(); Card.Color answer = testcard.getColor();
// assert // assert
assertEquals(expected, answer); assertEquals(expected, answer);
@ -59,7 +59,7 @@ public class CardTest {
Card.Color expected = Card.Color.BLACK; Card.Color expected = Card.Color.BLACK;
Card.Color color = Card.Color.BLACK; Card.Color color = Card.Color.BLACK;
// act // act
Card testcard = new Card(15, color, Card.evalue.CHOOSE);
Card testcard = new Card().setId(15).setColor(color).setValue(Card.evalue.CHOOSE);
Card.Color answer = testcard.getColor(); Card.Color answer = testcard.getColor();
// assert // assert
assertEquals(expected, answer); assertEquals(expected, answer);
@ -74,7 +74,7 @@ public class CardTest {
Card.evalue expected = Card.evalue.THREE; Card.evalue expected = Card.evalue.THREE;
Card.evalue value = Card.evalue.THREE; Card.evalue value = Card.evalue.THREE;
// act // act
Card testcard = new Card(2, Card.Color.BLUE, value);
Card testcard = new Card().setId(2).setColor(Card.Color.BLUE).setValue(value);
Card.evalue answer = testcard.getValue(); Card.evalue answer = testcard.getValue();
// assert // assert
assertEquals(expected, answer); assertEquals(expected, answer);
@ -87,7 +87,7 @@ public class CardTest {
Card.evalue expected = Card.evalue.SKIP; Card.evalue expected = Card.evalue.SKIP;
Card.evalue value = Card.evalue.SKIP; Card.evalue value = Card.evalue.SKIP;
// act // act
Card testcard = new Card(19, Card.Color.BLACK, value);
Card testcard = new Card().setId(19).setColor(Card.Color.BLACK).setValue(value);
Card.evalue answer = testcard.getValue(); Card.evalue answer = testcard.getValue();
// assert // assert
assertEquals(expected, answer); assertEquals(expected, answer);

Loading…
Cancel
Save