Skip to content

Commit 9038690

Browse files
committed
Add tests for PositionComposer class
1 parent eb4b1a0 commit 9038690

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.eternalcode.parcellockers.configuration.composer;
2+
3+
import com.eternalcode.parcellockers.shared.Position;
4+
import org.junit.jupiter.api.Test;
5+
import panda.std.AttemptFailedException;
6+
import panda.std.Result;
7+
8+
import static org.junit.jupiter.api.Assertions.assertEquals;
9+
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
10+
import static org.junit.jupiter.api.Assertions.assertThrows;
11+
import static org.junit.jupiter.api.Assertions.assertTrue;
12+
13+
class PositionComposerTest {
14+
15+
private final PositionComposer positionComposer = new PositionComposer();
16+
17+
@Test
18+
void testSerialize() {
19+
// Given
20+
Position position = new Position(10, 20, 30, "world");
21+
String expected = "Position{x=10, y=20, z=30, world='world'}";
22+
23+
// When
24+
Result<String, Exception> result = this.positionComposer.serialize(position);
25+
26+
// Then
27+
assertTrue(result.isOk());
28+
assertEquals(expected, result.get());
29+
}
30+
31+
@Test
32+
void testDeserialize() {
33+
// Given
34+
String positionString = "Position{x=-50, y=64, z=120, world='world_nether'}";
35+
Position expected = new Position(-50, 64, 120, "world_nether");
36+
37+
// When
38+
Result<Position, Exception> result = this.positionComposer.deserialize(positionString);
39+
40+
// Then
41+
assertTrue(result.isOk());
42+
assertEquals(expected, result.get());
43+
}
44+
45+
@Test
46+
void testDeserializeInvalidFormat() {
47+
// Given
48+
String invalidString = "world,-50,64,120";
49+
50+
// When
51+
Result<Position, Exception> result = this.positionComposer.deserialize(invalidString);
52+
53+
// Then
54+
assertTrue(result.isErr());
55+
assertInstanceOf(IllegalArgumentException.class, result.getError());
56+
}
57+
58+
@Test
59+
void testSerializeNull() {
60+
// When & Then
61+
assertThrows(NullPointerException.class, () -> this.positionComposer.serialize(null));
62+
}
63+
64+
@Test
65+
void testDeserializeNull() {
66+
// When & Then
67+
assertThrows(AttemptFailedException.class, () -> this.positionComposer.deserialize(null));
68+
}
69+
}

0 commit comments

Comments
 (0)