Skip to content

Commit

Permalink
Adds test for switch with arrow
Browse files Browse the repository at this point in the history
  • Loading branch information
caesar-ralf committed Oct 6, 2023
1 parent 01671e2 commit 1af2f00
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/test/java/com/spotify/fmt/FMTTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/switchwitharrows/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:format
29 changes: 29 additions & 0 deletions src/test/resources/switchwitharrows/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.apache.maven.plugin.my.unit</groupId>
<artifactId>project-to-test</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<name>Test MyMojo</name>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>









Original file line number Diff line number Diff line change
@@ -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;
};
}
}

0 comments on commit 1af2f00

Please sign in to comment.