Skip to content

Commit

Permalink
Update tests to run with JUnit 5
Browse files Browse the repository at this point in the history
* Removed @RunWith(SpringRunner.class)
* Removed @RunWith(JUnit4.class)
* Replaced @test imports
* Replaced @before with @beforeeach
* Replaced @ignore with @disabled
* Made public @tests package private
* Made test classes package private
* Added @ExtendWith(SpringExtension.class) to custom test slices
* Replaced @RunWith(MockitoJUnitRunner.class) with @ExtendWith(MockitoExtension.class) - for MockitoJUnitRunner.Silent.class added @MockitoSettings(strictness = Strictness.LENIENT)
  • Loading branch information
drumonii committed Oct 22, 2019
1 parent 97ac7e2 commit e6180a2
Show file tree
Hide file tree
Showing 106 changed files with 653 additions and 845 deletions.
9 changes: 7 additions & 2 deletions backend/build.gradle
Expand Up @@ -17,6 +17,7 @@ ext {
}

test {
useJUnitPlatform()
dependsOn ':frontend:karmaTests'
outputs.dir snippetsDir
}
Expand Down Expand Up @@ -81,9 +82,13 @@ dependencies {
implementation 'org.apache.commons:commons-collections4:4.4'

// Testing
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation 'org.springframework.security:spring-security-test'
testImplementation 'org.springframework.batch:spring-batch-test'
testImplementation('org.springframework.batch:spring-batch-test') {
exclude group: 'junit', module: 'junit'
}
testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'
}

Expand Down
Expand Up @@ -2,20 +2,20 @@

import com.drumonii.loltrollbuild.model.Build;
import com.drumonii.loltrollbuild.test.json.JsonTestFilesUtil;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.springframework.test.context.ActiveProfiles;

import static com.drumonii.loltrollbuild.config.Profiles.DDRAGON;
import static com.drumonii.loltrollbuild.config.Profiles.TESTING;
import static com.drumonii.loltrollbuild.util.GameMapUtil.SUMMONERS_RIFT_SID;

