From 1af2f0045936f95045a81c63f8f8abee2d24aa37 Mon Sep 17 00:00:00 2001 From: Caesar Ralf Date: Fri, 6 Oct 2023 16:56:30 +0200 Subject: [PATCH] Adds test for switch with arrow --- src/test/java/com/spotify/fmt/FMTTest.java | 13 +++++++-- .../switchwitharrows/invoker.properties | 1 + src/test/resources/switchwitharrows/pom.xml | 29 +++++++++++++++++++ .../main/java/com.spotify.fmt.test/Main.java | 13 +++++++++ 4 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 src/test/resources/switchwitharrows/invoker.properties create mode 100644 src/test/resources/switchwitharrows/pom.xml create mode 100644 src/test/resources/switchwitharrows/src/main/java/com.spotify.fmt.test/Main.java diff --git a/src/test/java/com/spotify/fmt/FMTTest.java b/src/test/java/com/spotify/fmt/FMTTest.java index 79c69ab..d8dd4e0 100644 --- a/src/test/java/com/spotify/fmt/FMTTest.java +++ b/src/test/java/com/spotify/fmt/FMTTest.java @@ -43,8 +43,8 @@ import org.mockito.Mockito; public class FMTTest { - private static String FORMAT = "format"; - private static String CHECK = "check"; + private static final String FORMAT = "format"; + private static final String CHECK = "check"; @Rule public MojoRule mojoRule = new MojoRule(); @@ -205,6 +205,15 @@ public void unsupportedForkMode() throws Exception { assertThat(fmt.getResult().processedFiles()).hasSize(1); } + @Test + public void switchWithArrows() throws Exception { + FMT fmt = loadMojo("switchwitharrows", FORMAT); + + fmt.execute(); + + assertThat(fmt.getResult().processedFiles()).hasSize(1); + } + @Test(expected = MojoFailureException.class) public void validateOnlyFailsWhenNotFormatted() throws Exception { Check check = loadMojo("validateonly_notformatted", CHECK); diff --git a/src/test/resources/switchwitharrows/invoker.properties b/src/test/resources/switchwitharrows/invoker.properties new file mode 100644 index 0000000..908e5e3 --- /dev/null +++ b/src/test/resources/switchwitharrows/invoker.properties @@ -0,0 +1 @@ +invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:format diff --git a/src/test/resources/switchwitharrows/pom.xml b/src/test/resources/switchwitharrows/pom.xml new file mode 100644 index 0000000..1e445a2 --- /dev/null +++ b/src/test/resources/switchwitharrows/pom.xml @@ -0,0 +1,29 @@ + + 4.0.0 + + org.apache.maven.plugin.my.unit + project-to-test + 1.0.0 + jar + Test MyMojo + + + + junit + junit + 4.13.1 + test + + + + + + + + + + + + diff --git a/src/test/resources/switchwitharrows/src/main/java/com.spotify.fmt.test/Main.java b/src/test/resources/switchwitharrows/src/main/java/com.spotify.fmt.test/Main.java new file mode 100644 index 0000000..12fa4af --- /dev/null +++ b/src/test/resources/switchwitharrows/src/main/java/com.spotify.fmt.test/Main.java @@ -0,0 +1,13 @@ +package com.spotify.fmt.test; + +public class Main { + public static void main(String[] args) { + var test = "a"; + var result = + switch (test) { + case "videos" -> null; + case "images" -> null; + default -> null; + }; + } +}