Migrate to Junit 5 syntax (#421)

This commit is contained in:
Paul Campbell 2021-07-02 07:39:33 +01:00 committed by GitHub
parent 73b3248542
commit 7b1d8e7368
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 64 additions and 77 deletions

View file

@ -1,14 +1,10 @@
package net.kemitix.checkstyle.ruleset.builder; package net.kemitix.checkstyle.ruleset.builder;
import com.google.common.reflect.ClassPath; import org.junit.jupiter.api.Test;
import org.junit.Test;
import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Stream;
import static java.util.Collections.singletonList; import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;

View file

@ -1,6 +1,6 @@
package net.kemitix.checkstyle.ruleset.builder; package net.kemitix.checkstyle.ruleset.builder;
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.assertThat;

View file

@ -1,6 +1,6 @@
package net.kemitix.checkstyle.ruleset.builder; package net.kemitix.checkstyle.ruleset.builder;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.io.IOException; import java.io.IOException;

View file

@ -3,11 +3,11 @@ package net.kemitix.checkstyle.ruleset.builder;
import lombok.val; import lombok.val;
import me.andrz.builder.map.MapBuilder; import me.andrz.builder.map.MapBuilder;
import org.assertj.core.api.ThrowableAssert; import org.assertj.core.api.ThrowableAssert;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.rules.ExpectedException; import org.junit.jupiter.api.io.TempDir;
import org.junit.rules.TemporaryFolder;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
@ -36,11 +36,8 @@ public class CheckstyleWriterTest {
private static final String FILE_SEPARATOR = System.getProperty("file.separator"); private static final String FILE_SEPARATOR = System.getProperty("file.separator");
@org.junit.Rule @TempDir
public ExpectedException exception = ExpectedException.none(); public File folder;
@org.junit.Rule
public TemporaryFolder folder = new TemporaryFolder();
private CheckstyleWriter checkstyleWriter; private CheckstyleWriter checkstyleWriter;
@ -61,7 +58,7 @@ public class CheckstyleWriterTest {
private RuleClassLocator ruleClassLocator = mock(RuleClassLocator.class); private RuleClassLocator ruleClassLocator = mock(RuleClassLocator.class);
private SourcesProperties sourceProperties = new SourcesProperties(); private SourcesProperties sourceProperties = new SourcesProperties();
@Before @BeforeEach
public void setUp() throws Exception { public void setUp() throws Exception {
ruleName = "RegexpOnFilename"; ruleName = "RegexpOnFilename";
ruleClassname = "com.puppycrawl.tools.checkstyle.checks.regexp.RegexpOnFilenameCheck"; ruleClassname = "com.puppycrawl.tools.checkstyle.checks.regexp.RegexpOnFilenameCheck";
@ -74,12 +71,12 @@ public class CheckstyleWriterTest {
.put(getOutputFile(RuleLevel.COMPLEXITY)) .put(getOutputFile(RuleLevel.COMPLEXITY))
.build(); .build();
outputProperties.setRulesetFiles(outputFiles); outputProperties.setRulesetFiles(outputFiles);
outputDirectory = folder.newFolder() outputDirectory = folder.toPath();
.toPath(); Files.createDirectories(outputDirectory);
outputProperties.setDirectory(outputDirectory); outputProperties.setDirectory(outputDirectory);
templateProperties = new TemplateProperties(); templateProperties = new TemplateProperties();
val checkstyleTemplate = folder.newFile("checkstyle-template.xml") val checkstyleTemplate = folder.toPath().resolve("checkstyle-template.xml");
.toPath(); checkstyleTemplate.toFile().createNewFile();
Files.write( Files.write(
checkstyleTemplate, TEMPLATE.getBytes(StandardCharsets.UTF_8), StandardOpenOption.TRUNCATE_EXISTING); checkstyleTemplate, TEMPLATE.getBytes(StandardCharsets.UTF_8), StandardOpenOption.TRUNCATE_EXISTING);
templateProperties.setCheckstyleXml(checkstyleTemplate); templateProperties.setCheckstyleXml(checkstyleTemplate);

View file

@ -1,6 +1,6 @@
package net.kemitix.checkstyle.ruleset.builder; package net.kemitix.checkstyle.ruleset.builder;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.List; import java.util.List;

View file

@ -1,8 +1,8 @@
package net.kemitix.checkstyle.ruleset.builder; package net.kemitix.checkstyle.ruleset.builder;
import lombok.val; import lombok.val;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -20,7 +20,7 @@ public class DefaultReadmeIndexBuilderTest {
private RulesProperties rulesProperties; private RulesProperties rulesProperties;
@Before @BeforeEach
public void setUp() throws Exception { public void setUp() throws Exception {
rulesProperties = new RulesProperties(); rulesProperties = new RulesProperties();
indexBuilder = new DefaultReadmeIndexBuilder(rulesProperties); indexBuilder = new DefaultReadmeIndexBuilder(rulesProperties);

View file

@ -1,7 +1,7 @@
package net.kemitix.checkstyle.ruleset.builder; package net.kemitix.checkstyle.ruleset.builder;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.*; import java.util.*;
@ -27,7 +27,7 @@ public class DefaultRuleClassLocatorTest {
private final RuleSource checkstyleRuleSource = RuleSourceMother.checkstyle.get(); private final RuleSource checkstyleRuleSource = RuleSourceMother.checkstyle.get();
private final RuleSource sevntuRuleSource = RuleSourceMother.sevntu.get(); private final RuleSource sevntuRuleSource = RuleSourceMother.sevntu.get();
@Before @BeforeEach
public void setUp() { public void setUp() {
sourceProperties.setSources(Arrays.asList( sourceProperties.setSources(Arrays.asList(
checkstyleRuleSource, sevntuRuleSource checkstyleRuleSource, sevntuRuleSource

View file

@ -1,25 +1,25 @@
package net.kemitix.checkstyle.ruleset.builder; package net.kemitix.checkstyle.ruleset.builder;
import lombok.val; import lombok.val;
import org.junit.Before; import org.assertj.core.api.WithAssertions;
import org.junit.Test; import org.junit.jupiter.api.BeforeEach;
import org.junit.rules.ExpectedException; import org.junit.jupiter.api.Test;
import org.junit.rules.TemporaryFolder; import org.junit.jupiter.api.io.TempDir;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Arrays; import java.util.Arrays;
import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Tests for {@link DefaultRuleReadmeLoader}. * Tests for {@link DefaultRuleReadmeLoader}.
* *
* @author Paul Campbell (pcampbell@kemitix.net) * @author Paul Campbell (pcampbell@kemitix.net)
*/ */
public class DefaultRuleReadmeLoaderTest { public class DefaultRuleReadmeLoaderTest
implements WithAssertions {
private RuleReadmeLoader loader; private RuleReadmeLoader loader;
@ -27,17 +27,14 @@ public class DefaultRuleReadmeLoaderTest {
private Path fragments; private Path fragments;
@org.junit.Rule @TempDir
public TemporaryFolder folder = new TemporaryFolder(); public File folder;
@org.junit.Rule @BeforeEach
public ExpectedException exception = ExpectedException.none();
@Before
public void setUp() throws Exception { public void setUp() throws Exception {
final TemplateProperties templateProperties = new TemplateProperties(); final TemplateProperties templateProperties = new TemplateProperties();
fragments = folder.newFolder("fragments") fragments = folder.toPath().resolve("fragments");
.toPath(); Files.createDirectories(fragments);
templateProperties.setReadmeFragments(fragments); templateProperties.setReadmeFragments(fragments);
loader = new DefaultRuleReadmeLoader(templateProperties); loader = new DefaultRuleReadmeLoader(templateProperties);
rule = new Rule(); rule = new Rule();
@ -61,10 +58,10 @@ public class DefaultRuleReadmeLoaderTest {
public void loadEnabledWithMissingFragment() { public void loadEnabledWithMissingFragment() {
//given //given
rule.setEnabled(true); rule.setEnabled(true);
exception.expect(ReadmeFragmentNotFoundException.class);
exception.expectMessage("name");
//when //when
loader.load(rule); assertThatExceptionOfType(ReadmeFragmentNotFoundException.class)
.isThrownBy(() -> loader.load(rule))
.withMessage("name");
} }
@Test @Test

View file

@ -2,8 +2,8 @@ package net.kemitix.checkstyle.ruleset.builder;
import lombok.val; import lombok.val;
import org.assertj.core.api.SoftAssertions; import org.assertj.core.api.SoftAssertions;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.HashMap; import java.util.HashMap;
@ -17,7 +17,7 @@ public class OutputPropertiesTest {
private OutputProperties outputProperties; private OutputProperties outputProperties;
@Before @BeforeEach
public void setUp() throws Exception { public void setUp() throws Exception {
outputProperties = new OutputProperties(); outputProperties = new OutputProperties();
} }

View file

@ -1,12 +1,10 @@
package net.kemitix.checkstyle.ruleset.builder; package net.kemitix.checkstyle.ruleset.builder;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import java.util.UUID;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
@ -19,7 +17,7 @@ public class ReadmeBuilderTest {
private ReadmeBuilder readmeBuilder; private ReadmeBuilder readmeBuilder;
private String template = "i:%s,ec:%s,es:%s,dc:%s,ds:%s"; private String template = "i:%s,ec:%s,es:%s,dc:%s,ds:%s";
@Before @BeforeEach
public void setUp() { public void setUp() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);

View file

@ -1,7 +1,7 @@
package net.kemitix.checkstyle.ruleset.builder; package net.kemitix.checkstyle.ruleset.builder;
import lombok.val; import lombok.val;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.io.IOException; import java.io.IOException;

View file

@ -1,8 +1,8 @@
package net.kemitix.checkstyle.ruleset.builder; package net.kemitix.checkstyle.ruleset.builder;
import net.kemitix.files.FileReaderWriter; import net.kemitix.files.FileReaderWriter;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
@ -40,7 +40,7 @@ public class ReadmeWriterTest {
private String templateBody = UUID.randomUUID().toString(); private String templateBody = UUID.randomUUID().toString();
private String formattedOutput = UUID.randomUUID().toString(); private String formattedOutput = UUID.randomUUID().toString();
@Before @BeforeEach
public void setUp() throws IOException { public void setUp() throws IOException {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);

View file

@ -1,6 +1,6 @@
package net.kemitix.checkstyle.ruleset.builder; package net.kemitix.checkstyle.ruleset.builder;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.stream.Stream; import java.util.stream.Stream;

View file

@ -1,7 +1,7 @@
package net.kemitix.checkstyle.ruleset.builder; package net.kemitix.checkstyle.ruleset.builder;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
@ -44,7 +44,7 @@ public class RuleLoaderTest {
private String enabledRuleName = "enabled-" + UUID.randomUUID().toString(); private String enabledRuleName = "enabled-" + UUID.randomUUID().toString();
private String disabledRuleName = "disabled-" + UUID.randomUUID().toString(); private String disabledRuleName = "disabled-" + UUID.randomUUID().toString();
@Before @BeforeEach
public void setUp() { public void setUp() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);

View file

@ -1,7 +1,7 @@
package net.kemitix.checkstyle.ruleset.builder; package net.kemitix.checkstyle.ruleset.builder;
import lombok.val; import lombok.val;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.Arrays; import java.util.Arrays;

View file

@ -1,6 +1,6 @@
package net.kemitix.checkstyle.ruleset.builder; package net.kemitix.checkstyle.ruleset.builder;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.Random; import java.util.Random;
import java.util.UUID; import java.util.UUID;

View file

@ -2,9 +2,8 @@ package net.kemitix.checkstyle.ruleset.builder;
import lombok.val; import lombok.val;
import org.assertj.core.api.SoftAssertions; import org.assertj.core.api.SoftAssertions;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import java.net.URI; import java.net.URI;
@ -19,7 +18,7 @@ public class RuleTest {
private RuleSource ruleSource = RuleSourceMother.checkstyle.get(); private RuleSource ruleSource = RuleSourceMother.checkstyle.get();
@Before @BeforeEach
public void setUp() throws Exception { public void setUp() throws Exception {
rule = new Rule(); rule = new Rule();
} }

View file

@ -1,7 +1,7 @@
package net.kemitix.checkstyle.ruleset.builder; package net.kemitix.checkstyle.ruleset.builder;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
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.assertThat;
@ -14,7 +14,7 @@ public class RulesPropertiesTest {
private RulesProperties rulesProperties; private RulesProperties rulesProperties;
@Before @BeforeEach
public void setUp() { public void setUp() {
rulesProperties = new RulesProperties(); rulesProperties = new RulesProperties();
} }

View file

@ -1,7 +1,7 @@
package net.kemitix.checkstyle.ruleset.builder; package net.kemitix.checkstyle.ruleset.builder;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
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.assertThat;
@ -9,7 +9,7 @@ public class SourcesPropertiesTest {
private SourcesProperties sourcesProperties; private SourcesProperties sourcesProperties;
@Before @BeforeEach
public void setUp() { public void setUp() {
sourcesProperties = new SourcesProperties(); sourcesProperties = new SourcesProperties();
} }

View file

@ -1,8 +1,8 @@
package net.kemitix.checkstyle.ruleset.builder; package net.kemitix.checkstyle.ruleset.builder;
import org.assertj.core.api.SoftAssertions; import org.assertj.core.api.SoftAssertions;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.io.File; import java.io.File;
import java.nio.file.Path; import java.nio.file.Path;
@ -17,7 +17,7 @@ public class TemplatePropertiesTest {
private TemplateProperties templateProperties; private TemplateProperties templateProperties;
@Before @BeforeEach
public void setUp() throws Exception { public void setUp() throws Exception {
templateProperties = new TemplateProperties(); templateProperties = new TemplateProperties();
} }