0

I'm using lombok in my code to generate some getters so nothing out of the ordinary. I initially planned to test some custom annotations of mine, but before I get the chance to do that, lombok is making some problems.

I simplified my code to reproduce the error, this is the setup that I ended with, and which doen't work.

I have this Class that I want to test:

import lombok.Getter;

public class ExampleModelClass {
    @Getter
    private final String exampleStringField = "default value";
}

I want the to test the contents of the exampleStringField, so I started with a failing test:

import borg.locutus.bukkitutils.test.utils.ExampleModelClass;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;


public class SqlAnnotationTest {

    @Test
    public void FieldContentTest() {
        ExampleModelClass model = new ExampleModelClass();

        assertEquals(model.getExampleStringField(), "not the default value");
    }
}

In my normal jar the getter generated by lombok works fine, so I am 100% sure that the code would actually work, but junit seems not to accept it. I keep getting a cannot find symbol error for the model.getExampleStringField(). I guess lombok is not being executed when my tests run, but I'd really like to change that. I'm using IntelliJ Ultimate 2020 and Maven.

monamona
  • 1,195
  • 2
  • 17
  • 43
  • How is Lombok configured in your project? I have a Lombok `provided` dependency in my `pom.xml` and it works totally fine for any Maven phase in the build. Also, there is an aux Lombok plugin for IntelliJ IDEA. Do you probably have Lombok IDEA plugin installed only? – terrorrussia-keeps-killing Dec 24 '20 at 07:38
  • What version of java are you running? How are you running the tests? Through maven or intellij? – Zack Dec 24 '20 at 07:39
  • I included as a dependency in my pom.xml with `provided` , and I'm using lombok 1.18.12, and junit 5.7.0 – monamona Dec 24 '20 at 07:40
  • I'm using the `Lifecycle` test option in the maven panel of intellij to run my tests. I'm using Java 8. – monamona Dec 24 '20 at 07:43
  • @monamona Does `mvn clean test` in your terminal, not in IntelliJ, pass the tests? – terrorrussia-keeps-killing Dec 24 '20 at 07:44
  • It seems I dont have maven installed like that, my terminal can't find `mvn` ... I always just used it via IntelliJ. – monamona Dec 24 '20 at 07:49
  • @monamona I doubt that IntelliJ IDEA is supplied with a broken Maven bundle or whatever that prevents Maven to work properly (additionally, it's not yet clear how your `pom.xml` looks like), but, unlike your way, I always use a standalone Apache Maven installation, and I build artifacts using it, never with IntelliJ. What if you install the latest Maven (simply unzip it somewhere, specify the `M2_HOME` env var, and add the `$M2_HOME/bin` dir to `PATH`) and try to make a clean double-check with it? – terrorrussia-keeps-killing Dec 24 '20 at 08:00
  • Look at the duplicate question. You need to enable the annotation processor and install the lombok plugin. - https://projectlombok.org/setup/intellij – Augusto Dec 24 '20 at 09:24
  • Both is enabled and installed, it still doesn't work. Lombok itself does work, just junit doesn't get the generated methods when testing. I consider it a separate issue, could you please reopen the question? :o – monamona Dec 24 '20 at 09:49
  • @monamona It's sort of strange. In Apache Maven and its default phases and goals, the classes that are compiled during the `compile` phase and then tested in the `test` phase (see the `./target` directory). Your build seem to fail at `test-compile` phase. Can you provide both `pom.xml` and the exact error you're getting? – terrorrussia-keeps-killing Dec 24 '20 at 14:56

0 Answers0