Archived
0

JUnit4 -> JUnit5

This commit is contained in:
2018-10-07 21:31:00 +03:00
parent 7a8a3e6ad4
commit 7225efced9
13 changed files with 175 additions and 161 deletions

View File

@@ -1,15 +1,15 @@
package mc.core.h2db;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.UUID;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
public class TestH2Player {
class TestH2Player {
@Test
public void testEquals() {
void testEquals() {
UUID uuid = UUID.randomUUID();
H2Player player1 = new H2Player();

View File

@@ -4,21 +4,21 @@ import mc.core.EntityLocation;
import mc.core.h2db.service.H2PlayerService;
import mc.core.player.Player;
import mc.core.world.World;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import java.util.List;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
@RunWith(SpringJUnit4ClassRunner.class)
@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = {TestSpringConfig.class})
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
public class TestH2PlayerManager {
class TestH2PlayerManager {
@Autowired
private H2PlayerService h2PlayerService;
@Autowired
@@ -27,7 +27,7 @@ public class TestH2PlayerManager {
private H2PlayerManager playerManager;
@Test
public void testCreatePlayer() {
void testCreatePlayer() {
final String playerName = "NEW_PLAYER";
final Player newPlayer = playerManager.createPlayer(playerName, EntityLocation.ZERO(), mockWorld);
@@ -45,7 +45,7 @@ public class TestH2PlayerManager {
}
@Test
public void testJoinServer() {
void testJoinServer() {
assertEquals(0, playerManager.getCountPlayers());
final String playerName = "NEW_PLAYER";
@@ -57,7 +57,7 @@ public class TestH2PlayerManager {
}
@Test
public void testLeftServer() {
void testLeftServer() {
assertEquals(0, playerManager.getCountPlayers());
final String playerName = "NEW_PLAYER";
@@ -87,7 +87,7 @@ public class TestH2PlayerManager {
}
@Test
public void testGetPlayer() {
void testGetPlayer() {
assertEquals(0, playerManager.getCountPlayers());
final String playerName = "NEW_PLAYER";
@@ -104,7 +104,7 @@ public class TestH2PlayerManager {
}
@Test
public void testGetPlayers() {
void testGetPlayers() {
assertEquals(0, playerManager.getCountPlayers());
final String playerName = "NEW_PLAYER";
@@ -128,7 +128,7 @@ public class TestH2PlayerManager {
}
@Test
public void testGetCountPlayers() {
void testGetCountPlayers() {
assertEquals(0, playerManager.getCountPlayers());
final String playerName = "NEW_PLAYER";
@@ -145,7 +145,7 @@ public class TestH2PlayerManager {
}
@Test
public void testGetOfflinePlayer() {
void testGetOfflinePlayer() {
final String playerName = "NEW_PLAYER";
final Player player = playerManager.createPlayer(playerName, EntityLocation.ZERO(), mockWorld);
playerManager.joinServer(player);

View File

@@ -3,21 +3,22 @@ package mc.core.h2db.service;
import mc.core.EntityLocation;
import mc.core.h2db.H2Player;
import mc.core.h2db.TestSpringConfig;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;
@RunWith(SpringJUnit4ClassRunner.class)
import static org.junit.jupiter.api.Assertions.*;
@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = {TestSpringConfig.class})
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
public class H2PlayerServiceTest {
class H2PlayerServiceTest {
@Autowired
private H2PlayerService h2PlayerService;
@@ -43,91 +44,101 @@ public class H2PlayerServiceTest {
}
@Test
public void save() {
void save() {
H2Player player = buildPlayer();
H2Player savedPlayer = h2PlayerService.save(player);
player.setId(savedPlayer.getId()); //FIXME костыль, однако
Assert.assertEquals(player, savedPlayer);
}
@Test(expected = Exception.class)
public void save_NameEmpty() {
H2Player player = buildPlayer();
player.setName("");
h2PlayerService.save(player);
}
@Test(expected = Exception.class)
public void save_NameNull() {
H2Player player = buildPlayer();
player.setName(null);
h2PlayerService.save(player);
}
@Test(expected = Exception.class)
public void save_UuidNull() {
H2Player player = buildPlayer();
player.setUuid(null);
h2PlayerService.save(player);
}
@Test(expected = Exception.class)
public void save_LocationNull() {
H2Player player = buildPlayer();
player.setLocation(null);
h2PlayerService.save(player);
assertEquals(player, savedPlayer);
}
@Test
public void remove() {
void save_NameEmpty() {
assertThrows(Exception.class, () -> {
H2Player player = buildPlayer();
player.setName("");
h2PlayerService.save(player);
});
}
@Test
void save_NameNull() {
assertThrows(Exception.class, () -> {
H2Player player = buildPlayer();
player.setName(null);
h2PlayerService.save(player);
});
}
@Test
void save_UuidNull() {
assertThrows(Exception.class, () -> {
H2Player player = buildPlayer();
player.setUuid(null);
h2PlayerService.save(player);
});
}
@Test
void save_LocationNull() {
assertThrows(Exception.class, () -> {
H2Player player = buildPlayer();
player.setLocation(null);
h2PlayerService.save(player);
});
}
@Test
void remove() {
H2Player player = h2PlayerService.save(buildPlayer());
h2PlayerService.remove(player);
H2Player player2 = h2PlayerService.getById(player.getId());
Assert.assertNull(player2);
}
@Test(expected = Exception.class)
public void remove_NotExists() {
H2Player player = h2PlayerService.save(buildPlayer());
h2PlayerService.remove(player);
h2PlayerService.remove(player);
assertNull(player2);
}
@Test
public void getByName() {
void remove_NotExists() {
assertThrows(Exception.class, () -> {
H2Player player = h2PlayerService.save(buildPlayer());
h2PlayerService.remove(player);
h2PlayerService.remove(player);
});
}
@Test
void getByName() {
H2Player player = h2PlayerService.save(buildPlayer());
H2Player player2 = h2PlayerService.getByName(player.getName());
Assert.assertEquals(player, player2);
assertEquals(player, player2);
}
@Test
public void getByName_NotExists() {
Assert.assertNull(h2PlayerService.getByName("UNKNOW_PLAYER"));
void getByName_NotExists() {
assertNull(h2PlayerService.getByName("UNKNOW_PLAYER"));
}
@Test
public void getByName_Empty() {
Assert.assertNull(h2PlayerService.getByName(""));
void getByName_Empty() {
assertNull(h2PlayerService.getByName(""));
}
@Test
public void getByName_Null() {
Assert.assertNull(h2PlayerService.getByName(null));
void getByName_Null() {
assertNull(h2PlayerService.getByName(null));
}
@Test
public void getById() {
void getById() {
H2Player player = h2PlayerService.save(buildPlayer());
H2Player player2 = h2PlayerService.getById(player.getId());
Assert.assertEquals(player, player2);
assertEquals(player, player2);
}
@Test
public void getById_NotExists() {
Assert.assertNull(h2PlayerService.getById(9999));
void getById_NotExists() {
assertNull(h2PlayerService.getById(9999));
}
}