diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml new file mode 100644 index 0000000..265de9d --- /dev/null +++ b/.github/workflows/verify.yml @@ -0,0 +1,22 @@ +name: Verify + +on: + pull_request: + branches: + - master + +jobs: + compile: + runs-on: ubuntu-latest + strategy: + matrix: + java: [17] + name: Java ${{ matrix.java }} compile and run tests + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-java@v3 + with: + java-version: ${{ matrix.java }} + distribution: 'adopt-hotspot' + - name: Compile with Java ${{ matrix.java }} + run: mvn test --no-transfer-progress diff --git a/pom.xml b/pom.xml index 8f994ed..139e36c 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ org.springframework.boot spring-boot-starter-parent - 2.5.5 + 2.7.0 diff --git a/src/test/java/io/tpd/superheroes/controller/SuperHeroControllerMockMvcStandaloneTest.java b/src/test/java/io/tpd/superheroes/controller/SuperHeroControllerMockMvcStandaloneTest.java index af52c26..423ff06 100644 --- a/src/test/java/io/tpd/superheroes/controller/SuperHeroControllerMockMvcStandaloneTest.java +++ b/src/test/java/io/tpd/superheroes/controller/SuperHeroControllerMockMvcStandaloneTest.java @@ -44,7 +44,7 @@ public class SuperHeroControllerMockMvcStandaloneTest { private JacksonTester 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 @@ -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")); @@ -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()); @@ -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"))); @@ -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()); @@ -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( @@ -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") diff --git a/src/test/java/io/tpd/superheroes/controller/SuperHeroControllerMockMvcWithContextTest.java b/src/test/java/io/tpd/superheroes/controller/SuperHeroControllerMockMvcWithContextTest.java index a840735..60f4218 100644 --- a/src/test/java/io/tpd/superheroes/controller/SuperHeroControllerMockMvcWithContextTest.java +++ b/src/test/java/io/tpd/superheroes/controller/SuperHeroControllerMockMvcWithContextTest.java @@ -41,7 +41,7 @@ public class SuperHeroControllerMockMvcWithContextTest { private JacksonTester jsonSuperHero; @Test - public void canRetrieveByIdWhenExists() throws Exception { + void canRetrieveByIdWhenExists() throws Exception { // given given(superHeroRepository.getSuperHero(2)) .willReturn(new SuperHero("Rob", "Mannon", "RobotMan")); @@ -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()); @@ -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"))); @@ -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()); @@ -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( @@ -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") diff --git a/src/test/java/io/tpd/superheroes/controller/SuperHeroControllerSpringBootMockTest.java b/src/test/java/io/tpd/superheroes/controller/SuperHeroControllerSpringBootMockTest.java index 1270e75..334e8b0 100644 --- a/src/test/java/io/tpd/superheroes/controller/SuperHeroControllerSpringBootMockTest.java +++ b/src/test/java/io/tpd/superheroes/controller/SuperHeroControllerSpringBootMockTest.java @@ -44,7 +44,7 @@ public class SuperHeroControllerSpringBootMockTest { private JacksonTester jsonSuperHero; @Test - public void canRetrieveByIdWhenExists() throws Exception { + void canRetrieveByIdWhenExists() throws Exception { // given given(superHeroRepository.getSuperHero(2)) .willReturn(new SuperHero("Rob", "Mannon", "RobotMan")); @@ -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()); @@ -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"))); @@ -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()); @@ -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( @@ -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") diff --git a/src/test/java/io/tpd/superheroes/controller/SuperHeroControllerSpringBootTest.java b/src/test/java/io/tpd/superheroes/controller/SuperHeroControllerSpringBootTest.java index be3b86d..f7fe4eb 100644 --- a/src/test/java/io/tpd/superheroes/controller/SuperHeroControllerSpringBootTest.java +++ b/src/test/java/io/tpd/superheroes/controller/SuperHeroControllerSpringBootTest.java @@ -33,7 +33,7 @@ public class SuperHeroControllerSpringBootTest { private TestRestTemplate restTemplate; @Test - public void canRetrieveByIdWhenExists() { + void canRetrieveByIdWhenExists() { // given given(superHeroRepository.getSuperHero(2)) .willReturn(new SuperHero("Rob", "Mannon", "RobotMan")); @@ -47,7 +47,7 @@ public void canRetrieveByIdWhenExists() { } @Test - public void canRetrieveByIdWhenDoesNotExist() { + void canRetrieveByIdWhenDoesNotExist() { // given given(superHeroRepository.getSuperHero(2)) .willThrow(new NonExistingHeroException()); @@ -61,7 +61,7 @@ public void canRetrieveByIdWhenDoesNotExist() { } @Test - public void canRetrieveByNameWhenExists() { + void canRetrieveByNameWhenExists() { // given given(superHeroRepository.getSuperHero("RobotMan")) .willReturn(Optional.of(new SuperHero("Rob", "Mannon", "RobotMan"))); @@ -76,7 +76,7 @@ public void canRetrieveByNameWhenExists() { } @Test - public void canRetrieveByNameWhenDoesNotExist() { + void canRetrieveByNameWhenDoesNotExist() { // given given(superHeroRepository.getSuperHero("RobotMan")) .willReturn(Optional.empty()); @@ -91,7 +91,7 @@ public void canRetrieveByNameWhenDoesNotExist() { } @Test - public void canCreateANewSuperHero() { + void canCreateANewSuperHero() { // when ResponseEntity superHeroResponse = restTemplate.postForEntity("/superheroes/", new SuperHero("Rob", "Mannon", "RobotMan"), SuperHero.class); @@ -101,7 +101,7 @@ public void canCreateANewSuperHero() { } @Test - public void headerIsPresent() throws Exception { + void headerIsPresent() throws Exception { // when ResponseEntity superHeroResponse = restTemplate.getForEntity("/superheroes/2", SuperHero.class);