Fixed JUnit tests causing build issues due to mixing JUnit 4 & JUnit 5
This commit is contained in:
@ -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[]{}));
|
||||
}
|
||||
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user