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 22
33import java .io .ByteArrayOutputStream ;
44import java .io .IOException ;
5+ import java .nio .Buffer ;
56import java .nio .ByteBuffer ;
67import java .nio .file .Files ;
78import java .nio .file .Paths ;
@@ -14,10 +15,12 @@ public static Game createGame() throws IOException {
1415 }
1516
1617 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+ }
1821
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 ));
2124 final ByteArrayOutputStream out = new ByteArrayOutputStream ();
2225 final InflaterOutputStream zin = new InflaterOutputStream (out );
2326 zin .write (compressedBytes );
@@ -26,8 +29,10 @@ public static Game createGame(String mapName) throws IOException {
2629 final byte [] bytes = out .toByteArray ();
2730 final ByteBuffer buffer = ByteBuffer .allocateDirect (bytes .length );
2831 buffer .put (bytes );
32+ return buffer ;
33+ }
2934
30- final Client client = new Client ( buffer );
35+ public static Game createGame ( Client client ) throws IOException {
3136 final Game game = new Game (client );
3237 game .init ();
3338 return game ;
Original file line number Diff line number Diff line change 44import static org .mockito .BDDMockito .given ;
55import static org .mockito .Mockito .mock ;
66
7+ import java .io .IOException ;
8+ import java .nio .ByteBuffer ;
79import java .util .ArrayList ;
810import java .util .List ;
911import org .junit .Before ;
12+ import org .junit .Test ;
1013import org .junit .experimental .theories .DataPoints ;
1114import org .junit .experimental .theories .FromDataPoints ;
1215import org .junit .experimental .theories .Theories ;
@@ -82,4 +85,21 @@ public void shouldNotFindNonOverlappingUnits(
8285 // THEN
8386 assertThat (unitsInRectangle ).doesNotContain (dummy );
8487 }
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+ }
85105}
You can’t perform that action at this time.
0 commit comments