From 9b9dbda152c50fc774e1f72a261199f06e2f7cd4 Mon Sep 17 00:00:00 2001 From: fdai7736 Date: Tue, 23 Jan 2024 23:55:30 +0100 Subject: [PATCH 1/4] Refactoring: change Class name Cards to Card --- .../onses/models/{Cards.java => Card.java} | 4 +- .../onses/{CardsTest.java => CardTest.java} | 40 +++++++++---------- 2 files changed, 22 insertions(+), 22 deletions(-) rename src/main/java/de/hsfulda/onses/models/{Cards.java => Card.java} (93%) rename src/test/java/de/hsfulda/onses/{CardsTest.java => CardTest.java} (56%) diff --git a/src/main/java/de/hsfulda/onses/models/Cards.java b/src/main/java/de/hsfulda/onses/models/Card.java similarity index 93% rename from src/main/java/de/hsfulda/onses/models/Cards.java rename to src/main/java/de/hsfulda/onses/models/Card.java index d2aeb30..216a62b 100644 --- a/src/main/java/de/hsfulda/onses/models/Cards.java +++ b/src/main/java/de/hsfulda/onses/models/Card.java @@ -1,6 +1,6 @@ package de.hsfulda.onses.models; -public class Cards { +public class Card { public enum ecolor { RED, BLUE, GREEN, YELLOW, BLACK; @@ -25,7 +25,7 @@ public class Cards { private final evalue value; - public Cards(int id, ecolor color, evalue value) + public Card(int id, ecolor color, evalue value) { this.id = id; this.color = color; diff --git a/src/test/java/de/hsfulda/onses/CardsTest.java b/src/test/java/de/hsfulda/onses/CardTest.java similarity index 56% rename from src/test/java/de/hsfulda/onses/CardsTest.java rename to src/test/java/de/hsfulda/onses/CardTest.java index ab7e6d7..d3c88bc 100644 --- a/src/test/java/de/hsfulda/onses/CardsTest.java +++ b/src/test/java/de/hsfulda/onses/CardTest.java @@ -5,9 +5,9 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; -import de.hsfulda.onses.models.Cards; +import de.hsfulda.onses.models.Card; -public class CardsTest { +public class CardTest { @Test @DisplayName("CardGetID5") @@ -17,7 +17,7 @@ public class CardsTest { int expected = 5; int ID = 5; // act - Cards testcard = new Cards(ID, Cards.ecolor.BLACK, Cards.evalue.FIVE); + Card testcard = new Card(ID, Card.ecolor.BLACK, Card.evalue.FIVE); int answer = testcard.getId(); // assert assertEquals(expected, answer); @@ -31,7 +31,7 @@ public class CardsTest { int expected = 112; int ID = 112; // act - Cards testcard = new Cards(ID, Cards.ecolor.BLUE, Cards.evalue.CHOOSEDRAW); + Card testcard = new Card(ID, Card.ecolor.BLUE, Card.evalue.CHOOSEDRAW); int answer = testcard.getId(); // assert assertEquals(expected, answer); @@ -43,11 +43,11 @@ public class CardsTest { public void CardTestGetColorBlue() { // arrange - Cards.ecolor expected = Cards.ecolor.BLUE; - Cards.ecolor color = Cards.ecolor.BLUE; + Card.ecolor expected = Card.ecolor.BLUE; + Card.ecolor color = Card.ecolor.BLUE; // act - Cards testcard = new Cards(9, color, Cards.evalue.FIVE); - Cards.ecolor answer = testcard.getColor(); + Card testcard = new Card(9, color, Card.evalue.FIVE); + Card.ecolor answer = testcard.getColor(); // assert assertEquals(expected, answer); } @@ -56,11 +56,11 @@ public class CardsTest { public void CardTestGetColorBlack() { // arrange - Cards.ecolor expected = Cards.ecolor.BLACK; - Cards.ecolor color = Cards.ecolor.BLACK; + Card.ecolor expected = Card.ecolor.BLACK; + Card.ecolor color = Card.ecolor.BLACK; // act - Cards testcard = new Cards(15, color, Cards.evalue.CHOOSE); - Cards.ecolor answer = testcard.getColor(); + Card testcard = new Card(15, color, Card.evalue.CHOOSE); + Card.ecolor answer = testcard.getColor(); // assert assertEquals(expected, answer); } @@ -71,11 +71,11 @@ public class CardsTest { public void CardTestGetValueThree() { // arrange - Cards.evalue expected = Cards.evalue.THREE; - Cards.evalue value = Cards.evalue.THREE; + Card.evalue expected = Card.evalue.THREE; + Card.evalue value = Card.evalue.THREE; // act - Cards testcard = new Cards(2, Cards.ecolor.BLUE, value); - Cards.evalue answer = testcard.getValue(); + Card testcard = new Card(2, Card.ecolor.BLUE, value); + Card.evalue answer = testcard.getValue(); // assert assertEquals(expected, answer); } @@ -84,11 +84,11 @@ public class CardsTest { public void CardTestGetValueSkip() { // arrange - Cards.evalue expected = Cards.evalue.SKIP; - Cards.evalue value = Cards.evalue.SKIP; + Card.evalue expected = Card.evalue.SKIP; + Card.evalue value = Card.evalue.SKIP; // act - Cards testcard = new Cards(19, Cards.ecolor.BLACK, value); - Cards.evalue answer = testcard.getValue(); + Card testcard = new Card(19, Card.ecolor.BLACK, value); + Card.evalue answer = testcard.getValue(); // assert assertEquals(expected, answer); } From d78f6b6eeefb721d11f86b499bd1c5eb8075234d Mon Sep 17 00:00:00 2001 From: fdai7736 Date: Tue, 23 Jan 2024 23:57:38 +0100 Subject: [PATCH 2/4] Refactoring: change enum Name to Color --- .../java/de/hsfulda/onses/models/Card.java | 14 ++++--------- src/test/java/de/hsfulda/onses/CardTest.java | 20 +++++++++---------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/models/Card.java b/src/main/java/de/hsfulda/onses/models/Card.java index 216a62b..d82f13b 100644 --- a/src/main/java/de/hsfulda/onses/models/Card.java +++ b/src/main/java/de/hsfulda/onses/models/Card.java @@ -2,14 +2,8 @@ package de.hsfulda.onses.models; public class Card { - public enum ecolor { + public enum Color { RED, BLUE, GREEN, YELLOW, BLACK; - - private static final ecolor[] colors = ecolor.values(); - public static ecolor getColors (int n) - { - return ecolor.colors[n]; - } }; public enum evalue { ZERO, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, DRAWTWO, SKIP, REVERSE, CHOOSE, CHOOSEDRAW; @@ -21,11 +15,11 @@ public class Card { }; private final int id; - private final ecolor color; + private final Color color; private final evalue value; - public Card(int id, ecolor color, evalue value) + public Card(int id, Color color, evalue value) { this.id = id; this.color = color; @@ -37,7 +31,7 @@ public class Card { return this.id; } - public ecolor getColor() { + public Color getColor() { return this.color; } diff --git a/src/test/java/de/hsfulda/onses/CardTest.java b/src/test/java/de/hsfulda/onses/CardTest.java index d3c88bc..fd5efab 100644 --- a/src/test/java/de/hsfulda/onses/CardTest.java +++ b/src/test/java/de/hsfulda/onses/CardTest.java @@ -17,7 +17,7 @@ public class CardTest { int expected = 5; int ID = 5; // act - Card testcard = new Card(ID, Card.ecolor.BLACK, Card.evalue.FIVE); + Card testcard = new Card(ID, Card.Color.BLACK, Card.evalue.FIVE); int answer = testcard.getId(); // assert assertEquals(expected, answer); @@ -31,7 +31,7 @@ public class CardTest { int expected = 112; int ID = 112; // act - Card testcard = new Card(ID, Card.ecolor.BLUE, Card.evalue.CHOOSEDRAW); + Card testcard = new Card(ID, Card.Color.BLUE, Card.evalue.CHOOSEDRAW); int answer = testcard.getId(); // assert assertEquals(expected, answer); @@ -43,11 +43,11 @@ public class CardTest { public void CardTestGetColorBlue() { // arrange - Card.ecolor expected = Card.ecolor.BLUE; - Card.ecolor color = Card.ecolor.BLUE; + Card.Color expected = Card.Color.BLUE; + Card.Color color = Card.Color.BLUE; // act Card testcard = new Card(9, color, Card.evalue.FIVE); - Card.ecolor answer = testcard.getColor(); + Card.Color answer = testcard.getColor(); // assert assertEquals(expected, answer); } @@ -56,11 +56,11 @@ public class CardTest { public void CardTestGetColorBlack() { // arrange - Card.ecolor expected = Card.ecolor.BLACK; - Card.ecolor color = Card.ecolor.BLACK; + Card.Color expected = Card.Color.BLACK; + Card.Color color = Card.Color.BLACK; // act Card testcard = new Card(15, color, Card.evalue.CHOOSE); - Card.ecolor answer = testcard.getColor(); + Card.Color answer = testcard.getColor(); // assert assertEquals(expected, answer); } @@ -74,7 +74,7 @@ public class CardTest { Card.evalue expected = Card.evalue.THREE; Card.evalue value = Card.evalue.THREE; // act - Card testcard = new Card(2, Card.ecolor.BLUE, value); + Card testcard = new Card(2, Card.Color.BLUE, value); Card.evalue answer = testcard.getValue(); // assert assertEquals(expected, answer); @@ -87,7 +87,7 @@ public class CardTest { Card.evalue expected = Card.evalue.SKIP; Card.evalue value = Card.evalue.SKIP; // act - Card testcard = new Card(19, Card.ecolor.BLACK, value); + Card testcard = new Card(19, Card.Color.BLACK, value); Card.evalue answer = testcard.getValue(); // assert assertEquals(expected, answer); From 39beb4acc65b6cf98447287e1c048d4e8f4d6703 Mon Sep 17 00:00:00 2001 From: fdai7736 Date: Wed, 24 Jan 2024 00:08:07 +0100 Subject: [PATCH 3/4] Refactoring: change remove Constructor to Setter --- .../java/de/hsfulda/onses/models/Card.java | 47 ++++++++++--------- src/test/java/de/hsfulda/onses/CardTest.java | 12 ++--- 2 files changed, 32 insertions(+), 27 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/models/Card.java b/src/main/java/de/hsfulda/onses/models/Card.java index d82f13b..ab34ad8 100644 --- a/src/main/java/de/hsfulda/onses/models/Card.java +++ b/src/main/java/de/hsfulda/onses/models/Card.java @@ -1,31 +1,36 @@ package de.hsfulda.onses.models; public class Card { - - public enum Color { - RED, BLUE, GREEN, YELLOW, BLACK; - }; - public enum evalue { - ZERO, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, DRAWTWO, SKIP, REVERSE, CHOOSE, CHOOSEDRAW; - - private static final evalue[] values = evalue.values(); - public static evalue getValue(int n) { - return evalue.values[n]; - } - }; - - private final int id; - private final Color color; - private final evalue value; - - - public Card(int id, Color color, evalue value) - { + private int id; + private Color color; + private evalue value; + + public enum Color { + RED, BLUE, GREEN, YELLOW, BLACK; + }; + public enum evalue { + ZERO, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, DRAWTWO, SKIP, REVERSE, CHOOSE, CHOOSEDRAW; + + private static final evalue[] values = evalue.values(); + public static evalue getValue(int n) { + return evalue.values[n]; + } + }; + + public Card setId(int id) { this.id = id; + return this; + } + + public Card setColor(Color color) { this.color = color; - this.value = value; + return this; } + public Card setValue(evalue value) { + this.value = value; + return this; + } public int getId() { return this.id; diff --git a/src/test/java/de/hsfulda/onses/CardTest.java b/src/test/java/de/hsfulda/onses/CardTest.java index fd5efab..fc84c62 100644 --- a/src/test/java/de/hsfulda/onses/CardTest.java +++ b/src/test/java/de/hsfulda/onses/CardTest.java @@ -17,7 +17,7 @@ public class CardTest { int expected = 5; int ID = 5; // 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(); // assert assertEquals(expected, answer); @@ -31,7 +31,7 @@ public class CardTest { int expected = 112; int ID = 112; // 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(); // assert assertEquals(expected, answer); @@ -46,7 +46,7 @@ public class CardTest { Card.Color expected = Card.Color.BLUE; Card.Color color = Card.Color.BLUE; // 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(); // assert assertEquals(expected, answer); @@ -59,7 +59,7 @@ public class CardTest { Card.Color expected = Card.Color.BLACK; Card.Color color = Card.Color.BLACK; // 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(); // assert assertEquals(expected, answer); @@ -74,7 +74,7 @@ public class CardTest { Card.evalue expected = Card.evalue.THREE; Card.evalue value = Card.evalue.THREE; // 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(); // assert assertEquals(expected, answer); @@ -87,7 +87,7 @@ public class CardTest { Card.evalue expected = Card.evalue.SKIP; Card.evalue value = Card.evalue.SKIP; // 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(); // assert assertEquals(expected, answer); From b373cdd9944a6c31f3d20f5cbf62f387372dc86a Mon Sep 17 00:00:00 2001 From: fdai7736 Date: Wed, 24 Jan 2024 00:09:11 +0100 Subject: [PATCH 4/4] Refactoring: change name from Enum Value --- .../java/de/hsfulda/onses/models/Card.java | 13 ++++-------- src/test/java/de/hsfulda/onses/CardTest.java | 20 +++++++++---------- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/models/Card.java b/src/main/java/de/hsfulda/onses/models/Card.java index ab34ad8..74d2393 100644 --- a/src/main/java/de/hsfulda/onses/models/Card.java +++ b/src/main/java/de/hsfulda/onses/models/Card.java @@ -3,18 +3,13 @@ package de.hsfulda.onses.models; public class Card { private int id; private Color color; - private evalue value; + private Value value; public enum Color { RED, BLUE, GREEN, YELLOW, BLACK; }; - public enum evalue { + public enum Value { ZERO, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, DRAWTWO, SKIP, REVERSE, CHOOSE, CHOOSEDRAW; - - private static final evalue[] values = evalue.values(); - public static evalue getValue(int n) { - return evalue.values[n]; - } }; public Card setId(int id) { @@ -27,7 +22,7 @@ public class Card { return this; } - public Card setValue(evalue value) { + public Card setValue(Value value) { this.value = value; return this; } @@ -40,7 +35,7 @@ public class Card { return this.color; } - public evalue getValue() { + public Value getValue() { return this.value; } } diff --git a/src/test/java/de/hsfulda/onses/CardTest.java b/src/test/java/de/hsfulda/onses/CardTest.java index fc84c62..f35fa7a 100644 --- a/src/test/java/de/hsfulda/onses/CardTest.java +++ b/src/test/java/de/hsfulda/onses/CardTest.java @@ -17,7 +17,7 @@ public class CardTest { int expected = 5; int ID = 5; // act - Card testcard = new Card().setId(ID).setColor(Card.Color.BLACK).setValue(Card.evalue.FIVE); + Card testcard = new Card().setId(ID).setColor(Card.Color.BLACK).setValue(Card.Value.FIVE); int answer = testcard.getId(); // assert assertEquals(expected, answer); @@ -31,7 +31,7 @@ public class CardTest { int expected = 112; int ID = 112; // act - Card testcard = new Card().setId(ID).setColor(Card.Color.BLUE).setValue(Card.evalue.CHOOSEDRAW); + Card testcard = new Card().setId(ID).setColor(Card.Color.BLUE).setValue(Card.Value.CHOOSEDRAW); int answer = testcard.getId(); // assert assertEquals(expected, answer); @@ -46,7 +46,7 @@ public class CardTest { Card.Color expected = Card.Color.BLUE; Card.Color color = Card.Color.BLUE; // act - Card testcard = new Card().setId(9).setColor(color).setValue(Card.evalue.FIVE); + Card testcard = new Card().setId(9).setColor(color).setValue(Card.Value.FIVE); Card.Color answer = testcard.getColor(); // assert assertEquals(expected, answer); @@ -59,7 +59,7 @@ public class CardTest { Card.Color expected = Card.Color.BLACK; Card.Color color = Card.Color.BLACK; // act - Card testcard = new Card().setId(15).setColor(color).setValue(Card.evalue.CHOOSE); + Card testcard = new Card().setId(15).setColor(color).setValue(Card.Value.CHOOSE); Card.Color answer = testcard.getColor(); // assert assertEquals(expected, answer); @@ -71,11 +71,11 @@ public class CardTest { public void CardTestGetValueThree() { // arrange - Card.evalue expected = Card.evalue.THREE; - Card.evalue value = Card.evalue.THREE; + Card.Value expected = Card.Value.THREE; + Card.Value value = Card.Value.THREE; // act Card testcard = new Card().setId(2).setColor(Card.Color.BLUE).setValue(value); - Card.evalue answer = testcard.getValue(); + Card.Value answer = testcard.getValue(); // assert assertEquals(expected, answer); } @@ -84,11 +84,11 @@ public class CardTest { public void CardTestGetValueSkip() { // arrange - Card.evalue expected = Card.evalue.SKIP; - Card.evalue value = Card.evalue.SKIP; + Card.Value expected = Card.Value.SKIP; + Card.Value value = Card.Value.SKIP; // act Card testcard = new Card().setId(19).setColor(Card.Color.BLACK).setValue(value); - Card.evalue answer = testcard.getValue(); + Card.Value answer = testcard.getValue(); // assert assertEquals(expected, answer); }