From 860453b46b73d7e977196a28439f1c4b4dca3c64 Mon Sep 17 00:00:00 2001 From: Toxic Dreamz Date: Wed, 19 Aug 2020 23:14:37 +0400 Subject: [PATCH] Fixed JUnit tests causing build issues due to mixing JUnit 4 & JUnit 5 --- .../java/org/dirty/flag/DirtyFlagTest.java | 14 +++---- partial-response/pom.xml | 14 +++---- .../com/iluwatar/partialresponse/AppTest.java | 11 +++--- .../partialresponse/FieldJsonMapperTest.java | 19 +++++---- .../partialresponse/VideoResourceTest.java | 39 +++++++++---------- pom.xml | 7 ++++ 6 files changed, 52 insertions(+), 52 deletions(-) diff --git a/dirty-flag/src/test/java/org/dirty/flag/DirtyFlagTest.java b/dirty-flag/src/test/java/org/dirty/flag/DirtyFlagTest.java index 6a3274a45..d0c9079a6 100644 --- a/dirty-flag/src/test/java/org/dirty/flag/DirtyFlagTest.java +++ b/dirty-flag/src/test/java/org/dirty/flag/DirtyFlagTest.java @@ -23,29 +23,27 @@ package org.dirty.flag; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; - import com.iluwatar.dirtyflag.DataFetcher; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; /** * Application test */ -public class DirtyFlagTest { +class DirtyFlagTest { @Test - public void testIsDirty() { + void testIsDirty() { var df = new DataFetcher(); var countries = df.fetch(); - assertFalse(countries.isEmpty()); + Assertions.assertTrue(countries.isEmpty()); } @Test - public void testIsNotDirty() { + void testIsNotDirty() { var df = new DataFetcher(); df.fetch(); var countries = df.fetch(); - assertTrue(countries.isEmpty()); + Assertions.assertTrue(countries.isEmpty()); } } diff --git a/partial-response/pom.xml b/partial-response/pom.xml index eb094874f..fad5450d9 100644 --- a/partial-response/pom.xml +++ b/partial-response/pom.xml @@ -35,13 +35,15 @@ partial-response - - junit - junit - org.junit.vintage junit-vintage-engine + 5.4.0 + test + + + org.mockito + mockito-junit-jupiter test @@ -49,10 +51,6 @@ junit-jupiter-engine test - - org.mockito - mockito-core - diff --git a/partial-response/src/test/java/com/iluwatar/partialresponse/AppTest.java b/partial-response/src/test/java/com/iluwatar/partialresponse/AppTest.java index b00ee6861..c423355f5 100644 --- a/partial-response/src/test/java/com/iluwatar/partialresponse/AppTest.java +++ b/partial-response/src/test/java/com/iluwatar/partialresponse/AppTest.java @@ -23,18 +23,17 @@ package com.iluwatar.partialresponse; -import org.junit.Test; - -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Assertions; /** * Application test */ -public class AppTest { +class AppTest { @Test - public void shouldExecuteApplicationWithoutException() { - assertDoesNotThrow(() -> App.main(new String[]{})); + void shouldExecuteApplicationWithoutException() { + Assertions.assertDoesNotThrow(() -> App.main(new String[]{})); } } \ No newline at end of file diff --git a/partial-response/src/test/java/com/iluwatar/partialresponse/FieldJsonMapperTest.java b/partial-response/src/test/java/com/iluwatar/partialresponse/FieldJsonMapperTest.java index 57741c1d7..6bf5bf190 100644 --- a/partial-response/src/test/java/com/iluwatar/partialresponse/FieldJsonMapperTest.java +++ b/partial-response/src/test/java/com/iluwatar/partialresponse/FieldJsonMapperTest.java @@ -23,24 +23,23 @@ package com.iluwatar.partialresponse; -import static org.junit.Assert.assertEquals; - -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * tests {@link FieldJsonMapper}. */ -public class FieldJsonMapperTest { - private FieldJsonMapper mapper; +class FieldJsonMapperTest { + private static FieldJsonMapper mapper; - @Before - public void setUp() { + @BeforeAll + static void setUp() { mapper = new FieldJsonMapper(); } @Test - public void shouldReturnJsonForSpecifiedFieldsInVideo() throws Exception { + void shouldReturnJsonForSpecifiedFieldsInVideo() throws Exception { var fields = new String[]{"id", "title", "length"}; var video = new Video( 2, "Godzilla Resurgence", 120, @@ -50,6 +49,6 @@ public class FieldJsonMapperTest { var jsonFieldResponse = mapper.toJson(video, fields); var expectedDetails = "{\"id\": 2,\"title\": \"Godzilla Resurgence\",\"length\": 120}"; - assertEquals(expectedDetails, jsonFieldResponse); + Assertions.assertEquals(expectedDetails, jsonFieldResponse); } } \ No newline at end of file diff --git a/partial-response/src/test/java/com/iluwatar/partialresponse/VideoResourceTest.java b/partial-response/src/test/java/com/iluwatar/partialresponse/VideoResourceTest.java index 252499803..dbd8e78dd 100644 --- a/partial-response/src/test/java/com/iluwatar/partialresponse/VideoResourceTest.java +++ b/partial-response/src/test/java/com/iluwatar/partialresponse/VideoResourceTest.java @@ -23,30 +23,29 @@ package com.iluwatar.partialresponse; -import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.when; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; import java.util.Map; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; /** * tests {@link VideoResource}. */ -@RunWith(MockitoJUnitRunner.class) -public class VideoResourceTest { +@ExtendWith(MockitoExtension.class) +class VideoResourceTest { @Mock - private FieldJsonMapper fieldJsonMapper; + private static FieldJsonMapper fieldJsonMapper; - private VideoResource resource; + private static VideoResource resource; - @Before - public void setUp() { + @BeforeAll + static void setUp() { var videos = Map.of( 1, new Video(1, "Avatar", 178, "epic science fiction film", "James Cameron", "English"), @@ -58,23 +57,23 @@ public class VideoResourceTest { } @Test - public void shouldGiveVideoDetailsById() throws Exception { + void shouldGiveVideoDetailsById() throws Exception { var actualDetails = resource.getDetails(1); var expectedDetails = "{\"id\": 1,\"title\": \"Avatar\",\"length\": 178,\"description\": " + "\"epic science fiction film\",\"director\": \"James Cameron\",\"language\": \"English\",}"; - assertEquals(expectedDetails, actualDetails); + Assertions.assertEquals(expectedDetails, actualDetails); } @Test - public void shouldGiveSpecifiedFieldsInformationOfVideo() throws Exception { + void shouldGiveSpecifiedFieldsInformationOfVideo() throws Exception { var fields = new String[]{"id", "title", "length"}; var expectedDetails = "{\"id\": 1,\"title\": \"Avatar\",\"length\": 178}"; - when(fieldJsonMapper.toJson(any(Video.class), eq(fields))).thenReturn(expectedDetails); + Mockito.when(fieldJsonMapper.toJson(Matchers.any(Video.class), Matchers.eq(fields))).thenReturn(expectedDetails); var actualFieldsDetails = resource.getDetails(2, fields); - assertEquals(expectedDetails, actualFieldsDetails); + Assertions.assertEquals(expectedDetails, actualFieldsDetails); } } \ No newline at end of file diff --git a/pom.xml b/pom.xml index 9b3382795..e917304a8 100644 --- a/pom.xml +++ b/pom.xml @@ -54,6 +54,7 @@ 1.3.2 1.19.0 1.4.8 + 3.5.0 https://sonarcloud.io iluwatar @@ -226,6 +227,12 @@ spring-webmvc ${spring.version} + + org.mockito + mockito-junit-jupiter + ${mockito-junit-jupiter.version} + test + com.h2database h2