Skip to content

Commit

Permalink
Fix test suite for Gradle
Browse files Browse the repository at this point in the history
  • Loading branch information
ryandens committed Aug 24, 2023
1 parent d3410b7 commit ddf1bd2
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 64 deletions.
2 changes: 1 addition & 1 deletion pom-operator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ dependencies {
testImplementation("fun.mike:diff-match-patch:0.0.2")
testImplementation("io.github.java-diff-utils:java-diff-utils:4.12")
testImplementation("org.hamcrest:hamcrest-all:1.3")
testImplementation("junit:junit:4.13.2")
testImplementation(testlibs.bundles.junit.jupiter)
compileOnly("org.slf4j:slf4j-api:2.0.0")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.9.2")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package io.github.pixee.maven.operator.test;

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

import io.github.pixee.maven.operator.Util;
import java.util.Arrays;
import java.util.List;
import org.apache.commons.lang3.SystemUtils;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class POMOperatorJavaIT {
@Test
Expand Down Expand Up @@ -35,6 +35,6 @@ public void testJavaSample() throws Exception {

int retCode = process.waitFor();

assertEquals("Embedded execution must return zero", 0, retCode);
assertEquals(0, retCode, "Embedded execution must return zero");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import io.github.pixee.maven.operator.ProjectModel
import io.github.pixee.maven.operator.ProjectModelFactory
import org.dom4j.Document
import org.dom4j.io.SAXReader
import org.junit.Assert.assertFalse
import org.junit.jupiter.api.Assertions.assertFalse
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.xmlunit.builder.DiffBuilder
Expand Down Expand Up @@ -57,8 +57,8 @@ open class AbstractTestBase {
LOGGER.debug("context after: {}", context)

assertFalse(
"Expected and outcome have differences",
getXmlDifferences(context.pomFile.resultPom, outcome).hasDifferences()
getXmlDifferences(context.pomFile.resultPom, outcome).hasDifferences(),
"Expected and outcome have differences"
)
} else {
val resultFilePath = "src/test/resources/" + this.javaClass.`package`.name.replace(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import io.github.pixee.maven.operator.POMScanner
import io.github.pixee.maven.operator.ProjectModelFactory
import io.github.pixee.maven.operator.Util.which
import org.apache.commons.lang3.SystemUtils
import org.junit.Assert.*
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.io.File
Expand Down Expand Up @@ -235,14 +236,16 @@ class MassRepoIT {
val dependencyAsStringWithPackaging = dependencyToUpgrade.toString()

assertFalse(
"Dependency should be originally missing", originalDependencies.contains(
dependencyAsStringWithPackaging
)
originalDependencies.contains(
dependencyAsStringWithPackaging
),
"Dependency should be originally missing"
)
assertTrue(
"New Dependency should be appearing", finalDependencies.contains(
dependencyAsStringWithPackaging
)
finalDependencies.contains(
dependencyAsStringWithPackaging
),
"New Dependency should be appearing"
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package io.github.pixee.maven.operator.test

import com.google.common.io.Files
import io.github.pixee.maven.operator.*
import org.junit.Test
import org.junit.jupiter.api.Test
import java.io.File
import kotlin.test.assertFalse
import kotlin.test.assertTrue

class POMOperatorMultipomTest : AbstractTestBase() {
@Test(expected = WrongDependencyTypeException::class)
@Test
fun testWithParentAndChildMissingPackaging() {
// expected = WrongDependencyTypeException::class
val parentResource = getResource("parent-and-child-parent-broken.xml")

val parentPomFiles = listOf(POMDocumentFactory.load(parentResource))
Expand All @@ -24,7 +25,7 @@ class POMOperatorMultipomTest : AbstractTestBase() {
)
}

@Test(expected = WrongDependencyTypeException::class)
@Test
fun testWithParentAndChildWrongType() {
val parentResource = getResource("parent-and-child-child-broken.xml")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.github.pixee.maven.operator.test

import io.github.pixee.maven.operator.*
import junit.framework.TestCase.*
import org.junit.Test
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.io.File
Expand All @@ -26,7 +26,7 @@ class POMOperatorQueryTest {

LOGGER.debug("Dependencies found: {}", dependencies)

assertTrue("Dependencies are not empty", dependencies.isNotEmpty())
assertTrue(dependencies.isNotEmpty(), "Dependencies are not empty")
}
}

Expand All @@ -40,11 +40,12 @@ class POMOperatorQueryTest {

val dependencies = POMOperator.queryDependency(context)

assertTrue("Dependencies are empty", dependencies.isEmpty())
assertTrue(dependencies.isEmpty(), "Dependencies are empty")
}

@Test(expected = IllegalStateException::class)
@Test
fun testFailedUnsafeQuery() {
// expected = IllegalStateException::class
val context =
ProjectModelFactory
.load(this.javaClass.getResource("pom-broken.xml")!!)
Expand All @@ -53,7 +54,7 @@ class POMOperatorQueryTest {

val dependencies = POMOperator.queryDependency(context)

assertTrue("Dependencies are empty", dependencies.isEmpty())
assertTrue(dependencies.isEmpty(), "Dependencies are empty")
}

@Test
Expand All @@ -74,7 +75,7 @@ class POMOperatorQueryTest {
val dependencies =
POMOperator.queryDependency(context, commandList = commandListOverride)

assertTrue("Dependencies are not empty", dependencies.isNotEmpty())
assertTrue(dependencies.isNotEmpty(), "Dependencies are not empty")
}
}
}
Expand All @@ -87,11 +88,11 @@ class POMOperatorQueryTest {

LOGGER.info("Using queryType: $queryType at $tempDirectory")

assertFalse("Temp Directory does not exist initially", tempDirectory.exists())
assertFalse(tempDirectory.exists(), "Temp Directory does not exist initially")
assertEquals(
"There must be no files",
tempDirectory.list()?.filter { File(it).isDirectory }?.size ?: 0,
0,
"There must be no files"
)

val context =
Expand All @@ -105,10 +106,10 @@ class POMOperatorQueryTest {

LOGGER.debug("Dependencies found: {}", dependencies)

assertTrue("Dependencies are not empty", dependencies.isNotEmpty())
assertTrue(dependencies.isNotEmpty(), "Dependencies are not empty")

assertTrue("Temp Directory ends up existing", tempDirectory.exists())
assertTrue("Temp Directory is a directory", tempDirectory.isDirectory)
assertTrue(tempDirectory.exists(), "Temp Directory ends up existing")
assertTrue(tempDirectory.isDirectory, "Temp Directory is a directory")
}
}

Expand All @@ -130,7 +131,7 @@ class POMOperatorQueryTest {

LOGGER.debug("Dependencies found: {}", dependencies)

assertTrue("Dependencies are not empty", dependencies.isNotEmpty())
assertTrue(dependencies.isNotEmpty(), "Dependencies are not empty")
}
}

Expand Down Expand Up @@ -179,9 +180,9 @@ class POMOperatorQueryTest {

LOGGER.debug("Dependencies found: {}", dependencies)

assertTrue("Dependencies are not empty", dependencies.isNotEmpty())
assertTrue(dependencies.isNotEmpty(), "Dependencies are not empty")

assertTrue("Random name matches", dependencies.first().artifactId.equals(randomName))
assertTrue(dependencies.first().artifactId.equals(randomName), "Random name matches")
}

@Test
Expand Down Expand Up @@ -268,9 +269,9 @@ class POMOperatorQueryTest {

LOGGER.debug("Dependencies found: {}", dependencies)

assertTrue("Dependencies are not empty", dependencies.isNotEmpty())
assertTrue(dependencies.isNotEmpty(), "Dependencies are not empty")

assertTrue("Random name matches", dependencies.first().artifactId.equals(randomName))
assertTrue(dependencies.first().artifactId.equals(randomName), "Random name matches")
}

@Test
Expand Down Expand Up @@ -332,7 +333,7 @@ class POMOperatorQueryTest {

LOGGER.debug("Dependencies found: {}", dependencies)

assertTrue("Dependencies are empty", dependencies.isEmpty())
assertTrue(dependencies.isEmpty(), "Dependencies are empty")
}

@Test
Expand Down Expand Up @@ -402,12 +403,12 @@ class POMOperatorQueryTest {

LOGGER.debug("Dependencies found: {}", dependencies)

assertTrue("Dependencies are empty", dependencies.isNotEmpty())
assertTrue(dependencies.isNotEmpty(), "Dependencies are empty")

val foundDependencies =
dependencies.firstOrNull { it.version == "0.0.1" && it.artifactId.equals("managed-$randomName") }

assertTrue("there's a dependencyManaged-version", foundDependencies != null)
assertTrue(foundDependencies != null, "there's a dependencyManaged-version")
}

private fun getCommandListFor(vararg names: String): List<Command> =
Expand Down Expand Up @@ -436,7 +437,7 @@ class POMOperatorQueryTest {

LOGGER.debug("Dependencies found: {}", dependencies)

assertTrue("Dependencies are empty", dependencies.isEmpty())
assertTrue(dependencies.isEmpty(), "Dependencies are empty")

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import io.github.pixee.maven.operator.Util.which
import org.apache.commons.lang3.SystemUtils
import org.dom4j.DocumentException
import org.hamcrest.MatcherAssert.assertThat
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import org.xmlunit.diff.ComparisonType
import java.io.File
import java.nio.charset.Charset
Expand All @@ -19,8 +19,9 @@ import kotlin.test.assertTrue
* Unit test for simple App.
*/
class POMOperatorTest : AbstractTestBase() {
@Test(expected = DocumentException::class)
@Test
fun testWithBrokenPom() {
// expected = DocumentException::class
gwt(
"broken-pom",
ProjectModelFactory.load(
Expand Down Expand Up @@ -76,8 +77,9 @@ class POMOperatorTest : AbstractTestBase() {
)
}

@Test(expected = MissingDependencyException::class)
@Test
fun testWithDependencyMissing() {
// expected = MissingDependencyException::class
gwt(
"case-dependency-missing",
ProjectModelFactory.load(
Expand Down Expand Up @@ -318,14 +320,15 @@ class POMOperatorTest : AbstractTestBase() {
)

assertEquals(
"Document changes a property called 'sample.version'",
differenceList.first().comparison.testDetails.xPath,
"/project[1]/properties[1]/sample.version[1]/text()[1]"
differenceList.first().comparison.testDetails.xPath,
"/project[1]/properties[1]/sample.version[1]/text()[1]",
"Document changes a property called 'sample.version'"
)
}

@Test(expected = IllegalStateException::class)
@Test
fun testCaseWithPropertyDefinedTwice() {
// expected = IllegalStateException::class
val dependencyToUpgrade =
Dependency("org.dom4j", "dom4j", version = "1.0.0")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package io.github.pixee.maven.operator.test

import io.github.pixee.maven.operator.InvalidPathException
import io.github.pixee.maven.operator.POMScanner
import org.junit.Test
import org.junit.jupiter.api.Test
import java.io.File
import kotlin.test.assertTrue
import kotlin.test.fail
Expand All @@ -17,8 +17,9 @@ class POMScannerTest: AbstractTestBase() {
val pmf = POMScanner.scanFrom(pomFile, currentDirectory)
}

@Test(expected = InvalidPathException::class)
@Test
fun testTwoLevelsWithLoop() {
// expected = InvalidPathException::class
val pomFile = getResourceAsFile("sample-child-with-relativepath-and-two-levels.xml")

val pmf = POMScanner.scanFrom(pomFile, currentDirectory)
Expand Down Expand Up @@ -102,4 +103,4 @@ class POMScannerTest: AbstractTestBase() {
}
}
}
}
}
Loading

0 comments on commit ddf1bd2

Please sign in to comment.