Skip to content

Commit

Permalink
🧪 minimal jqwik-kotlin npe example jqwik-team/jqwik#557
Browse files Browse the repository at this point in the history
  • Loading branch information
twentylemon committed Mar 11, 2024
0 parents commit 5c19f60
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 0 deletions.
141 changes: 141 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<?xml version="1.0" encoding="UTF-8"?>
<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.example</groupId>
<artifactId>jqwik-kotlin-npe</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<maven-surefire-plugin.version>3.2.2</maven-surefire-plugin.version>
<junit-bom.version>5.10.1</junit-bom.version>
<jqwik.version>1.8.1</jqwik.version>
<kotlin.version>1.9.22</kotlin.version>
</properties>

<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit-bom.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.jqwik</groupId>
<artifactId>jqwik</artifactId>
<version>${jqwik.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.jqwik</groupId>
<artifactId>jqwik-kotlin</artifactId>
<version>${jqwik.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<!-- https://kotlinlang.org/docs/maven.html#compile-kotlin-and-java-sources -->
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<extensions>true</extensions>
<configuration>
<args>
<arg>-java-parameters</arg> <!-- Get correct parameter names in jqwik reporting -->
<arg>-Xjsr305=strict</arg> <!-- Strict interpretation of nullability annotations in jqwik API -->
<arg>-Xemit-jvm-type-annotations</arg> <!-- Enable annotations on type variables -->
</args>
</configuration>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-lombok</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>compile</id>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/main/java</sourceDir>
</sourceDirs>
</configuration>
</execution>
<execution>
<id>test-compile</id>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/test/java</sourceDir>
</sourceDirs>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<compilerArgs>
<arg>-parameters
</arg> <!-- required if you want to report source code names of property method parameters -->
</compilerArgs>
</configuration>
<executions>
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>java-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>java-test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
<exclude>**/*ITest.java</exclude>
</excludes>
<forkCount>1</forkCount>
</configuration>
</plugin>
</plugins>
</build>

</project>
5 changes: 5 additions & 0 deletions src/main/java/Foo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class Foo {
public String foo() {
return "foo";
}
}
3 changes: 3 additions & 0 deletions src/main/kotlin/Bar.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Bar {
fun bar() = "bar"
}
20 changes: 20 additions & 0 deletions src/test/java/FooTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import net.jqwik.api.Arbitrary;
import net.jqwik.api.ForAll;
import net.jqwik.api.Property;
import net.jqwik.api.Provide;

import java.util.Set;

class FooTest {

@Property
void foo(@ForAll("arb") Set<Integer> i) {
System.out.println(i);
}

@Provide
Arbitrary<Set<Integer>> arb() {
return ArbKt.arb();
}

}
5 changes: 5 additions & 0 deletions src/test/kotlin/Arb.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import net.jqwik.api.Arbitraries
import net.jqwik.api.Arbitrary
import net.jqwik.kotlin.api.ofSize

fun arb(): Arbitrary<Set<Int>> = Arbitraries.integers().set().ofSize(2..5)

0 comments on commit 5c19f60

Please sign in to comment.