Skip to content
This repository has been archived by the owner on Jun 29, 2023. It is now read-only.

Commit

Permalink
Use Mockito's JUnit Jupiter extension #147
Browse files Browse the repository at this point in the history
  • Loading branch information
mp911de committed Jun 5, 2018
1 parent 93b53a3 commit 8036e3a
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 91 deletions.
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,13 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;

import external.MockitoExtension;
import org.mockito.junit.jupiter.MockitoExtension;

/**
* @author Mark Paluch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import biz.paluch.logging.gelf.GelfMessageAssembler;
import external.MockitoExtension;

/**
* @author Mark Paluch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;

import external.MockitoExtension;
import org.mockito.junit.jupiter.MockitoExtension;

/**
* @author Mark Paluch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentMatchers;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import biz.paluch.logging.gelf.intern.ErrorReporter;
import biz.paluch.logging.gelf.intern.GelfMessage;
import biz.paluch.logging.gelf.netty.NettyLocalHTTPServer;
import external.MockitoExtension;
import io.netty.handler.codec.http.HttpResponseStatus;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import biz.paluch.logging.gelf.intern.ErrorReporter;
import biz.paluch.logging.gelf.intern.GelfMessage;
import external.MockitoExtension;

/**
* @author Mark Paluch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import biz.paluch.logging.gelf.intern.ErrorReporter;
import biz.paluch.logging.gelf.intern.GelfMessage;
import external.MockitoExtension;

/**
* @author Mark Paluch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentMatchers;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import biz.paluch.logging.gelf.GelfMessageAssembler;
import biz.paluch.logging.gelf.intern.GelfSenderConfiguration;
import biz.paluch.logging.gelf.intern.GelfSenderFactory;
import biz.paluch.logging.gelf.intern.GelfSenderProvider;
import external.MockitoExtension;

/**
* @author Mark Paluch
Expand All @@ -46,22 +46,23 @@ public class GelfLogHandlerErrorsTests {

@BeforeEach
public void before() throws Exception {
GelfSenderFactory.addGelfSenderProvider(senderProvider);

when(senderProvider.supports(anyString())).thenReturn(true);
GelfSenderFactory.addGelfSenderProvider(senderProvider);
sut.setErrorManager(errorManager);

}

@AfterEach
public void after() throws Exception {
public void after() {
GelfSenderFactory.removeGelfSenderProvider(senderProvider);
GelfSenderFactory.removeAllAddedSenderProviders();
}

@Test
public void testRuntimeExceptionOnCreateSender() throws Exception {

sut.setGraylogHost(THE_HOST);

when(senderProvider.supports(anyString())).thenReturn(true);
when(senderProvider.create(any(GelfSenderConfiguration.class))).thenThrow(new IllegalStateException());

sut.publish(MESSAGE);
Expand All @@ -70,15 +71,15 @@ public void testRuntimeExceptionOnCreateSender() throws Exception {
}

@Test
public void testInvalidMessage() throws Exception {
public void testInvalidMessage() {

sut.publish(MESSAGE);

verify(errorManager, atLeast(1)).error(anyString(), ArgumentMatchers.<Exception> isNull(), anyInt());
}

@Test
public void testErrorOnSend() throws Exception {
public void testErrorOnSend() {

sut.publish(MESSAGE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentMatchers;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import biz.paluch.logging.gelf.GelfMessageAssembler;
import biz.paluch.logging.gelf.intern.GelfSenderFactory;
import biz.paluch.logging.gelf.intern.GelfSenderProvider;
import external.MockitoExtension;

/**
* @author Mark Paluch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import biz.paluch.logging.gelf.intern.GelfSenderFactory;
import biz.paluch.logging.gelf.intern.GelfSenderProvider;
Expand All @@ -19,7 +20,6 @@
import ch.qos.logback.core.Context;
import ch.qos.logback.core.status.Status;
import ch.qos.logback.core.status.StatusManager;
import external.MockitoExtension;

@ExtendWith(MockitoExtension.class)
public class GelfLogbackAppenderErrorsUnitTests {
Expand Down
74 changes: 0 additions & 74 deletions src/test/java/external/MockitoExtension.java

This file was deleted.

0 comments on commit 8036e3a

Please sign in to comment.