Skip to content

Commit

Permalink
#108 from junit4 to juni5
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Nov 27, 2020
1 parent 01b1d41 commit c5a9cba
Show file tree
Hide file tree
Showing 29 changed files with 532 additions and 698 deletions.
30 changes: 13 additions & 17 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
<parent>
<groupId>com.jcabi</groupId>
<artifactId>jcabi</artifactId>
<version>1.24</version>
<version>1.26.0</version>
</parent>
<artifactId>jcabi-log</artifactId>
<version>1.0-SNAPSHOT</version>
Expand Down Expand Up @@ -79,13 +79,24 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.21</version>
<version>1.8.0-beta1</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand All @@ -104,21 +115,6 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
<extensions>true</extensions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-invoker-plugin</artifactId>
<version>2.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<profiles>
<profile>
Expand Down
4 changes: 2 additions & 2 deletions src/it/it-decoloring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
<parent>
<groupId>com.jcabi</groupId>
<artifactId>jcabi</artifactId>
<version>1.20.1</version>
<version>1.26.0</version>
</parent>
<groupId>com.jcabi</groupId>
<artifactId>jcabi-log-test</artifactId>
Expand All @@ -46,7 +46,7 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<artifactId>commons-text</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Copyright (c) 2012-2017, jcabi.com
* All rights reserved.
*
Expand Down Expand Up @@ -29,12 +29,12 @@
*/
package com.jcabi.log;

import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.text.StringEscapeUtils;
import org.apache.log4j.Level;
import org.apache.log4j.spi.LoggingEvent;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

/**
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/com/jcabi/log/MsDecor.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,23 +112,23 @@ public void formatTo(final Formatter formatter, final int flags,
private String toText(final int precision) {
final double number;
final String title;
if (this.millis < 1000L) {
if (this.millis < 1000.0) {
number = this.millis;
title = "ms";
} else if (this.millis < 1000L * 60) {
number = this.millis / 1000L;
} else if (this.millis < (double) (1000L * 60L)) {
number = this.millis / 1000.0;
title = "s";
} else if (this.millis < 1000L * 60 * 60) {
number = this.millis / (1000L * 60);
} else if (this.millis < (double) (1000L * 60L * 60L)) {
number = this.millis / (double) (1000L * 60L);
title = "min";
} else if (this.millis < 1000L * 60 * 60 * 24) {
number = this.millis / (1000L * 60 * 60);
} else if (this.millis < (double) (1000L * 60L * 60L * 24L)) {
number = this.millis / (double) (1000L * 60L * 60L);
title = "hr";
} else if (this.millis < 1000L * 60 * 60 * 24 * 30) {
number = this.millis / (1000L * 60 * 60 * 24);
} else if (this.millis < (double) (1000L * 60L * 60L * 24L * 30L)) {
number = this.millis / (double) (1000L * 60L * 60L * 24L);
title = "days";
} else {
number = this.millis / (1000L * 60 * 60 * 24 * 30);
number = this.millis / (double) (1000L * 60L * 60L * 24L * 30L);
title = "mon";
}
final String format;
Expand Down
41 changes: 18 additions & 23 deletions src/test/java/com/jcabi/log/ConversionPatternTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.jupiter.api.Test;

/**
* Test case for {@link ConversionPattern}.
Expand All @@ -51,9 +51,6 @@ public final class ConversionPatternTest {
*/
private static final Colors COLORS = new Colors();

