Skip to content

Commit ca40eaa

Browse files
committed
Refactored tests.
1 parent 611866f commit ca40eaa

File tree

3 files changed

+35
-38
lines changed

3 files changed

+35
-38
lines changed

src/test/java/project_16x16/OptionsTest.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66

77
import org.junit.jupiter.api.Test;
88

9-
import project_16x16.Options;
10-
11-
public class OptionsTest {
9+
class OptionsTest {
1210

1311
@Test
14-
public void callingSaveWithIntShouldUpdateOptions() {
12+
void callingSaveWithIntShouldUpdateOptions() {
1513
int expected = 5;
1614
Preferences options = Preferences.userNodeForPackage(Options.class);
1715

@@ -21,7 +19,7 @@ public void callingSaveWithIntShouldUpdateOptions() {
2119
}
2220

2321
@Test
24-
public void callingSaveWithFloatShouldUpdateOptions() {
22+
void callingSaveWithFloatShouldUpdateOptions() {
2523
float expected = 5.5f;
2624
Preferences options = Preferences.userNodeForPackage(Options.class);
2725

@@ -31,7 +29,7 @@ public void callingSaveWithFloatShouldUpdateOptions() {
3129
}
3230

3331
@Test
34-
public void callingSaveWithBooleanShouldUpdateOptions() {
32+
void callingSaveWithBooleanShouldUpdateOptions() {
3533
Preferences options = Preferences.userNodeForPackage(Options.class);
3634

3735
Options.save(Options.Option.testKey, true);

src/test/java/project_16x16/components/TileTest.java

+13-13
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import processing.core.PVector;
1212
import project_16x16.Tileset;
1313

14-
public class TileTest {
14+
class TileTest {
1515

1616
private Tile tile;
1717
private PImage image;
@@ -23,33 +23,33 @@ void setup() {
2323
}
2424

2525
@Test
26-
void constructorTest() {
26+
void callingConstructor_shouldNotFail() {
2727
assertNotNull(tile);
2828
}
2929

3030
@Test
31-
void getIDTest() {
32-
assertEquals(tile.getId(), 1);
31+
void callingGetId_shouldReturnExpected() {
32+
assertEquals(1, tile.getId());
3333
}
3434

3535
@Test
36-
void getNameTest() {
37-
assertEquals(tile.getName(), "tile");
36+
void callingGetName_shouldReturnExpected() {
37+
assertEquals("tile", tile.getName());
3838
}
3939

4040
@Test
41-
void getPImageTest() {
42-
assertEquals(tile.getPImage(), image);
41+
void callingGetPImage_shouldReturnExpected() {
42+
assertEquals(image, tile.getPImage());
4343
}
4444

4545
@Test
46-
void getTileTypeTest() {
47-
assertEquals(tile.getTileType(), Tile.TileType.BACKGROUND);
46+
void callingGetTileType_shouldReturnExpected() {
47+
assertEquals(Tile.TileType.BACKGROUND, tile.getTileType());
4848
}
4949

5050
@Test
51-
void getPositionTest() {
52-
PVector vector = new PVector(Tileset.TILESETWIDTH, 0); // as ID = 1
53-
assertEquals(tile.getPosition(), vector);
51+
void callingGetPosition_shouldReturnExpected() {
52+
PVector vector = new PVector(Tileset.TILESETWIDTH, 0);
53+
assertEquals(vector, tile.getPosition());
5454
}
5555
}

src/test/java/project_16x16/multiplayer/MultiplayerTest.java

+18-19
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,18 @@
2222
import processing.net.Client;
2323
import processing.net.Server;
2424
import project_16x16.SideScroller;
25-
import project_16x16.multiplayer.Multiplayer;
2625

2726
@ExtendWith(MockitoExtension.class)
28-
public class MultiplayerTest {
27+
class MultiplayerTest {
2928

3029
@Mock
3130
private SideScroller player;
3231

3332
@Test
34-
public void callingConstructorAsServer_ok() {
33+
void callingConstructorAsServer_ok() {
3534
ConnectException ce = null;
3635
try {
37-
Multiplayer multiplayer = new Multiplayer(player, false);
36+
new Multiplayer(player, false);
3837
}
3938
catch (ConnectException e) {
4039
ce = e;
@@ -44,10 +43,10 @@ public void callingConstructorAsServer_ok() {
4443
}
4544

4645
@Test
47-
public void callingConstructorAsClient_ok() {
46+
void callingConstructorAsClient_ok() {
4847
ConnectException ce = null;
4948
try {
50-
Multiplayer multiplayer = new Multiplayer(player, true);
49+
new Multiplayer(player, true);
5150
}
5251
catch (ConnectException e) {
5352
ce = e;
@@ -57,13 +56,13 @@ public void callingConstructorAsClient_ok() {
5756
}
5857

5958
@Test
60-
public void callingConstructorAsServer_raisesException() {
59+
void callingConstructorAsServer_raisesException() {
6160
ConnectException ce = null;
6261
try (MockedConstruction<Server> mocked = mockConstruction(Server.class, (mock, context) -> {
6362
when(mock.active()).thenReturn(false);
6463
})) {
6564
try {
66-
Multiplayer multiplayer = new Multiplayer(player, true);
65+
new Multiplayer(player, true);
6766
}
6867
catch (ConnectException e) {
6968
ce = e;
@@ -74,13 +73,13 @@ public void callingConstructorAsServer_raisesException() {
7473
}
7574

7675
@Test
77-
public void callingConstructorAsClient_raisesException() {
76+
void callingConstructorAsClient_raisesException() {
7877
ConnectException ce = null;
7978
try (MockedConstruction<Client> mocked = mockConstruction(Client.class, (mock, context) -> {
8079
when(mock.active()).thenReturn(false);
8180
})) {
8281
try {
83-
Multiplayer multiplayer = new Multiplayer(player, false);
82+
new Multiplayer(player, false);
8483
}
8584
catch (ConnectException e) {
8685
ce = e;
@@ -91,7 +90,7 @@ public void callingConstructorAsClient_raisesException() {
9190
}
9291

9392
@Test
94-
public void callingReadDataAsServerWithNoClient_returnsNullData() {
93+
void callingReadDataAsServerWithNoClient_returnsNullData() {
9594
ConnectException ce = null;
9695
JSONObject data = null;
9796
try (MockedConstruction<Server> mocked = mockConstruction(Server.class, (mock, context) -> {
@@ -112,7 +111,7 @@ public void callingReadDataAsServerWithNoClient_returnsNullData() {
112111
}
113112

114113
@Test
115-
public void callingReadDataAsServerWithClient_returnsData() {
114+
void callingReadDataAsServerWithClient_returnsData() {
116115
ConnectException ce = null;
117116
JSONObject data = null;
118117

@@ -138,7 +137,7 @@ public void callingReadDataAsServerWithClient_returnsData() {
138137
}
139138

140139
@Test
141-
public void callingReadDataAsClientWithNoAvailableData_returnsNullData() {
140+
void callingReadDataAsClientWithNoAvailableData_returnsNullData() {
142141
ConnectException ce = null;
143142
JSONObject data = null;
144143
try (MockedConstruction<Client> client = mockConstruction(Client.class, (mock, context) -> {
@@ -159,7 +158,7 @@ public void callingReadDataAsClientWithNoAvailableData_returnsNullData() {
159158
}
160159

161160
@Test
162-
public void callingReadDataAsClient_returnsData() {
161+
void callingReadDataAsClient_returnsData() {
163162
ConnectException ce = null;
164163
JSONObject data = null;
165164
try (MockedConstruction<Client> client = mockConstruction(Client.class, (mock, context) -> {
@@ -182,7 +181,7 @@ public void callingReadDataAsClient_returnsData() {
182181
}
183182

184183
@Test
185-
public void callingWriteDataAsServer() {
184+
void callingWriteDataAsServer() {
186185
ConnectException ce = null;
187186
try (MockedConstruction<Server> mocked = mockConstruction(Server.class, (mock, context) -> {
188187
when(mock.active()).thenReturn(true);
@@ -203,7 +202,7 @@ public void callingWriteDataAsServer() {
203202
}
204203

205204
@Test
206-
public void callingWriteDataAsClient() {
205+
void callingWriteDataAsClient() {
207206
ConnectException ce = null;
208207
try (MockedConstruction<Client> mocked = mockConstruction(Client.class, (mock, context) -> {
209208
when(mock.active()).thenReturn(true);
@@ -224,7 +223,7 @@ public void callingWriteDataAsClient() {
224223
}
225224

226225
@Test
227-
public void callingWriteDataAsClientNotActive_doNotWrites() {
226+
void callingWriteDataAsClientNotActive_doNotWrites() {
228227
ConnectException ce = null;
229228
try (MockedConstruction<Client> mocked = mockConstruction(Client.class, (mock, context) -> {
230229
when(mock.active()).thenReturn(true);
@@ -246,7 +245,7 @@ public void callingWriteDataAsClientNotActive_doNotWrites() {
246245
}
247246

248247
@Test
249-
public void callingExitAsServer() {
248+
void callingExitAsServer() {
250249
ConnectException ce = null;
251250
try (MockedConstruction<Server> mocked = mockConstruction(Server.class, (mock, context) -> {
252251
when(mock.active()).thenReturn(true);
@@ -267,7 +266,7 @@ public void callingExitAsServer() {
267266
}
268267

269268
@Test
270-
public void callingExitAsClient() {
269+
void callingExitAsClient() {
271270
ConnectException ce = null;
272271
try (MockedConstruction<Client> mocked = mockConstruction(Client.class, (mock, context) -> {
273272
when(mock.active()).thenReturn(true);

0 commit comments

Comments
 (0)