File tree Expand file tree Collapse file tree 2 files changed +29
-4
lines changed Expand file tree Collapse file tree 2 files changed +29
-4
lines changed Original file line number Diff line number Diff line change 2
2
3
3
import java .io .ByteArrayOutputStream ;
4
4
import java .io .IOException ;
5
+ import java .nio .Buffer ;
5
6
import java .nio .ByteBuffer ;
6
7
import java .nio .file .Files ;
7
8
import java .nio .file .Paths ;
@@ -14,10 +15,12 @@ public static Game createGame() throws IOException {
14
15
}
15
16
16
17
public static Game createGame (String mapName ) throws IOException {
17
- final String location = "src/test/resources/" + mapName + "_frame0_buffer.bin" ;
18
+ final ByteBuffer buffer = binToBuffer ("src/test/resources/" + mapName + "_frame0_buffer.bin" );
19
+ return createGame (new Client (buffer ));
20
+ }
18
21
19
- // load bytebuffer
20
- final byte [] compressedBytes = Files .readAllBytes (Paths .get (location ));
22
+ public static ByteBuffer binToBuffer ( String binLocation ) throws IOException {
23
+ final byte [] compressedBytes = Files .readAllBytes (Paths .get (binLocation ));
21
24
final ByteArrayOutputStream out = new ByteArrayOutputStream ();
22
25
final InflaterOutputStream zin = new InflaterOutputStream (out );
23
26
zin .write (compressedBytes );
@@ -26,8 +29,10 @@ public static Game createGame(String mapName) throws IOException {
26
29
final byte [] bytes = out .toByteArray ();
27
30
final ByteBuffer buffer = ByteBuffer .allocateDirect (bytes .length );
28
31
buffer .put (bytes );
32
+ return buffer ;
33
+ }
29
34
30
- final Client client = new Client ( buffer );
35
+ public static Game createGame ( Client client ) throws IOException {
31
36
final Game game = new Game (client );
32
37
game .init ();
33
38
return game ;
Original file line number Diff line number Diff line change 4
4
import static org .mockito .BDDMockito .given ;
5
5
import static org .mockito .Mockito .mock ;
6
6
7
+ import java .io .IOException ;
8
+ import java .nio .ByteBuffer ;
7
9
import java .util .ArrayList ;
8
10
import java .util .List ;
9
11
import org .junit .Before ;
12
+ import org .junit .Test ;
10
13
import org .junit .experimental .theories .DataPoints ;
11
14
import org .junit .experimental .theories .FromDataPoints ;
12
15
import org .junit .experimental .theories .Theories ;
@@ -82,4 +85,21 @@ public void shouldNotFindNonOverlappingUnits(
82
85
// THEN
83
86
assertThat (unitsInRectangle ).doesNotContain (dummy );
84
87
}
88
+
89
+ @ Test
90
+ public void ifReplaySelfAndEnemyShouldBeNull () throws IOException {
91
+ ByteBuffer buffer = GameBuilder .binToBuffer ("src/test/resources/" + "(2)Benzene.scx" + "_frame0_buffer.bin" );
92
+
93
+ Client client = new Client (buffer );
94
+ // modify the buffer to fake a replay
95
+ client .gameData ().setIsReplay (true );
96
+
97
+ Game game = GameBuilder .createGame (client );
98
+
99
+ assertThat (game .isReplay ());
100
+ assertThat (game .self () == null );
101
+ assertThat (game .enemy () == null );
102
+ assertThat (game .enemies ().isEmpty ());
103
+ assertThat (game .allies ().isEmpty ());
104
+ }
85
105
}
You can’t perform that action at this time.
0 commit comments