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,8 +12,9 @@
*/
package org.openhab.binding.networkupstools.internal;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import java.io.File;
import java.io.IOException;
@@ -28,7 +29,7 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.commons.io.FileUtils;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openhab.core.library.CoreItemFactory;
/**
@@ -75,7 +76,7 @@ public class NutNameChannelsTest {
for (final Entry<NutName, String> entry : readMeNutNames.entrySet()) {
final Matcher matcher = README_PATTERN.matcher(entry.getValue());
assertNotNull("Could not find NutName in readme for : " + entry.getValue(), entry.getKey());
assertNotNull(entry.getKey(), "Could not find NutName in readme for : " + entry.getValue());
if (matcher.find()) {
list.add(String.format(TEMPLATE_CHANNEL, entry.getKey().getChannelId(),
nutNameToChannelType(entry.getKey())));
@@ -145,10 +146,10 @@ public class NutNameChannelsTest {
private NutName lineToNutName(final String line) {
final Matcher matcher = README_PATTERN.matcher(line);
assertTrue("Could not match readme line: " + line, matcher.find());
assertTrue(matcher.find(), "Could not match readme line: " + line);
final String name = matcher.group(1);
final NutName channelIdToNutName = NutName.channelIdToNutName(name);
assertNotNull("Name should not match null: '" + name + "' ->" + line, channelIdToNutName);
assertNotNull(channelIdToNutName, "Name should not match null: '" + name + "' ->" + line);
return channelIdToNutName;
}

View File

@@ -12,14 +12,14 @@
*/
package org.openhab.binding.networkupstools.internal;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang.StringUtils;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
* Test class to check the validity of the {@link NutName} enum.
@@ -38,12 +38,12 @@ public class NutNameTest {
for (final NutName nn : NutName.values()) {
final Matcher matcher = CHANNEL_PATTERN.matcher(nn.getName());
assertTrue("NutName name '" + nn + "' could not be matched with expected pattern.", matcher.find());
assertTrue(matcher.find(), "NutName name '" + nn + "' could not be matched with expected pattern.");
final String expectedChannelId = matcher.group(1)
+ StringUtils.capitalize(Optional.ofNullable(matcher.group(2)).orElse(""))
+ StringUtils.capitalize(Optional.ofNullable(matcher.group(3)).orElse(""))
+ StringUtils.capitalize(Optional.ofNullable(matcher.group(4)).orElse(""));
assertEquals("Channel name not correct", expectedChannelId, nn.getChannelId());
assertEquals(expectedChannelId, nn.getChannelId(), "Channel name not correct");
}
}
}

View File

@@ -12,10 +12,9 @@
*/
package org.openhab.binding.networkupstools.internal.nut;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.MockitoAnnotations.initMocks;
import java.io.IOException;
import java.io.InputStream;
@@ -27,24 +26,25 @@ import java.nio.file.Paths;
import java.util.Map;
import org.eclipse.jdt.annotation.NonNull;
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.junit.jupiter.MockitoExtension;
/**
* Unit test to test the {@link NutApi} using a mock Socket connection.
*
* @author Hilbrand Bouwkamp - Initial contribution
*/
@ExtendWith(MockitoExtension.class)
public class NutApiTest {
@Mock
private Socket socket;
private @Mock Socket socket;
private NutConnector connector;
@Before
@BeforeEach
public void setUp() throws IOException {
initMocks(this);
connector = new NutConnector("localhost", 0, "test", "pwd") {
@Override
protected Socket newSocket() {