0

I have a project I'm trying to unit test.

The tests run fine. The following code is a dummy test for brevity:

enum class QueryFilterOperator(val operator: String) {
    EQUAL("="),
    GREATER_THAN(">"),
    LOWER_THAN("<"),
    GREATER_THAN_OR_EQUAL(">="),
    LOWER_THAN_OR_EQUAL("<=");
}

class QueryFilterOperatorTest : StringSpec({
    "a query filter operator" {
        assertEquals("=", EQUAL.operator)
    }
})

But when trying to debug it using IntelliJ tooling, the compilation fails on some kapt generated code:

package com.wizy.data.contracts;

import java.lang.System;

@kotlin.Metadata(mv = {1, 1, 16}, bv = {1, 0, 3}, k = 1, d1 = {"\u0000\u0012\n\u0002\u0018\u0002\n\u0002\u0010\u0010\n\u0000\n\u0002\u0010\u000e\n\u0002\b\t\b\u0086\u0001\u0018\u00002\b\u0012\u0004\u0012\u00020\u00000\u0001B\u000f\b\u0002\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u00a2\u0006\u0002\u0010\u0004R\u0011\u0010\u0002\u001a\u00020\u0003\u00a2\u0006\b\n\u0000\u001a\u0004\b\u0005\u0010\u0006j\u0002\b\u0007j\u0002\b\bj\u0002\b\tj\u0002\b\nj\u0002\b\u000b\u00a8\u0006\f"}, d2 = {"Lcom/wizy/data/contracts/QueryFilterOperator;", "", "operator", "", "(Ljava/lang/String;ILjava/lang/String;)V", "getOperator", "()Ljava/lang/String;", "EQUAL", "GREATER_THAN", "LOWER_THAN", "GREATER_THAN_OR_EQUAL", "LOWER_THAN_OR_EQUAL", "data-contracts"})
public enum QueryFilterOperator {
    /*public static final*/ EQUAL /* = new EQUAL(null) */,
    /*public static final*/ GREATER_THAN /* = new GREATER_THAN(null) */,
    /*public static final*/ LOWER_THAN /* = new LOWER_THAN(null) */,
    /*public static final*/ GREATER_THAN_OR_EQUAL /* = new GREATER_THAN_OR_EQUAL(null) */,
    /*public static final*/ LOWER_THAN_OR_EQUAL /* = new LOWER_THAN_OR_EQUAL(null) */;
    @org.jetbrains.annotations.NotNull()
    private final java.lang.String operator = null;

    @org.jetbrains.annotations.NotNull()
    public final java.lang.String getOperator() {
        return null;
    }

    QueryFilterOperator(java.lang.String operator) {
    }
}

In this code, we can see that the enum constructors are not set correctly.

If I remove the constructor and try again (using an admittedly even dummier test), I can debug as intended.

enum class QueryFilterOperator {
    EQUAL,
    GREATER_THAN,
    LOWER_THAN,
    GREATER_THAN_OR_EQUAL,
    LOWER_THAN_OR_EQUAL;
}

class QueryFilterOperatorTest : StringSpec({
    "a query filter operator" {
        assertNotEquals(EQUAL, GREATER_THAN)
    }
})

Why is kapt behaving this way ? Why does it complain only when debugging? Why does it even generate this obviously incorrect java code?

Here is the kapt configuration in the POM:

<plugin>
    <groupId>org.jetbrains.kotlin</groupId>
    <artifactId>kotlin-maven-plugin</artifactId>
    <version>1.3.61</version>
    <executions>
        <execution>
            <id>kapt</id>
            <goals>
                <goal>kapt</goal>
            </goals>
            <configuration>
                <sourceDirs>
                    <sourceDir>src/main/java</sourceDir>
                </sourceDirs>
                <annotationProcessorPaths/>
            </configuration>
        </execution>
        <execution>
            <id>compile</id>
            <phase>process-sources</phase>
            <goals>
                <goal>compile</goal>
            </goals>
            <configuration>
                <sourceDirs>
                    <source>${basedir}/src/main/java</source>
                    <source>${basedir}/target/generated-sources/annotations</source>
                </sourceDirs>
            </configuration>
        </execution>
        <execution>
            <id>test-compile</id>
            <phase>test-compile</phase>
            <goals>
                <goal>test-compile</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <jvmTarget>1.8</jvmTarget>
    </configuration>
</plugin>
xlecoustillier
  • 16,183
  • 14
  • 60
  • 85

1 Answers1

0

Hmm, after wiping out every IntelliJ project files (*.iml files and .idea directory), everything is running fine, even in debug.

xlecoustillier
  • 16,183
  • 14
  • 60
  • 85