Skip to content

Commit

Permalink
Add badge sonatype
Browse files Browse the repository at this point in the history
  • Loading branch information
jsalinaspolo committed Mar 2, 2021
1 parent d5291c9 commit 83a9af7
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 9 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![Build Status](https://travis-ci.org/jsalinaspolo/logcapture.svg?branch=master)](https://travis-ci.org/jsalinaspolo/logcapture)
[![Download](https://api.bintray.com/packages/jspcore/maven/logcapture-core/images/download.svg?version=1.2.1) ](https://bintray.com/jspcore/maven/logcapture-core/1.2.1/link)
[![Sonatype Nexus](https://img.shields.io/nexus/r/org.logcapture/logcapture-core?server=https%3A%2F%2Fs01.oss.sonatype.org)](https://repo1.maven.org/maven2/org/logcapture/)
[![codecov](https://codecov.io/gh/jsalinaspolo/logcapture/branch/master/graph/badge.svg)](https://codecov.io/gh/jsalinaspolo/logcapture)
[![Known Vulnerabilities](https://snyk.io/test/github/jsalinaspolo/logcapture/badge.svg?targetFile=build.gradle)](https://snyk.io/test/github/jsalinaspolo/logcapture?targetFile=build.gradle)

Expand Down Expand Up @@ -75,29 +75,29 @@ More example how to use the library at [ExampleShould.java](https://github.com/j

## Binaries

Binaries and dependency information for Maven, Ivy, Gradle and others can be found at [http://search.maven.org](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.logcapture%22%20AND%20a%3A%22logcapture%22).
Binaries and dependency information for Maven, Ivy, Gradle and others can be found at [http://search.maven.org](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.logcapture%22%20AND%20a%3A%22logcapture%22).

Gradle

```
testImplementation 'com.logcapture:logcapture-core:x.y.z'
testImplementation 'org.logcapture:logcapture-core:x.y.z'
```

add one of the test library dependency

```
testImplementation 'com.logcapture:logcapture-junit4:x.y.z'
testImplementation 'com.logcapture:logcapture-junit5:x.y.z'
testImplementation 'com.logcapture:logcapture-spock:x.y.z'
testImplementation 'com.logcapture:logcapture-kotest:x.y.z'
testImplementation 'org.logcapture:logcapture-junit4:x.y.z'
testImplementation 'org.logcapture:logcapture-junit5:x.y.z'
testImplementation 'org.logcapture:logcapture-spock:x.y.z'
testImplementation 'org.logcapture:logcapture-kotest:x.y.z'
```


Maven:

```xml
<dependency>
<groupId>com.logcapture</groupId>
<groupId>org.logcapture</groupId>
<artifactId>logcapture-core</artifactId>
<version>x.y.z</version>
</dependency>
Expand Down
6 changes: 6 additions & 0 deletions logcapture-example/logcapture-example.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

dependencies {
implementation "org.logcapture:logcapture-core:1.2.2"
implementation "org.logcapture:logcapture-junit4:1.2.2"
implementation "junit:junit:4.12"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package org.logcapture.example;

import org.logcapture.junit4.LogCaptureRule;
import org.junit.Rule;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.slf4j.MarkerFactory;

import static ch.qos.logback.classic.Level.INFO;
import static org.logcapture.assertion.ExpectedLoggedException.logException;
import static org.logcapture.assertion.ExpectedLoggingMessage.aLog;
import static org.logcapture.matcher.exception.ExceptionCauseMatcher.causeOf;
import static org.logcapture.matcher.exception.ExceptionCauseMessageMatcher.whereCauseMessage;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.isA;

public class ExampleShould {
private final Logger log = LoggerFactory.getLogger(ExampleShould.class);

@Rule
public LogCaptureRule logCaptureRule = new LogCaptureRule();

private ServiceThatLogs underTest = new ServiceThatLogs();

@Test
public void verify_captured_events() {
underTest.methodThatLogsStuff();
logCaptureRule.logged(aLog().info()
.withMessage("a message"));
}

@Test
public void verify_captured_events_with_marker() {
log.info(MarkerFactory.getMarker("a_marker"), "a message");
logCaptureRule.logged(aLog()
.withLevel(equalTo(INFO))
.withMarker("a_marker")
.withMessage(equalTo("a message")));
}

@Test
public void verify_captured_events_with_exception() {
RuntimeException exception = new RuntimeException();

underTest.methodThatLogs(exception);
logCaptureRule.logged(aLog()
.havingException(logException()
.withException(isA(RuntimeException.class))
));
}

@Test
public void verify_captured_events_with_exception_cause_message() {
RuntimeException exception = new RuntimeException(new IllegalStateException("Some state is invalid"));
underTest.methodThatLogs(exception);
logCaptureRule.logged(aLog()
.havingException(logException()
.withException(whereCauseMessage(containsString("state is invalid")))
));
}

@Test
public void verify_captured_events_with_exception_cause() {
RuntimeException exception = new RuntimeException(new IllegalStateException("Some state is invalid"));
underTest.methodThatLogs(exception);
logCaptureRule.logged(aLog()
.havingException(logException()
.withException(causeOf(IllegalStateException.class))
));
}

@Test
public void verify_mdc_keys() {
MDC.put("aKey", "someValue");

underTest.methodThatLogsStuff();
logCaptureRule.logged(aLog().info()
.withMdc("aKey", equalTo("someValue"))
.withMessage("a message"));
}

class ServiceThatLogs {

void methodThatLogsStuff() {
log.info("a message");
log.info("another message");
}

void methodThatLogs(Exception exception) {
log.error("message", exception);
}
}
}
3 changes: 2 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ include 'logcapture-core',
'logcapture-junit5',
'logcapture-spock',
'logcapture-spock2',
'logcapture-kotest'
'logcapture-kotest',
'logcapture-example'

rootProject.name = 'logcapture'
rootProject.children.each { child ->
Expand Down

0 comments on commit 83a9af7

Please sign in to comment.