Skip to content

Commit

Permalink
Convert tests to JUnit 5
Browse files Browse the repository at this point in the history
  • Loading branch information
slachiewicz committed Apr 14, 2024
1 parent 9357430 commit 1da0cdd
Show file tree
Hide file tree
Showing 29 changed files with 778 additions and 701 deletions.
11 changes: 5 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,6 @@
<artifactId>plexus-build-api</artifactId>
<version>${plexus-build-api.version}</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-matchers</artifactId>
Expand Down Expand Up @@ -274,6 +268,11 @@
<version>1.5.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun.istack</groupId>
<artifactId>istack-commons-runtime</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
import org.codehaus.mojo.jaxb2.shared.Validate;
import org.codehaus.mojo.jaxb2.shared.filters.Filter;
import org.codehaus.mojo.jaxb2.shared.filters.pattern.PatternFileFilter;
import org.junit.Assert;
import org.junit.Before;
import org.junit.jupiter.api.BeforeEach;
import org.w3c.dom.Document;
import se.jguru.shared.algorithms.api.resources.PropertyResources;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* @author <a href="mailto:lj@jguru.se">Lennart J&ouml;relid</a>, jGuru Europe AB
*/
Expand All @@ -31,7 +33,7 @@ public abstract class AbstractJavadocExtractorTest {
protected JavaDocExtractor extractor;
protected List<Filter<File>> javaSourceExcludeFilter;

@Before
@BeforeEach
public void setupSharedState() {

sourceRootDirectories = new ArrayList<File>();
Expand All @@ -54,14 +56,14 @@ protected void addSourceRootDirectory(final String resourcePath) {

final String effectiveResourcePath = resourcePath.charAt(0) == '/' ? resourcePath : "/" + resourcePath;
final URL resource = Thread.currentThread().getContextClassLoader().getResource(effectiveResourcePath);
Assert.assertNotNull("Effective resourcePath [" + resourcePath + "] could not be found.", resource);
assertNotNull(resource, "Effective resourcePath [" + resourcePath + "] could not be found.");

final File toAdd = new File(resource.getPath());
final boolean exists = toAdd.exists();
final boolean isDirectory = toAdd.isDirectory();

Assert.assertTrue("Resource [" + toAdd.getAbsolutePath() + "] was nonexistent.", exists);
Assert.assertTrue("Resource [" + toAdd.getAbsolutePath() + "] was not a directory.", isDirectory);
assertTrue(exists, "Resource [" + toAdd.getAbsolutePath() + "] was nonexistent.");
assertTrue(isDirectory, "Resource [" + toAdd.getAbsolutePath() + "] was not a directory.");

sourceRootDirectories.add(toAdd);
}
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,17 @@
import org.codehaus.mojo.jaxb2.shared.Validate;
import org.custommonkey.xmlunit.Diff;
import org.custommonkey.xmlunit.XMLUnit;
import org.junit.Assert;
import org.junit.Before;
import org.junit.jupiter.api.BeforeEach;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* @author <a href="mailto:lj@jguru.se">Lennart J&ouml;relid</a>, jGuru Europe AB
*/
Expand Down Expand Up @@ -70,10 +72,10 @@ public AbstractSourceCodeAwareNodeProcessingTest() {
// Setup the basic directories.
basedir = getBasedir();
testJavaDir = new File(basedir, "src/test/java");
Assert.assertTrue(testJavaDir.exists() && testJavaDir.isDirectory());
assertTrue(testJavaDir.exists() && testJavaDir.isDirectory());
}

@Before
@BeforeEach
public final void setupSharedState() throws Exception {

log = new BufferingLog(BufferingLog.LogLevel.DEBUG);
Expand All @@ -92,7 +94,7 @@ public final void setupSharedState() throws Exception {

// Create the JAXBContext
jaxbClasses = getJaxbAnnotatedClassesForJaxbContext();
Assert.assertNotNull("getJaxbAnnotatedClassesForJaxbContext() should not return a null List.", jaxbClasses);
assertNotNull(jaxbClasses, "getJaxbAnnotatedClassesForJaxbContext() should not return a null List.");
final Class<?>[] classArray = jaxbClasses.toArray(new Class<?>[jaxbClasses.size()]);
jaxbContext = JAXBContext.newInstance(classArray);

Expand Down Expand Up @@ -174,8 +176,8 @@ protected File getBasedir() {
}

final File toReturn = new File(basedirPath);
Assert.assertNotNull("Could not find 'basedir'. Please set the system property 'basedir'.", toReturn);
Assert.assertTrue("'basedir' must be an existing directory. ", toReturn.exists() && toReturn.isDirectory());
assertNotNull(toReturn, "Could not find 'basedir'. Please set the system property 'basedir'.");
assertTrue(toReturn.exists() && toReturn.isDirectory(), "'basedir' must be an existing directory. ");

// All done.
return toReturn;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,23 @@
import java.util.TreeMap;

import org.codehaus.mojo.jaxb2.schemageneration.XsdGeneratorHelper;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import se.jguru.shared.algorithms.api.resources.PropertyResources;

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

/**
* @author <a href="mailto:lj@jguru.se">Lennart J&ouml;relid</a>, jGuru Europe AB
*/
public class DomHelperTest {
class DomHelperTest {

@Test
public void validateDomHelperAccessors() throws Exception {
void validateDomHelperAccessors() throws Exception {

// Assemble
final String xsd = PropertyResources.readFully("testdata/schemageneration/javadoc/enums/rawEnumSchema.xsd");
Expand Down Expand Up @@ -50,15 +52,15 @@ public void validateDomHelperAccessors() throws Exception {
}

// Assert
Assert.assertNotNull(xpath2ValueMap);
Assert.assertEquals(3, xpath2ValueMap.size());
assertNotNull(xpath2ValueMap);
assertEquals(3, xpath2ValueMap.size());

final String prefix =
"#document/xs:schema/xs:simpleType[@name='foodPreference']/" + "xs:restriction/xs:enumeration[@value='";

Assert.assertEquals("LACTO_VEGETARIAN", xpath2ValueMap.get(prefix + "LACTO_VEGETARIAN']"));
Assert.assertEquals("NONE", xpath2ValueMap.get(prefix + "NONE']"));
Assert.assertEquals("VEGAN", xpath2ValueMap.get(prefix + "VEGAN']"));
assertEquals("LACTO_VEGETARIAN", xpath2ValueMap.get(prefix + "LACTO_VEGETARIAN']"));
assertEquals("NONE", xpath2ValueMap.get(prefix + "NONE']"));
assertEquals("VEGAN", xpath2ValueMap.get(prefix + "VEGAN']"));
}

//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,21 @@
import jakarta.xml.bind.annotation.XmlType;
import org.codehaus.mojo.jaxb2.schemageneration.postprocessing.javadoc.location.FieldLocation;
import org.codehaus.mojo.jaxb2.schemageneration.postprocessing.schemaenhancement.XmlNameAnnotatedClassWithFieldAccess;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

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

/**
* @author <a href="mailto:lj@jguru.se">Lennart J&ouml;relid</a>, jGuru Europe AB
*/
public class FieldLocationTest {
class FieldLocationTest {

private Class<XmlNameAnnotatedClassWithFieldAccess> theClass;
private Map<String, Field> fieldName2MethodMap;

@Before
public void setupSharedState() {
@BeforeEach
void setupSharedState() {

fieldName2MethodMap = new TreeMap<String, Field>();

Expand All @@ -35,7 +36,7 @@ public void setupSharedState() {
}

@Test
public void validateFieldLocationWithXmlName() throws Exception {
void validateFieldLocationWithXmlName() throws Exception {

// Assemble
final String packageName = theClass.getPackage().getName();
Expand Down Expand Up @@ -64,9 +65,9 @@ public void validateFieldLocationWithXmlName() throws Exception {
packageName, theClass.getSimpleName(), classXmlName, stringField.getName(), stringFieldXmlName);

// Assert
Assert.assertEquals(expectedIntegerFieldPath, integerFieldLocation.getPath());
Assert.assertEquals(expectedStringFieldPath, stringFieldLocation.getPath());
Assert.assertEquals(expectedIntegerFieldToString, integerFieldLocation.toString());
Assert.assertEquals(integerFieldXmlName, integerFieldLocation.getMemberName());
assertEquals(expectedIntegerFieldPath, integerFieldLocation.getPath());
assertEquals(expectedStringFieldPath, stringFieldLocation.getPath());
assertEquals(expectedIntegerFieldToString, integerFieldLocation.toString());
assertEquals(integerFieldXmlName, integerFieldLocation.getMemberName());
}
}
Loading

0 comments on commit 1da0cdd

Please sign in to comment.