Skip to content

Commit

Permalink
[#148] added tests for sealed classes feature
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasstamann committed Apr 11, 2024
1 parent fbdd751 commit e731e07
Show file tree
Hide file tree
Showing 3 changed files with 175 additions and 0 deletions.
94 changes: 94 additions & 0 deletions integrationtest/java17/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<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>

<artifactId>aptk-tools-java17</artifactId>
<packaging>jar</packaging>

<parent>
<groupId>io.toolisticon.aptk</groupId>
<artifactId>integrationtest-parent</artifactId>
<version>0.24.1-148_records-SNAPSHOT</version>
</parent>

<name>aptk-tools-java17</name>


<dependencies>

<dependency>
<groupId>io.toolisticon.aptk</groupId>
<artifactId>aptk-tools</artifactId>
</dependency>

</dependencies>


<build>

<plugins>

<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<executions>
<execution>
<id>enforce</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>[3.0.4,)</version>
</requireMavenVersion>
<requireJavaVersion>
<version>9</version>
</requireJavaVersion>
<bannedDependencies>
<searchTransitive>false</searchTransitive>
<excludes>
<exclude>*</exclude>
</excludes>
<includes>
<include>io.toolisticon.aptk:aptk-tools:*</include>
<include>*:*:*:*:test:*</include>
<include>*:*:*:*:provided:*</include>
</includes>
</bannedDependencies>
</rules>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>16</source>
<target>16</target>
</configuration>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>


</plugins>


</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package io.toolisticon.aptk.tools.wrapper;

import io.toolisticon.aptk.common.ToolingProvider;
import io.toolisticon.cute.Cute;
import io.toolisticon.cute.PassIn;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;

import javax.lang.model.element.TypeElement;
import java.util.stream.Collectors;

public class Java17Tests {


@Test
public void test_sealedClassesFeature_unsealed() {
Cute.unitTest().when().passInElement().<TypeElement>fromClass(Java17Tests.class).intoUnitTest((processingEnvironment, element) -> {
try {
ToolingProvider.setTooling(processingEnvironment);

TypeElementWrapper elementWrapper = TypeElementWrapper.wrap(element);

MatcherAssert.assertThat(elementWrapper.getPermittedSubclasses(), Matchers.empty());
MatcherAssert.assertThat(element.getPermittedSubclasses(), Matchers.empty());

} finally {
ToolingProvider.clearTooling();
}

}).thenExpectThat().compilationSucceeds().executeTest();

}



static final class AllowedClass extends SealedClass {

}

@PassIn
static sealed class SealedClass permits AllowedClass{

}



@Test
public void test_sealedClassesFeature_sealed() {
Cute.unitTest().when().passInElement().<TypeElement>fromClass(SealedClass.class).intoUnitTest((processingEnvironment, element) -> {
try {
ToolingProvider.setTooling(processingEnvironment);

TypeElementWrapper elementWrapper = TypeElementWrapper.wrap(element);

MatcherAssert.assertThat(elementWrapper.getPermittedSubclasses().stream().map(e -> e.getQualifiedName()).collect(Collectors.toSet()), Matchers.contains(SealedClass.class.getCanonicalName()));
MatcherAssert.assertThat(element.getPermittedSubclasses().stream().map(e -> e.toString()).collect(Collectors.toSet()), , Matchers.contains(SealedClass.class.getCanonicalName()));

} finally {
ToolingProvider.clearTooling();
}

}).thenExpectThat().compilationSucceeds().executeTest();

}


}
13 changes: 13 additions & 0 deletions integrationtest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@
</modules>

</profile>
<profile>
<id>java-17</id>
<activation>
<jdk>[17,)</jdk>
</activation>

<modules>
<module>java9</module>
<module>java16</module>
<module>java17</module>
</modules>

</profile>
</profiles>

</project>

0 comments on commit e731e07

Please sign in to comment.