@ActiveProfiles({ TESTING, DDRAGON })
@Ignore
public class BuildsDdragonRestControllerTest extends BuildsRestControllerTest {
@Disabled
class BuildsDdragonRestControllerTest extends BuildsRestControllerTest {

@Before
public void before() {
@BeforeEach
void beforeEach() {
JsonTestFilesUtil jsonTestFilesUtil = new JsonTestFilesUtil(objectMapper);

championsResponse = jsonTestFilesUtil.getFullChampionsResponse();
Expand Down
Expand Up @@ -8,13 +8,11 @@
import com.drumonii.loltrollbuild.riot.api.SummonerSpellsResponse;
import com.drumonii.loltrollbuild.test.rest.WebMvcRestTest;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;

import static com.drumonii.loltrollbuild.util.GameMapUtil.SUMMONERS_RIFT_SID;
Expand All @@ -25,10 +23,9 @@
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

@RunWith(SpringRunner.class)
@WebMvcRestTest(BuildsRestController.class)
@Ignore
public abstract class BuildsRestControllerTest {
@Disabled
abstract class BuildsRestControllerTest {

@Autowired
private MockMvc mockMvc;
Expand Down Expand Up @@ -59,10 +56,10 @@ public abstract class BuildsRestControllerTest {
protected MapsResponse mapsResponse;
protected SummonerSpellsResponse summonerSpellsResponse;

public abstract void before();
abstract void beforeEach();

@Test
public void getBuilds() throws Exception {
void getBuilds() throws Exception {
// qbe
mockMvc.perform(get("{apiPath}/builds", apiPath))
.andExpect(status().isOk())
Expand All @@ -80,7 +77,7 @@ public void getBuilds() throws Exception {
}

@Test
public void getBuild() throws Exception {
void getBuild() throws Exception {
// find with non existing build Id
mockMvc.perform(get("{apiPath}/builds/{id}", apiPath, 0))
.andExpect(status().isNotFound());
Expand Down Expand Up @@ -156,7 +153,7 @@ public void getBuild() throws Exception {
}

@Test
public void saveBuild() throws Exception {
void saveBuild() throws Exception {
Build build = new Build();

// Save with missing attributes
Expand Down Expand Up @@ -224,7 +221,7 @@ public void saveBuild() throws Exception {
}

@Test
public void countBuild() throws Exception {
void countBuild() throws Exception {
long count = buildsRepository.count();

mockMvc.perform(get("{apiPath}/builds/count", apiPath))
Expand Down
Expand Up @@ -3,17 +3,17 @@
import com.drumonii.loltrollbuild.riot.api.ItemsResponse;
import com.drumonii.loltrollbuild.riot.api.SummonerSpellsResponse;
import com.drumonii.loltrollbuild.test.json.JsonTestFilesUtil;
import org.junit.Before;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.test.context.ActiveProfiles;

import static com.drumonii.loltrollbuild.config.Profiles.DDRAGON;
import static com.drumonii.loltrollbuild.config.Profiles.TESTING;

@ActiveProfiles({ TESTING, DDRAGON })
public class ChampionsDdragonRestControllerTest extends ChampionsRestControllerTest {
class ChampionsDdragonRestControllerTest extends ChampionsRestControllerTest {

@Before
public void before() {
@BeforeEach
void beforeEach() {
JsonTestFilesUtil jsonTestFilesUtil = new JsonTestFilesUtil(objectMapper);

championsResponse = jsonTestFilesUtil.getFullChampionsResponse();
Expand Down
Expand Up @@ -8,12 +8,10 @@
import com.drumonii.loltrollbuild.test.rest.WebMvcRestTest;
import com.drumonii.loltrollbuild.util.RandomizeUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;

import static com.drumonii.loltrollbuild.util.GameMapUtil.HOWLING_ABYSS_ID;
Expand All @@ -22,9 +20,8 @@
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

@RunWith(SpringRunner.class)
@WebMvcRestTest(ChampionsRestController.class)
public abstract class ChampionsRestControllerTest {
abstract class ChampionsRestControllerTest {

@Autowired
private MockMvc mockMvc;
Expand All @@ -46,10 +43,10 @@ public abstract class ChampionsRestControllerTest {

protected ChampionsResponse championsResponse;

public abstract void before();
abstract void beforeEach();

@Test
public void getChampions() throws Exception {
void getChampions() throws Exception {
Champion champion = RandomizeUtil.getRandom(championsResponse.getChampions().values());

// qbe
Expand Down Expand Up @@ -95,7 +92,7 @@ public void getChampions() throws Exception {
}

@Test
public void getChampion() throws Exception {
void getChampion() throws Exception {
// find with non existing champion Id
mockMvc.perform(get("{apiPath}/champions/{id}", apiPath, 0))
.andExpect(status().isNotFound());
Expand All @@ -116,20 +113,20 @@ public void getChampion() throws Exception {
}

@Test
public void getTags() throws Exception {
void getTags() throws Exception {
mockMvc.perform(get("{apiPath}/champions/tags", apiPath))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON));
}

@Test
public void trollBuildWithChampionThatDoesNotExist() throws Exception {
void trollBuildWithChampionThatDoesNotExist() throws Exception {
mockMvc.perform(get("{apiPath}/champions/{id}/troll-build", apiPath, 0))
.andExpect(status().isNotFound());
}

@Test
public void trollBuild() throws Exception {
void trollBuild() throws Exception {
Champion azir = championsResponse.getChampions().get("Azir");

// get with champion Id and map specified
Expand Down Expand Up @@ -179,7 +176,7 @@ public void trollBuild() throws Exception {
}

@Test
public void trollBuildForViktor() throws Exception {
void trollBuildForViktor() throws Exception {
Champion viktor = championsResponse.getChampions().get("Viktor");

// get with Viktor Id and map specified
Expand Down Expand Up @@ -230,7 +227,7 @@ public void trollBuildForViktor() throws Exception {
}

@Test
public void trollBuildWithNoItems() throws Exception {
void trollBuildWithNoItems() throws Exception {
itemsRepository.deleteAll();
summonerSpellsRepository.deleteAll();

Expand Down
Expand Up @@ -2,7 +2,7 @@

import com.drumonii.loltrollbuild.test.rest.AbstractRestTests;
import org.hamcrest.Matcher;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.http.*;
import org.springframework.test.util.JsonPathExpectationsHelper;

Expand All @@ -12,10 +12,10 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.is;

public class ErrorRestControllerTest extends AbstractRestTests {
class ErrorRestControllerTest extends AbstractRestTests {

@Test
public void getsErrorForPermitAllRequest() {
void getsErrorForPermitAllRequest() {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
HttpEntity<String> httpEntity = new HttpEntity<>(headers);
Expand All @@ -27,7 +27,7 @@ public void getsErrorForPermitAllRequest() {
}

@Test
public void getsErrorForSecureRequest() {
void getsErrorForSecureRequest() {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
HttpEntity<String> httpEntity = new HttpEntity<>(headers);
Expand Down
@@ -1,17 +1,17 @@
package com.drumonii.loltrollbuild.api;

import com.drumonii.loltrollbuild.test.json.JsonTestFilesUtil;
import org.junit.Before;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.test.context.ActiveProfiles;

import static com.drumonii.loltrollbuild.config.Profiles.DDRAGON;
import static com.drumonii.loltrollbuild.config.Profiles.TESTING;

@ActiveProfiles({ TESTING, DDRAGON })
public class ImagesDdragonRestControllerTest extends ImagesRestControllerTest {
class ImagesDdragonRestControllerTest extends ImagesRestControllerTest {

@Before
public void before() {
@BeforeEach
void beforeEach() {
JsonTestFilesUtil jsonTestFilesUtil = new JsonTestFilesUtil(objectMapper);

championsResponse = jsonTestFilesUtil.getFullChampionsResponse();
Expand Down
Expand Up @@ -12,13 +12,11 @@
import com.drumonii.loltrollbuild.riot.service.ImageService;
import com.drumonii.loltrollbuild.test.rest.WebMvcRestTest;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.context.annotation.FilterType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;

import java.util.Optional;
Expand All @@ -30,10 +28,9 @@
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

@RunWith(SpringRunner.class)
@WebMvcRestTest(value = ImagesRestController.class,
includeFilters = @Filter(type = FilterType.ASSIGNABLE_TYPE, classes = { ImageService.class }))
public abstract class ImagesRestControllerTest {
abstract class ImagesRestControllerTest {

@Autowired
private MockMvc mockMvc;
Expand Down Expand Up @@ -61,10 +58,10 @@ public abstract class ImagesRestControllerTest {
protected MapsResponse mapsResponse;
protected SummonerSpellsResponse summonerSpellsResponse;

public abstract void before();
abstract void beforeEach();

@Test
public void summonerSpellImg() throws Exception {
void summonerSpellImg() throws Exception {
mockMvc.perform(get("{apiPath}/img/summoner-spells/{img}", apiPath, 0))
.andExpect(status().isNotFound());

Expand All @@ -80,7 +77,7 @@ public void summonerSpellImg() throws Exception {
}

@Test
public void itemImg() throws Exception {
void itemImg() throws Exception {
mockMvc.perform(get("{apiPath}/img/items/{img}", apiPath, 0))
.andExpect(status().isNotFound());

Expand All @@ -96,7 +93,7 @@ public void itemImg() throws Exception {
}

@Test
public void championImg() throws Exception {
void championImg() throws Exception {
mockMvc.perform(get("{apiPath}/img/champions/{img}", apiPath, 0))
.andExpect(status().isNotFound());

Expand All @@ -112,7 +109,7 @@ public void championImg() throws Exception {
}

@Test
public void championSpellImg() throws Exception {
void championSpellImg() throws Exception {
mockMvc.perform(get("{apiPath}/img/champions/{id}/spell/{img}", apiPath, 0, "key"))
.andExpect(status().isNotFound());

Expand All @@ -134,7 +131,7 @@ public void championSpellImg() throws Exception {
}

@Test
public void championPassiveImg() throws Exception {
void championPassiveImg() throws Exception {
mockMvc.perform(get("{apiPath}/img/champions/{id}/passive", apiPath, 0))
.andExpect(status().isNotFound());

Expand All @@ -150,7 +147,7 @@ public void championPassiveImg() throws Exception {
}

@Test
public void mapImg() throws Exception {
void mapImg() throws Exception {
mockMvc.perform(get("{apiPath}/img/maps/{mapId}", apiPath, 0))
.andExpect(status().isNotFound());

Expand Down
@@ -1,17 +1,17 @@
package com.drumonii.loltrollbuild.api;

import com.drumonii.loltrollbuild.test.json.JsonTestFilesUtil;
import org.junit.Before;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.test.context.ActiveProfiles;

import static com.drumonii.loltrollbuild.config.Profiles.DDRAGON;
import static com.drumonii.loltrollbuild.config.Profiles.TESTING;

@ActiveProfiles({ TESTING, DDRAGON })
public class ItemsDdragonRestControllerTest extends ItemsRestControllerTest {
class ItemsDdragonRestControllerTest extends ItemsRestControllerTest {

@Before
public void before() {
@BeforeEach
void beforeEach() {
JsonTestFilesUtil jsonTestFilesUtil = new JsonTestFilesUtil(objectMapper);

itemsResponse = jsonTestFilesUtil.getItemsResponse();
Expand Down

0 comments on commit e6180a2

Please sign in to comment.