Reputation: 339
Weird behavior. I've got a vanilla spring boot project I made with initializr. The build.gradle
is below and as you can see it loaded up the test dependency for spring boot starter test, which includes the assertj package.
plugins {
id 'org.springframework.boot' version '2.5.4'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.acme'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-webflux'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.projectreactor:reactor-test'
}
test {
useJUnitPlatform()
}
However, I have my first test component here
package com.foretold.astrocalc.app.controllers;
import org.assertj.core.api.Assertions.assertThat;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
public class ChartControllerTest {
@Autowired
private ChartController controller;
@Test
public void contextLoads() throws Exception{
assertThat(controller).isNotNull();
}
}
And IJ is telling me that it cannot resolve the symbol assertThat. It loads up to Assertions
in the import statement and that's in. When I click into the Assertions
class I see the public method assertThat
. Is there some IJ setting that's screwing up the static import?
It does work to just import Assertions
and use the method with dot notation, but why won't the static import work?
Upvotes: 1
Views: 5628
Reputation: 102
When we want to write assertions in AssertJ, we have to use static assertThat method instead. This means that you have to import it like following instead:
import static org.assertj.core.api.Assertions.assertThat;
Upvotes: 4