Skip to content

456456 #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: PR build
on:
push:
branches:
- master
jobs:
build-backend:
runs-on: self-hosted
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'adopt'
- name: Cache Maven packages
uses: actions/cache@v1
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
# Step that runs the tests
- name: Run tests
run: |
chmod 777 mvnw
./mvnw test
Empty file modified mvnw
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.5</version>
<version>2.6.6</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* @author moises.macero
*/
@ExtendWith(MockitoExtension.class)
public class SuperHeroControllerMockMvcStandaloneTest {
class SuperHeroControllerMockMvcStandaloneTest {

private MockMvc mvc;

Expand All @@ -44,7 +44,7 @@ public class SuperHeroControllerMockMvcStandaloneTest {
private JacksonTester<SuperHero> jsonSuperHero;

@BeforeEach
public void setup() {
void setup() {
// We would need this line if we would not use the MockitoExtension
// MockitoAnnotations.initMocks(this);
// Here we can't use @AutoConfigureJsonTesters because there isn't a Spring context
Expand All @@ -57,7 +57,7 @@ public void setup() {
}

@Test
public void canRetrieveByIdWhenExists() throws Exception {
void canRetrieveByIdWhenExists() throws Exception {
// given
given(superHeroRepository.getSuperHero(2))
.willReturn(new SuperHero("Rob", "Mannon", "RobotMan"));
Expand All @@ -76,7 +76,7 @@ public void canRetrieveByIdWhenExists() throws Exception {
}

@Test
public void canRetrieveByIdWhenDoesNotExist() throws Exception {
void canRetrieveByIdWhenDoesNotExist() throws Exception {
// given
given(superHeroRepository.getSuperHero(2))
.willThrow(new NonExistingHeroException());
Expand All @@ -93,7 +93,7 @@ public void canRetrieveByIdWhenDoesNotExist() throws Exception {
}

@Test
public void canRetrieveByNameWhenExists() throws Exception {
void canRetrieveByNameWhenExists() throws Exception {
// given
given(superHeroRepository.getSuperHero("RobotMan"))
.willReturn(Optional.of(new SuperHero("Rob", "Mannon", "RobotMan")));
Expand All @@ -112,7 +112,7 @@ public void canRetrieveByNameWhenExists() throws Exception {
}

@Test
public void canRetrieveByNameWhenDoesNotExist() throws Exception {
void canRetrieveByNameWhenDoesNotExist() throws Exception {
// given
given(superHeroRepository.getSuperHero("RobotMan"))
.willReturn(Optional.empty());
Expand All @@ -129,7 +129,7 @@ public void canRetrieveByNameWhenDoesNotExist() throws Exception {
}

@Test
public void canCreateANewSuperHero() throws Exception {
void canCreateANewSuperHero() throws Exception {
// when
MockHttpServletResponse response = mvc.perform(
post("/superheroes/").contentType(MediaType.APPLICATION_JSON).content(
Expand All @@ -141,7 +141,7 @@ public void canCreateANewSuperHero() throws Exception {
}

@Test
public void headerIsPresent() throws Exception {
void headerIsPresent() throws Exception {
// when
MockHttpServletResponse response = mvc.perform(
get("/superheroes/2")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/
@AutoConfigureJsonTesters
@WebMvcTest(SuperHeroController.class)
public class SuperHeroControllerMockMvcWithContextTest {
class SuperHeroControllerMockMvcWithContextTest {

@Autowired
private MockMvc mvc;
Expand All @@ -41,7 +41,7 @@ public class SuperHeroControllerMockMvcWithContextTest {
private JacksonTester<SuperHero> jsonSuperHero;

@Test
public void canRetrieveByIdWhenExists() throws Exception {
void canRetrieveByIdWhenExists() throws Exception {
// given
given(superHeroRepository.getSuperHero(2))
.willReturn(new SuperHero("Rob", "Mannon", "RobotMan"));
Expand All @@ -60,7 +60,7 @@ public void canRetrieveByIdWhenExists() throws Exception {
}

@Test
public void canRetrieveByIdWhenDoesNotExist() throws Exception {
void canRetrieveByIdWhenDoesNotExist() throws Exception {
// given
given(superHeroRepository.getSuperHero(2))
.willThrow(new NonExistingHeroException());
Expand All @@ -77,7 +77,7 @@ public void canRetrieveByIdWhenDoesNotExist() throws Exception {
}

@Test
public void canRetrieveByNameWhenExists() throws Exception {
void canRetrieveByNameWhenExists() throws Exception {
// given
given(superHeroRepository.getSuperHero("RobotMan"))
.willReturn(Optional.of(new SuperHero("Rob", "Mannon", "RobotMan")));
Expand All @@ -96,7 +96,7 @@ public void canRetrieveByNameWhenExists() throws Exception {
}

@Test
public void canRetrieveByNameWhenDoesNotExist() throws Exception {
void canRetrieveByNameWhenDoesNotExist() throws Exception {
// given
given(superHeroRepository.getSuperHero("RobotMan"))
.willReturn(Optional.empty());
Expand All @@ -113,7 +113,7 @@ public void canRetrieveByNameWhenDoesNotExist() throws Exception {
}

@Test
public void canCreateANewSuperHero() throws Exception {
void canCreateANewSuperHero() throws Exception {
// when
MockHttpServletResponse response = mvc.perform(
post("/superheroes/").contentType(MediaType.APPLICATION_JSON).content(
Expand All @@ -125,7 +125,7 @@ public void canCreateANewSuperHero() throws Exception {
}

@Test
public void headerIsPresent() throws Exception {
void headerIsPresent() throws Exception {
// when
MockHttpServletResponse response = mvc.perform(
get("/superheroes/2")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
@AutoConfigureJsonTesters
@SpringBootTest
@AutoConfigureMockMvc
public class SuperHeroControllerSpringBootMockTest {
class SuperHeroControllerSpringBootMockTest {

@Autowired
private MockMvc mvc;
Expand All @@ -44,7 +44,7 @@ public class SuperHeroControllerSpringBootMockTest {
private JacksonTester<SuperHero> jsonSuperHero;

@Test
public void canRetrieveByIdWhenExists() throws Exception {
void canRetrieveByIdWhenExists() throws Exception {
// given
given(superHeroRepository.getSuperHero(2))
.willReturn(new SuperHero("Rob", "Mannon", "RobotMan"));
Expand All @@ -63,7 +63,7 @@ public void canRetrieveByIdWhenExists() throws Exception {
}

@Test
public void canRetrieveByIdWhenDoesNotExist() throws Exception {
void canRetrieveByIdWhenDoesNotExist() throws Exception {
// given
given(superHeroRepository.getSuperHero(2))
.willThrow(new NonExistingHeroException());
Expand All @@ -80,7 +80,7 @@ public void canRetrieveByIdWhenDoesNotExist() throws Exception {
}

@Test
public void canRetrieveByNameWhenExists() throws Exception {
void canRetrieveByNameWhenExists() throws Exception {
// given
given(superHeroRepository.getSuperHero("RobotMan"))
.willReturn(Optional.of(new SuperHero("Rob", "Mannon", "RobotMan")));
Expand All @@ -99,7 +99,7 @@ public void canRetrieveByNameWhenExists() throws Exception {
}

@Test
public void canRetrieveByNameWhenDoesNotExist() throws Exception {
void canRetrieveByNameWhenDoesNotExist() throws Exception {
// given
given(superHeroRepository.getSuperHero("RobotMan"))
.willReturn(Optional.empty());
Expand All @@ -116,7 +116,7 @@ public void canRetrieveByNameWhenDoesNotExist() throws Exception {
}

@Test
public void canCreateANewSuperHero() throws Exception {
void canCreateANewSuperHero() throws Exception {
// when
MockHttpServletResponse response = mvc.perform(
post("/superheroes/").contentType(MediaType.APPLICATION_JSON).content(
Expand All @@ -128,7 +128,7 @@ public void canCreateANewSuperHero() throws Exception {
}

@Test
public void headerIsPresent() throws Exception {
void headerIsPresent() throws Exception {
// when
MockHttpServletResponse response = mvc.perform(
get("/superheroes/2")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

import java.util.Objects;
import java.util.Optional;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -24,7 +25,7 @@
* @author moises.macero
*/
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class SuperHeroControllerSpringBootTest {
class SuperHeroControllerSpringBootTest {

@MockBean
private SuperHeroRepository superHeroRepository;
Expand All @@ -33,7 +34,7 @@ public class SuperHeroControllerSpringBootTest {
private TestRestTemplate restTemplate;

@Test
public void canRetrieveByIdWhenExists() {
void canRetrieveByIdWhenExists() {
// given
given(superHeroRepository.getSuperHero(2))
.willReturn(new SuperHero("Rob", "Mannon", "RobotMan"));
Expand All @@ -43,11 +44,11 @@ public void canRetrieveByIdWhenExists() {

// then
assertThat(superHeroResponse.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(superHeroResponse.getBody().equals(new SuperHero("Rob", "Mannon", "RobotMan")));
assertThat(Objects.equals(superHeroResponse.getBody(), new SuperHero("Rob", "Mannon", "RobotMan")));
}

@Test
public void canRetrieveByIdWhenDoesNotExist() {
void canRetrieveByIdWhenDoesNotExist() {
// given
given(superHeroRepository.getSuperHero(2))
.willThrow(new NonExistingHeroException());
Expand All @@ -61,7 +62,7 @@ public void canRetrieveByIdWhenDoesNotExist() {
}

@Test
public void canRetrieveByNameWhenExists() {
void canRetrieveByNameWhenExists() {
// given
given(superHeroRepository.getSuperHero("RobotMan"))
.willReturn(Optional.of(new SuperHero("Rob", "Mannon", "RobotMan")));
Expand All @@ -72,11 +73,11 @@ public void canRetrieveByNameWhenExists() {

// then
assertThat(superHeroResponse.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(superHeroResponse.getBody().equals(new SuperHero("Rob", "Mannon", "RobotMan")));
assertThat(Objects.equals(superHeroResponse.getBody(), new SuperHero("Rob", "Mannon", "RobotMan")));
}

@Test
public void canRetrieveByNameWhenDoesNotExist() {
void canRetrieveByNameWhenDoesNotExist() {
// given
given(superHeroRepository.getSuperHero("RobotMan"))
.willReturn(Optional.empty());
Expand All @@ -91,7 +92,7 @@ public void canRetrieveByNameWhenDoesNotExist() {
}

@Test
public void canCreateANewSuperHero() {
void canCreateANewSuperHero() {
// when
ResponseEntity<SuperHero> superHeroResponse = restTemplate.postForEntity("/superheroes/",
new SuperHero("Rob", "Mannon", "RobotMan"), SuperHero.class);
Expand All @@ -101,7 +102,7 @@ public void canCreateANewSuperHero() {
}

@Test
public void headerIsPresent() throws Exception {
void headerIsPresent() throws Exception {
// when
ResponseEntity<SuperHero> superHeroResponse = restTemplate.getForEntity("/superheroes/2", SuperHero.class);

Expand Down
4 changes: 4 additions & 0 deletions src/test/resources/junit-platform.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
junit.jupiter.execution.parallel.enabled = true
junit.jupiter.execution.parallel.mode.default = concurrent
junit.jupiter.execution.parallel.mode.classes.default = concurrent
junit.jupiter.execution.parallel.config.fixed.parallelism = 5