/**
* Test some edge cases: these shouldn't result in replacement.
*/
@Test
public void testGenerateNoReplacement() {
MatcherAssert.assertThat(
Expand All @@ -78,10 +75,6 @@ public void testGenerateNoReplacement() {
);
}

/**
* Test the empty edge case: should be replaced with the wrapped empty
* string.
*/
@Test
public void testGenerateEmpty() {
MatcherAssert.assertThat(
Expand All @@ -90,9 +83,6 @@ public void testGenerateEmpty() {
);
}

/**
* Normal test cases.
*/
@Test
public void testGenerateSimple() {
MatcherAssert.assertThat(
Expand All @@ -111,27 +101,32 @@ public void testGenerateSimple() {
);
}

/**
* Test cases where the body includes curly braces. The correct (balanced)
* curly brace pair should be replaced.
*/
@Test
public void testGenerateCurlyBraces() {
MatcherAssert.assertThat(
convert("%color{%c{1}}"),
Matchers.equalTo(colorWrap("%c{1}"))
ConversionPatternTest.convert("%color{%c{1}}"),
Matchers.equalTo(ConversionPatternTest.colorWrap("%c{1}"))
);
MatcherAssert.assertThat(
convert("%color{%c{1}}foo"),
Matchers.equalTo(String.format("%sfoo", colorWrap("%c{1}")))
ConversionPatternTest.convert("%color{%c{1}}foo"),
Matchers.equalTo(
String.format("%sfoo", ConversionPatternTest.colorWrap("%c{1}"))
)
);
MatcherAssert.assertThat(
convert("%color{%c1}}foo"),
Matchers.equalTo(String.format("%s}foo", colorWrap("%c1")))
ConversionPatternTest.convert("%color{%c1}}foo"),
Matchers.equalTo(
String.format("%s}foo", ConversionPatternTest.colorWrap("%c1"))
)
);
MatcherAssert.assertThat(
convert("%color{%c{{{1}{2}}}}foo"),
Matchers.equalTo(String.format("%sfoo", colorWrap("%c{{{1}{2}}}")))
ConversionPatternTest.convert("%color{%c{{{1}{2}}}}foo"),
Matchers.equalTo(
String.format(
"%sfoo",
ConversionPatternTest.colorWrap("%c{{{1}{2}}}")
)
)
);
}

Expand Down
23 changes: 11 additions & 12 deletions src/test/java/com/jcabi/log/DecorsManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@

import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

/**
* Test case for {@link DecorsManager}.
Expand All @@ -42,10 +43,6 @@
*/
public final class DecorsManagerTest {

/**
* DecorsManager can return one of built-in decors.
* @throws Exception If some problem
*/
@Test
public void hasBuiltInDecors() throws Exception {
MatcherAssert.assertThat(
Expand All @@ -54,13 +51,15 @@ public void hasBuiltInDecors() throws Exception {
);
}

/**
* DecorsManager can throw exception if a decor is missed.
* @throws Exception If some problem
*/
@Test(expected = DecorException.class)
public void throwsExceptionForAbsentDecor() throws Exception {
DecorsManager.decor("non-existing-formatter", null);
@Test
public void throwsExceptionForAbsentDecor() {
Assertions.assertThrows(
DecorException.class,
() -> {
DecorsManager.decor("non-existing-formatter", null);
}
);

}

}
10 changes: 1 addition & 9 deletions src/test/java/com/jcabi/log/DomDecorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import java.util.Formatter;
import javax.xml.parsers.DocumentBuilderFactory;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.mockito.hamcrest.MockitoHamcrest;
import org.w3c.dom.Document;
Expand All @@ -46,10 +46,6 @@
*/
public final class DomDecorTest {

/**
* DocumentDecor can transform Document to text.
* @throws Exception If some problem
*/
@Test
public void convertsDocumentToText() throws Exception {
final Document doc = DocumentBuilderFactory.newInstance()
Expand All @@ -64,10 +60,6 @@ public void convertsDocumentToText() throws Exception {
);
}

/**
* DocumentDecor can handle NULL properly.
* @throws Exception If some problem
*/
@Test
public void convertsNullToText() throws Exception {
final Formattable decor = new DomDecor(null);
Expand Down
10 changes: 1 addition & 9 deletions src/test/java/com/jcabi/log/ExceptionDecorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import java.util.Formattable;
import java.util.Formatter;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.mockito.hamcrest.MockitoHamcrest;

Expand All @@ -45,10 +45,6 @@
*/
public final class ExceptionDecorTest {

/**
* ExceptionDecor can transform exception to text.
* @throws Exception If some problem
*/
@Test
public void convertsExceptionToText() throws Exception {
final Formattable decor = new ExceptionDecor(new IOException("ouch!"));
Expand All @@ -69,10 +65,6 @@ public void convertsExceptionToText() throws Exception {
);
}

/**
* ExceptionDecor can handle NULL properly.
* @throws Exception If some problem
*/
@Test
public void convertsNullToText() throws Exception {
final Formattable decor = new ExceptionDecor(null);
Expand Down
8 changes: 2 additions & 6 deletions src/test/java/com/jcabi/log/LineNumberTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import org.apache.log4j.WriterAppender;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.jupiter.api.Test;

/**
* Test case for %L pattern.
Expand All @@ -55,10 +55,6 @@ public final class LineNumberTest {
*/
private static final String CONV_PATTERN = "%c:%L";

/**
* PaternLayout can use %L properly.
* @throws Exception If something goes wrong
*/
@Test
public void testLineNumber() throws Exception {
final PatternLayout layout = new PatternLayout();
Expand All @@ -75,7 +71,7 @@ public void testLineNumber() throws Exception {
MatcherAssert.assertThat(
writer.toString(),
Matchers.containsString(
"com.jcabi.log.LineNumberTest:73"
"com.jcabi.log.LineNumberTest:247"
)
);
} finally {
Expand Down
Loading

0 comments on commit c5a9cba

Please sign in to comment.