Skip to content

Commit 8a1cb72

Browse files
committed
ensure all mock behaviors and game objects are unique
1 parent 79948be commit 8a1cb72

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

src/test/java/unittest/mock/graphics/MockGameObject.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@
66
import tech.fastj.systems.control.GameHandler;
77

88
import java.awt.Graphics2D;
9+
import java.util.Objects;
10+
import java.util.UUID;
911

1012
public class MockGameObject extends GameObject {
13+
14+
private final UUID id = UUID.randomUUID();
15+
1116
@Override
1217
public void destroy(GameHandler origin) {
1318
}
@@ -42,4 +47,24 @@ public void scale(Pointf scaleMod, Pointf centerpoint) {
4247
@Override
4348
public void render(Graphics2D g) {
4449
}
50+
51+
@Override
52+
public boolean equals(Object o) {
53+
if (this == o) {
54+
return true;
55+
}
56+
if (o == null || getClass() != o.getClass()) {
57+
return false;
58+
}
59+
if (!super.equals(o)) {
60+
return false;
61+
}
62+
MockGameObject that = (MockGameObject) o;
63+
return id.equals(that.id);
64+
}
65+
66+
@Override
67+
public int hashCode() {
68+
return Objects.hash(super.hashCode(), id);
69+
}
4570
}

src/test/java/unittest/mock/systems/behaviors/MockBehavior.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@
55
import tech.fastj.math.Pointf;
66
import tech.fastj.systems.behaviors.Behavior;
77

8+
import java.util.Objects;
9+
import java.util.UUID;
10+
811
public class MockBehavior implements Behavior {
912

13+
private final UUID id = UUID.randomUUID();
14+
1015
private Pointf pointf;
1116

1217
@Override
@@ -35,4 +40,21 @@ public void destroy() {
3540
public Pointf getPointf() {
3641
return pointf;
3742
}
43+
44+
@Override
45+
public boolean equals(Object o) {
46+
if (this == o) {
47+
return true;
48+
}
49+
if (o == null || getClass() != o.getClass()) {
50+
return false;
51+
}
52+
MockBehavior that = (MockBehavior) o;
53+
return id.equals(that.id) && Objects.equals(pointf, that.pointf);
54+
}
55+
56+
@Override
57+
public int hashCode() {
58+
return Objects.hash(id, pointf);
59+
}
3860
}

0 commit comments

Comments
 (0)