package org.openrewrite.java.cleanup
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.openrewrite.PathUtils
import org.openrewrite.java.JavaParser
import org.openrewrite.test.RecipeSpec
import org.openrewrite.test.RewriteTest
import java.nio.file.Paths
interface LowercasePackageTest : RewriteTest {
// Note, you can define defaults for the RecipeSpec and these defaults will be
override fun defaults(spec: RecipeSpec) {
.recipe(LowercasePackage()) // Which recipe each test should run
// A java source file that already has a lowercase package name should be left
fun packageIsAlreadyLowercase() = rewriteRun(
// Assert that a java source file with uppercase letters in its package name
// is correctly transformed by the recipe.
fun lowerCasePackage() = rewriteRun(
// Each test can customize the RecipeSpec prior to execution of the test.
// In this case, the recipe has already been defined in defaults(), and
// this test will use a parser that logs warnings and errors
.parser(JavaParser.fromJavaVersion()
.logCompilationWarningsAndErrors(false)
// The Java source file before transformation:
package com.UPPERCASE.CamelCase;
// The expected Java source file after transformation.
package com.uppercase.camelcase;
// An optional callback that can be used after the recipe has been
// executed to assert additional conditions on the resulting source file.
assertThat(PathUtils.equalIgnoringSeparators(cu.sourcePath, Paths.get("com/uppercase/camelcase/A.java"))).isTrue
// This test defines both source files and asserts that each file is correctly
// handled by the recipe.
fun combinedExample() = rewriteRun(
// Assert the first source file is not modified.
//Assert the second source file is modified.
package com.UPPERCASE.CamelCase;
package com.uppercase.camelcase;