Skip to content

Commit

Permalink
junit5/jupiter test migration for some tests in the service-base module.
Browse files Browse the repository at this point in the history
All the base tests needed for testing device registries implementations are now using junit5. The file based registry unit tests use Junit5
Signed-off-by: Trystram Jean-Baptiste <jbtrystram@redhat.com>
  • Loading branch information
jbtrystram committed May 1, 2019
1 parent ce8c4c7 commit d5f98a0
Show file tree
Hide file tree
Showing 23 changed files with 877 additions and 814 deletions.
11 changes: 11 additions & 0 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-junit5</artifactId>
<version>${vertx.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
Expand All @@ -228,6 +233,12 @@
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-junit5</artifactId>
Expand Down
13 changes: 13 additions & 0 deletions service-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,23 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-junit5</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

import org.eclipse.hono.config.ServiceConfigProperties;
import org.eclipse.hono.util.Constants;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.*;
Expand All @@ -46,7 +46,7 @@ public class AbstractServiceBaseTest {
/**
* Sets up common mock objects used by the test cases.
*/
@Before
@BeforeEach
public void initMocks() {
eventBus = mock(EventBus.class);
vertx = mock(Vertx.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
package org.eclipse.hono.service;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

import org.eclipse.hono.util.EventBusMessage;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import io.vertx.core.Future;
import io.vertx.core.json.JsonObject;
Expand All @@ -36,7 +37,7 @@ public class EventBusServiceTest {
/**
* Sets up the fixture.
*/
@BeforeClass
@BeforeAll
public static void setUp() {
service = new EventBusService<Object>() {

Expand Down Expand Up @@ -90,13 +91,13 @@ public void testValidType() {
.put("intValue", 42);

final String stringValue = EventBusService.getTypesafeValueForField(String.class, payload, "stringValue");
Assert.assertEquals("foo", stringValue);
assertEquals("foo", stringValue);

final Integer intValue = EventBusService.getTypesafeValueForField(Integer.class, payload, "intValue");
Assert.assertEquals(Integer.valueOf(42), intValue);
assertEquals(Integer.valueOf(42), intValue);

final Boolean booleanValue = EventBusService.getTypesafeValueForField(Boolean.class, payload, "booleanValue");
Assert.assertEquals(Boolean.TRUE, booleanValue);
assertEquals(Boolean.TRUE, booleanValue);
}

/**
Expand All @@ -107,10 +108,10 @@ public void testInvalidType() {
final JsonObject device = new JsonObject().put("device-id", "someValue");

final String stringValue = EventBusService.getTypesafeValueForField(String.class, device, "device-id");
Assert.assertEquals("someValue", stringValue);
assertEquals("someValue", stringValue);

final Integer intValue = EventBusService.getTypesafeValueForField(Integer.class, device, "device-id");
Assert.assertNull(intValue);
assertNull(intValue);
}

/**
Expand All @@ -121,7 +122,6 @@ public void testGetNull() {
final JsonObject device = new JsonObject().put("device-id", (String) null);

final String value = EventBusService.getTypesafeValueForField(String.class, device, "device-id");
Assert.assertNull(value);
assertNull(value);
}

}
Loading

0 comments on commit d5f98a0

Please sign in to comment.