BAEL-3091: The Prototype Pattern in Java - Changes based on comments
This commit is contained in:
+24
-7
@@ -7,18 +7,35 @@ import org.junit.jupiter.api.Test;
|
||||
public class TreePrototypeUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenATreePrototypeWhenClonedThenCreateA_Clone() {
|
||||
public void givenAPlasticTreePrototypeWhenClonedThenCreateA_Clone() {
|
||||
double mass = 10.0;
|
||||
double height = 3.7;
|
||||
Position position = new Position(3, 7);
|
||||
Position otherPosition = new Position(4, 8);
|
||||
|
||||
Tree tree = new Tree(mass, height);
|
||||
tree.setPosition(position);
|
||||
Tree anotherTree = (Tree) tree.createA_Clone();
|
||||
anotherTree.setPosition(otherPosition);
|
||||
PlasticTree plasticTree = new PlasticTree(mass, height);
|
||||
plasticTree.setPosition(position);
|
||||
PlasticTree anotherPlasticTree = (PlasticTree) plasticTree.copy();
|
||||
anotherPlasticTree.setPosition(otherPosition);
|
||||
|
||||
assertEquals(position, tree.getPosition());
|
||||
assertEquals(otherPosition, anotherTree.getPosition());
|
||||
assertEquals(position, plasticTree.getPosition());
|
||||
assertEquals(otherPosition, anotherPlasticTree.getPosition());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAPineTreePrototypeWhenClonedThenCreateA_Clone() {
|
||||
double mass = 10.0;
|
||||
double height = 3.7;
|
||||
Position position = new Position(3, 7);
|
||||
Position otherPosition = new Position(4, 8);
|
||||
|
||||
PineTree pineTree = new PineTree(mass, height);
|
||||
pineTree.setPosition(position);
|
||||
PineTree anotherPineTree = (PineTree) pineTree.copy();
|
||||
anotherPineTree.setPosition(otherPosition);
|
||||
|
||||
assertEquals(position, pineTree.getPosition());
|
||||
assertEquals(otherPosition, anotherPineTree.getPosition());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user