-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#148] added tests for sealed classes feature
- Loading branch information
1 parent
5c043c5
commit e12d17a
Showing
3 changed files
with
175 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
68 changes: 68 additions & 0 deletions
68
integrationtest/java17/src/test/java/io/toolisticon/aptk/tools/wrapper/Java17Tests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters