-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
345 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<artifactId>hello-elf4j-world</artifactId> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<release>${java.version}</release> | ||
<source>${java.version}</source> | ||
<target>${java.version}</target> | ||
</configuration> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<version>3.13.0</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<version>3.5.2</version> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<dependencies> | ||
<!-- | ||
<dependency> | ||
<artifactId>@project.artifactId@</artifactId> | ||
<groupId>@project.groupId@</groupId> | ||
<scope>test</scope> | ||
</dependency> | ||
--> | ||
<dependency> | ||
<artifactId>mock-loggers-elf4j</artifactId> | ||
<groupId>io.github.vitalijr2.logging</groupId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<artifactId>elf4j</artifactId> | ||
<groupId>io.github.elf4j</groupId> | ||
<version>4.1.0</version> | ||
</dependency> | ||
<dependency> | ||
<artifactId>hamcrest</artifactId> | ||
<groupId>org.hamcrest</groupId> | ||
<scope>test</scope> | ||
<version>3.0</version> | ||
</dependency> | ||
<dependency> | ||
<artifactId>junit-jupiter-engine</artifactId> | ||
<groupId>org.junit.jupiter</groupId> | ||
<scope>test</scope> | ||
<version>${junit.version}</version> | ||
</dependency> | ||
<dependency> | ||
<artifactId>junit-jupiter-params</artifactId> | ||
<groupId>org.junit.jupiter</groupId> | ||
<scope>test</scope> | ||
<version>${junit.version}</version> | ||
</dependency> | ||
<dependency> | ||
<artifactId>mockito-core</artifactId> | ||
<groupId>org.mockito</groupId> | ||
<scope>test</scope> | ||
<version>${mockito.version}</version> | ||
</dependency> | ||
<dependency> | ||
<artifactId>mockito-junit-jupiter</artifactId> | ||
<groupId>org.mockito</groupId> | ||
<scope>test</scope> | ||
<version>${mockito.version}</version> | ||
</dependency> | ||
</dependencies> | ||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<artifactId>mock-loggers-bom</artifactId> | ||
<!-- | ||
<groupId>@project.groupId@</groupId> | ||
--> | ||
<groupId>io.github.vitalijr2.logging</groupId> | ||
<scope>import</scope> | ||
<type>pom</type> | ||
<version>1.2.0-SNAPSHOT</version> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
<description>Basic example</description> | ||
<groupId>example.hello</groupId> | ||
<modelVersion>4.0.0</modelVersion> | ||
<properties> | ||
<java.version>11</java.version> | ||
<junit.version>5.11.4</junit.version> | ||
<mockito.version>5.15.2</mockito.version> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
<version>1.0.0</version> | ||
</project> |
27 changes: 27 additions & 0 deletions
27
elf4j/src/it/hello-elf4j-world/src/main/java/example/hello/HelloService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package example.hello; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import elf4j.Logger; | ||
|
||
public class HelloService { | ||
|
||
private final Logger log = Logger.instance(); | ||
|
||
public String sayHelloWorld() { | ||
return sayHello("World"); | ||
} | ||
|
||
public String sayHello(String name) { | ||
if (requireNonNull(name, "Name is missed").isBlank()) { | ||
throw new IllegalArgumentException("Name is empty"); | ||
} | ||
|
||
var greeting = "Hello " + name + "!"; | ||
|
||
log.atInfo().log(greeting); | ||
|
||
return greeting; | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
elf4j/src/it/hello-elf4j-world/src/test/java/example/hello/HelloServiceAnnotationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package example.hello; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.verifyNoMoreInteractions; | ||
import static org.mockito.Mockito.when; | ||
|
||
import elf4j.Logger; | ||
import io.github.vitalijr2.logging.mock.MockLoggers; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
@MockLoggers | ||
class HelloServiceAnnotationTest { | ||
|
||
@BeforeEach | ||
void setUp() { | ||
var logger = Logger.instance(); | ||
|
||
when(Logger.instance().atInfo()).thenReturn(logger); | ||
} | ||
|
||
@DisplayName("Names") | ||
@ParameterizedTest(name = "<{0}>") | ||
@ValueSource(strings = {"John", "Jane"}) | ||
void names(String name) { | ||
var helloService = new HelloService(); | ||
|
||
assertDoesNotThrow(() -> helloService.sayHello(name)); | ||
|
||
verify(Logger.instance()).atInfo(); | ||
verify(Logger.instance()).log("Hello " + name + "!"); | ||
verifyNoMoreInteractions(Logger.instance()); | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
elf4j/src/it/hello-elf4j-world/src/test/java/example/hello/HelloServiceBasicTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package example.hello; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.verifyNoMoreInteractions; | ||
import static org.mockito.Mockito.when; | ||
|
||
import elf4j.Logger; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class HelloServiceBasicTest { | ||
|
||
@DisplayName("Hello world") | ||
@Test | ||
void helloWorld() { | ||
var helloService = new HelloService(); | ||
var logger = Logger.instance(); | ||
|
||
when(Logger.instance().atInfo()).thenReturn(logger); | ||
|
||
assertDoesNotThrow(helloService::sayHelloWorld); | ||
|
||
verify(Logger.instance()).atInfo(); | ||
verify(Logger.instance()).log("Hello World!"); | ||
verifyNoMoreInteractions(Logger.instance()); | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
elf4j/src/it/hello-elf4j-world/src/test/java/example/hello/HelloServiceExtensionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package example.hello; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.verifyNoMoreInteractions; | ||
import static org.mockito.Mockito.when; | ||
|
||
import elf4j.Logger; | ||
import io.github.vitalijr2.logging.mock.MockLoggerExtension; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
@ExtendWith(MockLoggerExtension.class) | ||
class HelloServiceExtensionTest { | ||
|
||
private static Logger logger; | ||
|
||
@BeforeAll | ||
static void setUpClass() { | ||
logger = Logger.instance(); | ||
} | ||
|
||
@BeforeEach | ||
void setUp() { | ||
when(Logger.instance().atInfo()).thenReturn(logger); | ||
} | ||
|
||
@DisplayName("Names") | ||
@ParameterizedTest(name = "<{0}>") | ||
@ValueSource(strings = {"John", "Jane"}) | ||
void names(String name) { | ||
var helloService = new HelloService(); | ||
|
||
assertDoesNotThrow(() -> helloService.sayHello(name)); | ||
|
||
verify(Logger.instance()).atInfo(); | ||
verify(Logger.instance()).log("Hello " + name + "!"); | ||
verifyNoMoreInteractions(Logger.instance()); | ||
} | ||
|
||
} |
66 changes: 66 additions & 0 deletions
66
elf4j/src/it/hello-elf4j-world/src/test/java/example/hello/HelloServiceFullTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package example.hello; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.core.StringStartsWith.startsWith; | ||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.mockito.Mockito.clearInvocations; | ||
import static org.mockito.Mockito.reset; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.verifyNoInteractions; | ||
import static org.mockito.Mockito.verifyNoMoreInteractions; | ||
import static org.mockito.Mockito.when; | ||
|
||
import elf4j.Logger; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.NullAndEmptySource; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
class HelloServiceFullTest { | ||
|
||
private static Logger logger; | ||
|
||
@BeforeAll | ||
static void setUpClass() { | ||
logger = Logger.instance(); | ||
} | ||
|
||
@BeforeEach | ||
void setUp() { | ||
clearInvocations(logger); | ||
reset(logger); | ||
} | ||
|
||
@DisplayName("Names") | ||
@ParameterizedTest(name = "<{0}>") | ||
@ValueSource(strings = {"John", "Jane"}) | ||
void names(String name) { | ||
var helloService = new HelloService(); | ||
|
||
when(Logger.instance().atInfo()).thenReturn(logger); | ||
|
||
assertDoesNotThrow(() -> helloService.sayHello(name)); | ||
|
||
verify(Logger.instance()).atInfo(); | ||
verify(Logger.instance()).log("Hello " + name + "!"); | ||
verifyNoMoreInteractions(Logger.instance()); | ||
} | ||
|
||
@DisplayName("Null or empty name") | ||
@ParameterizedTest(name = "<{0}>") | ||
@NullAndEmptySource | ||
@ValueSource(strings = " ") | ||
void nullOrEmptyName(String name) { | ||
var helloService = new HelloService(); | ||
|
||
var exception = assertThrows(RuntimeException.class, () -> helloService.sayHello(name)); | ||
|
||
verifyNoInteractions(Logger.instance()); | ||
|
||
assertThat(exception.getMessage(), startsWith("Name is")); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<settings> | ||
<profiles> | ||
<profile> | ||
<activation> | ||
<activeByDefault>true</activeByDefault> | ||
</activation> | ||
<id>it-repo</id> | ||
<pluginRepositories> | ||
<pluginRepository> | ||
<id>local.central</id> | ||
<releases> | ||
<enabled>true</enabled> | ||
</releases> | ||
<snapshots> | ||
<enabled>true</enabled> | ||
</snapshots> | ||
<url>@localRepositoryUrl@</url> | ||
</pluginRepository> | ||
</pluginRepositories> | ||
<repositories> | ||
<repository> | ||
<id>local.central</id> | ||
<releases> | ||
<enabled>true</enabled> | ||
</releases> | ||
<snapshots> | ||
<enabled>true</enabled> | ||
</snapshots> | ||
<url>@localRepositoryUrl@</url> | ||
</repository> | ||
</repositories> | ||
</profile> | ||
</profiles> | ||
</settings> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters