Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.takari.maven.testing.executor.MavenRuntime;
import io.takari.maven.testing.executor.junit.MavenPluginTest;
import java.nio.file.Paths;
import org.junit.jupiter.api.DisplayName;

/**
* @author Réda Housni Alaoui
Expand All @@ -27,8 +28,9 @@ public AbstractMavenModuleTest(
}

@MavenPluginTest
public void GIVEN_bad_formatted_files_WHEN_format_code_THEN_all_files_should_have_correct_format()
throws Exception {
@DisplayName(
"GIVEN bad formatted files WHEN format code THEN all files should have correct format")
public void test1() throws Exception {
mavenExecution()
.withCliOptions(goalCliOption("validate-code-format"))
.execute()
Expand All @@ -45,19 +47,19 @@ public void GIVEN_bad_formatted_files_WHEN_format_code_THEN_all_files_should_hav
}

@MavenPluginTest
public void
GIVEN_bad_formatted_file_WHEN_validating_THEN_the_command_formatting_all_files_is_displayed()
throws Exception {
@DisplayName(
"GIVEN bad formatted file WHEN validating THEN the command formatting all files is displayed")
public void test2() throws Exception {
mavenExecution()
.withCliOptions(goalCliOption("validate-code-format"))
.execute()
.assertLogText("Run 'mvn git-code-format:format-code' to format all the files.");
}

@MavenPluginTest
public void
GIVEN_bad_formatted_file_WHEN_adding_and_committing_it_THEN_it_should_have_correct_format()
throws Exception {
@DisplayName(
"GIVEN bad formatted file WHEN adding and committing it THEN it should have correct format")
public void test3() throws Exception {
mavenExecution()
.withCliOptions(goalCliOption("validate-code-format"))
.execute()
Expand All @@ -84,9 +86,9 @@ public void GIVEN_bad_formatted_files_WHEN_format_code_THEN_all_files_should_hav
}

@MavenPluginTest
public void
GIVEN_bad_formatted_generated_file_WHEN_formatting_THEN_generated_file_should_be_skipped()
throws Exception {
@DisplayName(
"GIVEN bad formatted generated file WHEN formatting THEN generated file should be skipped")
public void test4() throws Exception {
String generatedSourceFile =
Paths.get(mavenModuleDirectory)
.resolve("target/generated-sources/GeneratedBadFormat.java")
Expand All @@ -100,9 +102,10 @@ public void GIVEN_bad_formatted_files_WHEN_format_code_THEN_all_files_should_hav
}

@MavenPluginTest
public void
GIVEN_bad_formatted_files_WHEN_format_code_with_aosp_enabled_THEN_all_files_should_be_formatted_according_to_aosp()
throws Exception {
@DisplayName(
"GIVEN bad formatted files WHEN format code with aosp enabled THEN all files should be"
+ " formatted according to aosp")
public void test5() throws Exception {
mavenExecution()
.withCliOptions(goalCliOption("validate-code-format"), "-Daosp=true")
.execute()
Expand All @@ -125,8 +128,8 @@ public void GIVEN_bad_formatted_files_WHEN_format_code_THEN_all_files_should_hav
}

@MavenPluginTest
public void GIVEN_bad_formatted_file_WHEN_committing_all_THEN_it_should_have_correct_format()
throws Exception {
@DisplayName("GIVEN bad formatted file WHEN committing all THEN it should have correct format")
public void test6() throws Exception {
mavenExecution()
.withCliOptions(goalCliOption("validate-code-format"))
.execute()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.treewalk.TreeWalk;
import org.junit.jupiter.api.DisplayName;

/**
* Covers <a href="https://github.com/Cosium/git-code-format-maven-plugin/issues/227">issue 227</a>.
Expand All @@ -38,8 +39,9 @@ public AutoCrlfFileTest(MavenRuntime.MavenRuntimeBuilder mavenBuilder) throws Ex
}

@MavenPluginTest
public void GIVEN_auto_crlf_WHEN_committing_a_badly_formatted_file_THEN_it_is_not_left_modified()
throws Exception {
@DisplayName(
"GIVEN auto crlf WHEN committing a badly formatted file THEN it is not left modified")
public void test1() throws Exception {
enableAutoCrlf();
commitBaseline();

Expand Down
36 changes: 21 additions & 15 deletions core/src/test/java/com/cosium/code/format/EmptyCommitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.eclipse.jgit.api.MergeResult.MergeStatus;
import org.eclipse.jgit.api.errors.AbortedByHookException;
import org.eclipse.jgit.lib.ObjectId;
import org.junit.jupiter.api.DisplayName;

/**
* Covers <a href="https://github.com/Cosium/git-code-format-maven-plugin/issues/96">issue 96</a>.
Expand Down Expand Up @@ -48,9 +49,10 @@ public EmptyCommitTest(MavenRuntime.MavenRuntimeBuilder mavenBuilder) throws Exc
}

@MavenPluginTest
public void
GIVEN_default_options_WHEN_the_formatting_reverts_the_staged_change_THEN_git_creates_an_empty_commit()
throws Exception {
@DisplayName(
"GIVEN default options WHEN the formatting reverts the staged change THEN git creates an"
+ " empty commit")
public void test1() throws Exception {
commitBaseline();

installHooks(DO_NOT_FAIL_ON_EMPTY_COMMIT);
Expand All @@ -63,9 +65,10 @@ public EmptyCommitTest(MavenRuntime.MavenRuntimeBuilder mavenBuilder) throws Exc
}

@MavenPluginTest
public void
GIVEN_fail_on_empty_commit_WHEN_the_formatting_reverts_the_staged_change_THEN_the_commit_is_refused()
throws Exception {
@DisplayName(
"GIVEN fail on empty commit WHEN the formatting reverts the staged change THEN the commit is"
+ " refused")
public void test2() throws Exception {
commitBaseline();

installHooks(FAIL_ON_EMPTY_COMMIT);
Expand All @@ -81,9 +84,10 @@ public EmptyCommitTest(MavenRuntime.MavenRuntimeBuilder mavenBuilder) throws Exc
}

@MavenPluginTest
public void
GIVEN_fail_on_empty_commit_WHEN_the_staged_change_survives_the_formatting_THEN_the_commit_succeeds()
throws Exception {
@DisplayName(
"GIVEN fail on empty commit WHEN the staged change survives the formatting THEN the commit"
+ " succeeds")
public void test3() throws Exception {
commitBaseline();

installHooks(FAIL_ON_EMPTY_COMMIT);
Expand All @@ -109,9 +113,10 @@ public EmptyCommitTest(MavenRuntime.MavenRuntimeBuilder mavenBuilder) throws Exc
}

@MavenPluginTest
public void
GIVEN_fail_on_empty_commit_WHEN_only_a_deletion_survives_the_formatting_THEN_the_commit_succeeds()
throws Exception {
@DisplayName(
"GIVEN fail on empty commit WHEN only a deletion survives the formatting THEN the commit"
+ " succeeds")
public void test4() throws Exception {
write(OTHER_JAVA, OTHER_BASELINE);
jGit().add().addFilepattern(OTHER_JAVA).call();
commitBaseline();
Expand All @@ -131,9 +136,10 @@ public EmptyCommitTest(MavenRuntime.MavenRuntimeBuilder mavenBuilder) throws Exc
}

@MavenPluginTest
public void
GIVEN_fail_on_empty_commit_WHEN_the_formatting_reverts_the_merge_resolution_THEN_the_merge_commit_is_created()
throws Exception {
@DisplayName(
"GIVEN fail on empty commit WHEN the formatting reverts the merge resolution THEN the merge"
+ " commit is created")
public void test5() throws Exception {
commitBaseline();
String mainBranch = jGit().getRepository().getBranch();

Expand Down
35 changes: 19 additions & 16 deletions core/src/test/java/com/cosium/code/format/MavenWrapperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.junit.jupiter.api.DisplayName;

/**
* Covers <a href="https://github.com/Cosium/git-code-format-maven-plugin/issues/90">issue 90</a>.
Expand All @@ -34,8 +35,8 @@ public MavenWrapperTest(MavenRuntime.MavenRuntimeBuilder mavenBuilder) throws Ex
}

@MavenPluginTest
public void GIVEN_a_maven_wrapper_WHEN_installing_the_hooks_THEN_the_hook_runs_the_wrapper()
throws Exception {
@DisplayName("GIVEN a maven wrapper WHEN installing the hooks THEN the hook runs the wrapper")
public void test1() throws Exception {
Path wrapper = installMavenWrapper(projectRoot());

installHooks();
Expand All @@ -44,9 +45,10 @@ public void GIVEN_a_maven_wrapper_WHEN_installing_the_hooks_THEN_the_hook_runs_t
}

@MavenPluginTest
public void
GIVEN_a_maven_wrapper_in_a_parent_directory_WHEN_installing_the_hooks_THEN_the_hook_runs_the_wrapper()
throws Exception {
@DisplayName(
"GIVEN a maven wrapper in a parent directory WHEN installing the hooks THEN the hook runs the"
+ " wrapper")
public void test2() throws Exception {
// The build is run from the module, while the wrapper sits at the root of the repository.
Path wrapper = installMavenWrapper(projectRoot());
Path module = Files.createDirectories(projectRoot().resolve("module"));
Expand All @@ -58,18 +60,19 @@ public void GIVEN_a_maven_wrapper_WHEN_installing_the_hooks_THEN_the_hook_runs_t
}

@MavenPluginTest
public void
GIVEN_no_maven_wrapper_WHEN_installing_the_hooks_THEN_the_hook_runs_the_maven_installation()
throws Exception {
@DisplayName(
"GIVEN no maven wrapper WHEN installing the hooks THEN the hook runs the maven installation")
public void test3() throws Exception {
installHooks();

assertThat(readHookScript()).doesNotContain(MAVEN_WRAPPER);
}

@MavenPluginTest
public void
GIVEN_the_maven_wrapper_is_not_preferred_WHEN_installing_the_hooks_THEN_the_hook_runs_the_maven_installation()
throws Exception {
@DisplayName(
"GIVEN the maven wrapper is not preferred WHEN installing the hooks THEN the hook runs the"
+ " maven installation")
public void test4() throws Exception {
installMavenWrapper(projectRoot());

buildMavenExecution(projectRoot())
Expand All @@ -85,8 +88,8 @@ public void GIVEN_a_maven_wrapper_WHEN_installing_the_hooks_THEN_the_hook_runs_t
* the selected wrapper is something git can actually run.
*/
@MavenPluginTest
public void GIVEN_a_maven_wrapper_WHEN_committing_THEN_the_wrapper_formats_the_staged_file()
throws Exception {
@DisplayName("GIVEN a maven wrapper WHEN committing THEN the wrapper formats the staged file")
public void test5() throws Exception {
installMavenWrapper(projectRoot());

installHooks();
Expand All @@ -106,9 +109,9 @@ public void GIVEN_a_maven_wrapper_WHEN_committing_THEN_the_wrapper_formats_the_s
}

@MavenPluginTest
public void
GIVEN_a_maven_wrapper_WHEN_the_validation_fails_THEN_the_wrapper_is_the_command_to_run()
throws Exception {
@DisplayName(
"GIVEN a maven wrapper WHEN the validation fails THEN the wrapper is the command to run")
public void test6() throws Exception {
installMavenWrapper(projectRoot());

buildMavenExecution(projectRoot())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.treewalk.TreeWalk;
import org.junit.jupiter.api.DisplayName;

/**
* Covers <a href="https://github.com/Cosium/git-code-format-maven-plugin/issues/49">issue 49</a>,
Expand All @@ -33,9 +34,10 @@ public PartiallyStagedFileTest(MavenRuntime.MavenRuntimeBuilder mavenBuilder) th
}

@MavenPluginTest
public void
GIVEN_partially_staged_file_WHEN_committing_THEN_staged_lines_are_formatted_and_unstaged_changes_survive()
throws Exception {
@DisplayName(
"GIVEN partially staged file WHEN committing THEN staged lines are formatted and unstaged"
+ " changes survive")
public void test1() throws Exception {
String baseline =
"public class BadFormat {\n"
+ "\n"
Expand Down Expand Up @@ -77,9 +79,10 @@ public PartiallyStagedFileTest(MavenRuntime.MavenRuntimeBuilder mavenBuilder) th
}

@MavenPluginTest
public void
GIVEN_formatting_conflicting_with_unstaged_changes_WHEN_committing_THEN_the_commit_still_succeeds()
throws Exception {
@DisplayName(
"GIVEN formatting conflicting with unstaged changes WHEN committing THEN the commit still"
+ " succeeds")
public void test2() throws Exception {
String baseline = "public class BadFormat {\n" + "\n" + " void a() {}\n" + "}\n";
commitBaseline(baseline);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.Map;
import java.util.Set;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

Expand All @@ -37,7 +38,8 @@ public void beforeEach() {
}

@Test
public void testMavenHomeExecutable() {
@DisplayName("Maven home executable")
public void test1() {
systemProperties.put("maven.home", "/opt/maven");
Path expectedPath = Paths.get("/opt/maven/bin/mvn");
commandRunner.validExecutables.add(expectedPath.toString());
Expand All @@ -46,7 +48,8 @@ public void testMavenHomeExecutable() {
}

@Test
public void testMavenHomeDebugExecutable() {
@DisplayName("Maven home debug executable")
public void test2() {
systemProperties.put("maven.home", "/opt/maven");
Path expectedPath = Paths.get("/opt/maven/bin/mvnDebug");
commandRunner.validExecutables.add(expectedPath.toString());
Expand All @@ -55,15 +58,17 @@ public void testMavenHomeDebugExecutable() {
}

@Test
public void testMavenPathExecutableFallback() {
@DisplayName("Maven path executable fallback")
public void test3() {
systemProperties.put("maven.home", "/opt/maven");
commandRunner.validExecutables.add("mvn");
Path path = tested.select(false, false);
assertThat(path).isEqualTo(Paths.get("mvn"));
}

@Test
public void testMavenPathDebugExecutableFallback() {
@DisplayName("Maven path debug executable fallback")
public void test4() {
systemProperties.put("maven.home", "/opt/maven");
commandRunner.validExecutables.add("mvnDebug");
Path path = tested.select(true, false);
Expand Down
Loading