Skip to content

Commit

Permalink
Upgradte tests to JUnit5 (#521)
Browse files Browse the repository at this point in the history
* Replace Junit4 by JUnit5 v5.7.1
* Bump assertj to v3.19.0
* Bump mockito to v3.8.0
* Bump lombok to v1.18.18
  • Loading branch information
abelsromero committed Mar 25, 2021
1 parent 5d2e24d commit 329c13a
Show file tree
Hide file tree
Showing 19 changed files with 62 additions and 61 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Maintenance::
* Rewrite `AsciidoctorHttpMojoTest` to Java to make it more approachable (#516)
* Rewrite `AsciidoctorZipMojoTest` to Java to make it more approachable (#518)
* Rewrite `AsciidoctorDoxiaParserTest` to Java + remove Groovy & Spock configurations (#519)
* Upgrade tests to JUni5 (#521)

== v2.1.0 (2020-09-15)

Expand Down
24 changes: 17 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@
<doxia.version>1.8</doxia.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.7.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.jruby</groupId>
Expand Down Expand Up @@ -143,27 +155,25 @@
<version>${doxia.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>test</scope>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.16.1</version>
<version>3.19.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.3.0</version>
<version>3.8.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
<version>1.18.18</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.apache.maven.plugin.MojoFailureException;
import org.asciidoctor.maven.io.TestFilesHelper;
import org.asciidoctor.maven.io.UserInputSimulator;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.assertj.core.api.Assertions;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import java.io.File;

Expand Down Expand Up @@ -188,7 +188,7 @@ public void should_apply_code_highlighting_with_prettify() throws MojoFailureExc
.contains("prettify");
}

@Ignore("Not supported in Asciidoctorj (gem not embedded)")
@Disabled("Not supported in Asciidoctorj (gem not embedded)")
@Test
public void should_apply_code_highlighting_with_pygments() throws MojoFailureException, MojoExecutionException {
// given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import org.asciidoctor.maven.io.ConsoleHolder;
import org.asciidoctor.maven.test.processors.*;
import org.assertj.core.api.Assertions;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.util.Arrays;
Expand Down Expand Up @@ -374,7 +374,7 @@ public void should_convert_to_html_using_all_extension_types() throws MojoFailur
* To execute, copy _org.asciidoctor.extension.spi.ExtensionRegistry to
* /src/test/resources/META-INF/services/ and execute
*/
@Ignore
@Disabled
@Test
public void property_extension() throws MojoFailureException, MojoExecutionException {
// given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
import org.asciidoctor.maven.io.ConsoleHolder;
import org.asciidoctor.maven.log.FailIf;
import org.asciidoctor.maven.log.LogHandler;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;


import java.io.File;
import java.util.Arrays;
Expand Down Expand Up @@ -129,7 +130,7 @@ public void should_not_fail_and_log_errors_as_INFO_when_outputToConsole_is_set()
consoleHolder.release();
}

@Ignore
@Disabled
@Test
public void should_not_fail_and_log_errors_as_INFO_when_outputToConsole_is_set_and_doc_contains_messages_without_cursor_and_verbose_is_enabled() throws MojoFailureException, MojoExecutionException {
// setup
Expand Down Expand Up @@ -169,7 +170,7 @@ public void should_not_fail_and_log_errors_as_INFO_when_outputToConsole_is_set_a

}

@Ignore
@Disabled
@Test
public void should_not_fail_and_log_verbose_errors_when_gempath_is_set() throws MojoFailureException, MojoExecutionException {
// setup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.asciidoctor.maven.io.ConsoleHolder;
import org.asciidoctor.maven.test.processors.RequireCheckerTreeprocessor;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.io.*;
import java.nio.file.Files;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.asciidoctor.maven.TestUtils.ResourceBuilder;
import org.asciidoctor.maven.io.ConsoleHolder;
import org.codehaus.plexus.logging.console.ConsoleLogger;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.sonatype.plexus.build.incremental.BuildContext;
import org.sonatype.plexus.build.incremental.DefaultBuildContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.asciidoctor.maven.io.TestFilesHelper;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.io.IOException;
Expand Down
37 changes: 13 additions & 24 deletions src/test/java/org/asciidoctor/maven/SourceDirectoryFinderTest.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package org.asciidoctor.maven;

import org.asciidoctor.maven.process.SourceDirectoryFinder;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import java.io.File;
import java.io.IOException;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
Expand All @@ -16,8 +14,8 @@

public class SourceDirectoryFinderTest {

@Rule
public TemporaryFolder testFolder = new TemporaryFolder();
@TempDir
public File testDirectory;

private static final File MOJO_DEFAULT_SOURCE_DIR = new File(SourceDirectoryFinder.DEFAULT_SOURCE_DIR);
private static final File[] FALLBACK_CANDIDATES = new File[]{
Expand All @@ -30,9 +28,8 @@ public class SourceDirectoryFinderTest {


@Test
public void should_not_try_candidates_and_not_find_when_initial_does_not_match_default_value() throws IOException {
public void should_not_try_candidates_and_not_find_when_initial_does_not_match_default_value() {
// given
final File testDirectory = testFolder.newFolder();
final File fakePath = new File("fake_path");

// when
Expand All @@ -46,9 +43,8 @@ public void should_not_try_candidates_and_not_find_when_initial_does_not_match_d
}

@Test
public void should_not_try_candidates_and_find_when_initial_does_not_match_default_value() throws IOException {
public void should_not_try_candidates_and_find_when_initial_does_not_match_default_value() {
// given
final File testDirectory = testFolder.newFolder();
final File fakePath = new File("fake_path");
new File(testDirectory, fakePath.toString()).mkdirs();

Expand All @@ -61,9 +57,8 @@ public void should_not_try_candidates_and_find_when_initial_does_not_match_defau
}

@Test
public void should_find_default_candidate_when_set_as_relative_path() throws IOException {
public void should_find_default_candidate_when_set_as_relative_path() {
// given
final File testDirectory = testFolder.newFolder();
final File candidate = MOJO_DEFAULT_SOURCE_DIR;
new File(testDirectory, candidate.toString()).mkdirs();

Expand All @@ -78,9 +73,8 @@ public void should_find_default_candidate_when_set_as_relative_path() throws IOE
}

@Test
public void should_find_default_candidate_when_set_as_absolute_path() throws IOException {
public void should_find_default_candidate_when_set_as_absolute_path() {
// given
final File testDirectory = testFolder.newFolder();
final File candidate = new File(testDirectory, MOJO_DEFAULT_SOURCE_DIR.toString());
candidate.mkdirs();

Expand All @@ -95,9 +89,8 @@ public void should_find_default_candidate_when_set_as_absolute_path() throws IOE
}

@Test
public void should_find_first_fallback_candidate_when_set_as_relative_path() throws IOException {
public void should_find_first_fallback_candidate_when_set_as_relative_path() {
// given
final File testDirectory = testFolder.newFolder();
final File candidate = FALLBACK_CANDIDATES[0];
new File(testDirectory, FALLBACK_CANDIDATES[0].toString()).mkdirs();
final File defaultSourceDir = MOJO_DEFAULT_SOURCE_DIR;
Expand All @@ -113,9 +106,8 @@ public void should_find_first_fallback_candidate_when_set_as_relative_path() thr
}

@Test
public void should_find_first_fallback_candidate_when_set_as_absolute_path() throws IOException {
public void should_find_first_fallback_candidate_when_set_as_absolute_path() {
// given
final File testDirectory = testFolder.newFolder();
final File candidate = new File(testDirectory, FALLBACK_CANDIDATES[0].toString());
candidate.mkdirs();
final File defaultSourceDir = MOJO_DEFAULT_SOURCE_DIR;
Expand All @@ -131,9 +123,8 @@ public void should_find_first_fallback_candidate_when_set_as_absolute_path() thr
}

@Test
public void should_find_second_fallback_candidate_when_set_as_relative_path() throws IOException {
public void should_find_second_fallback_candidate_when_set_as_relative_path() {
// given
final File testDirectory = testFolder.newFolder();
final File candidate = FALLBACK_CANDIDATES[1];
new File(testDirectory, FALLBACK_CANDIDATES[1].toString()).mkdirs();
final File defaultSourceDir = MOJO_DEFAULT_SOURCE_DIR;
Expand All @@ -149,9 +140,8 @@ public void should_find_second_fallback_candidate_when_set_as_relative_path() th
}

@Test
public void should_find_second_fallback_candidate_when_set_as_absolute_path() throws IOException {
public void should_find_second_fallback_candidate_when_set_as_absolute_path() {
// given
final File testDirectory = testFolder.newFolder();
final File candidate = new File(testDirectory, FALLBACK_CANDIDATES[1].toString());
candidate.mkdirs();
final File defaultSourceDir = MOJO_DEFAULT_SOURCE_DIR;
Expand All @@ -167,9 +157,8 @@ public void should_find_second_fallback_candidate_when_set_as_absolute_path() th
}

@Test
public void should_try_all_candidates_and_not_find_any_candidate_when_initial_is_default() throws IOException {
public void should_try_all_candidates_and_not_find_any_candidate_when_initial_is_default() {
// given
final File testDirectory = testFolder.newFolder();
final File defaultSourceDir = MOJO_DEFAULT_SOURCE_DIR;

// when
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import lombok.Value;
import org.apache.commons.io.IOUtils;
import org.apache.maven.plugin.logging.Log;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.asciidoctor.ast.Cursor;
import org.asciidoctor.log.LogRecord;
import org.asciidoctor.log.Severity;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.asciidoctor.maven.process;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.apache.maven.model.Resource;
import org.apache.maven.plugin.logging.Log;
import org.asciidoctor.maven.AsciidoctorRefreshMojo;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.asciidoctor.maven.refresh;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.apache.maven.doxia.sink.impl.AbstractTextSink;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import java.io.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.asciidoctor.AttributesBuilder;
import org.asciidoctor.OptionsBuilder;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.util.AbstractMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.asciidoctor.maven.log.FailIf;
import org.asciidoctor.maven.log.LogHandler;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
import org.asciidoctor.extension.Treeprocessor;
import org.asciidoctor.jruby.internal.JRubyRuntimeContext;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class RequireCheckerTreeprocessor extends Treeprocessor {

@Override
public Document process(Document document) {
assertEquals("constant", JRubyRuntimeContext.get(document).evalScriptlet("defined? ::DateTime").toString());
// Leave a trace in the converted document so that the test can check that I was called
document.getBlocks().add(createBlock(document, "paragraph", RequireCheckerTreeprocessor.class.getSimpleName() + " was here"));
return document;
}
@Override
public Document process(Document document) {
assertEquals("constant", JRubyRuntimeContext.get(document).evalScriptlet("defined? ::DateTime").toString());
// Leave a trace in the converted document so that the test can check that I was called
document.getBlocks().add(createBlock(document, "paragraph", RequireCheckerTreeprocessor.class.getSimpleName() + " was here"));
return document;
}
}

0 comments on commit 329c13a

Please sign in to comment.