Migrate tests to JUnit 5 (#8519)

Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
Wouter Born
2020-09-21 18:21:26 +02:00
committed by GitHub
parent 6df6783b60
commit bd82ca82df
478 changed files with 3996 additions and 4419 deletions

View File

@@ -12,10 +12,8 @@
*/
package org.openhab.binding.robonect.internal;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.ExecutionException;
@@ -26,10 +24,11 @@ import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.http.HttpMethod;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.jupiter.MockitoExtension;
import org.openhab.binding.robonect.internal.model.ErrorList;
import org.openhab.binding.robonect.internal.model.MowerInfo;
import org.openhab.binding.robonect.internal.model.Name;
@@ -38,25 +37,20 @@ import org.openhab.binding.robonect.internal.model.VersionInfo;
/**
* The goal of this class is to test the functionality of the RobonectClient,
* by mocking the module responses.
*
*
* @author Marco Meyer - Initial contribution
*/
@ExtendWith(MockitoExtension.class)
public class RobonectClientTest {
private RobonectClient subject;
@Mock
private HttpClient httpClientMock;
private @Mock HttpClient httpClientMock;
private @Mock ContentResponse responseMock;
private @Mock Request requestMock;
@Mock
private ContentResponse responseMock;
@Mock
private Request requestMock;
@Before
@BeforeEach
public void init() {
MockitoAnnotations.initMocks(this);
RobonectEndpoint dummyEndPoint = new RobonectEndpoint("123.456.789.123", null, null);
subject = new RobonectClient(httpClientMock, dummyEndPoint);
}
@@ -179,33 +173,33 @@ public class RobonectClientTest {
verify(httpClientMock, times(1)).newRequest("http://123.456.789.123/json?cmd=status");
}
@Test(expected = RobonectCommunicationException.class)
@Test
public void shouldReceiveErrorAnswerOnInterruptedException()
throws InterruptedException, ExecutionException, TimeoutException {
when(httpClientMock.newRequest("http://123.456.789.123/json?cmd=status")).thenReturn(requestMock);
when(requestMock.method(HttpMethod.GET)).thenReturn(requestMock);
when(requestMock.timeout(30000L, TimeUnit.MILLISECONDS)).thenReturn(requestMock);
when(requestMock.send()).thenThrow(new InterruptedException("Mock Interrupted Exception"));
MowerInfo answer = subject.getMowerInfo();
assertThrows(RobonectCommunicationException.class, () -> subject.getMowerInfo());
}
@Test(expected = RobonectCommunicationException.class)
@Test
public void shouldReceiveErrorAnswerOnExecutionException()
throws InterruptedException, ExecutionException, TimeoutException {
when(httpClientMock.newRequest("http://123.456.789.123/json?cmd=status")).thenReturn(requestMock);
when(requestMock.method(HttpMethod.GET)).thenReturn(requestMock);
when(requestMock.timeout(30000L, TimeUnit.MILLISECONDS)).thenReturn(requestMock);
when(requestMock.send()).thenThrow(new ExecutionException(new Exception("Mock Exception")));
MowerInfo answer = subject.getMowerInfo();
assertThrows(RobonectCommunicationException.class, () -> subject.getMowerInfo());
}
@Test(expected = RobonectCommunicationException.class)
@Test
public void shouldReceiveErrorAnswerOnTimeoutException()
throws InterruptedException, ExecutionException, TimeoutException {
when(httpClientMock.newRequest("http://123.456.789.123/json?cmd=status")).thenReturn(requestMock);
when(requestMock.method(HttpMethod.GET)).thenReturn(requestMock);
when(requestMock.timeout(30000L, TimeUnit.MILLISECONDS)).thenReturn(requestMock);
when(requestMock.send()).thenThrow(new TimeoutException("Mock Timeout Exception"));
MowerInfo answer = subject.getMowerInfo();
assertThrows(RobonectCommunicationException.class, () -> subject.getMowerInfo());
}
}

View File

@@ -12,7 +12,7 @@
*/
package org.openhab.binding.robonect.internal.handler;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*;
@@ -21,12 +21,15 @@ import java.time.ZoneId;
import java.time.ZonedDateTime;
import org.eclipse.jetty.client.HttpClient;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import org.openhab.binding.robonect.internal.RobonectBindingConstants;
import org.openhab.binding.robonect.internal.RobonectClient;
import org.openhab.binding.robonect.internal.model.ErrorEntry;
@@ -57,28 +60,20 @@ import org.openhab.core.types.UnDefType;
*
* @author Marco Meyer - Initial contribution
*/
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.WARN)
public class RobonectHandlerTest {
private RobonectHandler subject;
@Mock
private Thing robonectThingMock;
private @Mock Thing robonectThingMock;
private @Mock RobonectClient robonectClientMock;
private @Mock ThingHandlerCallback callbackMock;
private @Mock HttpClient httpClientMock;
private @Mock TimeZoneProvider timezoneProvider;
@Mock
private RobonectClient robonectClientMock;
@Mock
private ThingHandlerCallback callbackMock;
@Mock
private HttpClient httpClientMock;
@Mock
private TimeZoneProvider timezoneProvider;
@Before
@BeforeEach
public void setUp() {
MockitoAnnotations.initMocks(this);
subject = new RobonectHandler(robonectThingMock, httpClientMock, timezoneProvider);
subject.setCallback(callbackMock);
subject.setRobonectClient(robonectClientMock);

View File

@@ -12,12 +12,12 @@
*/
package org.openhab.binding.robonect.internal.model;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import java.nio.charset.StandardCharsets;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/**
* The goal of this class is to test the model parser to make sure the structures
@@ -29,7 +29,7 @@ public class ModelParserTest {
private ModelParser subject;
@Before
@BeforeEach
public void setUp() {
subject = new ModelParser();
}