我正在尝试学习 JPA 上的复数视觉演示课程,而我刚刚构建的测试在 assertThat 方法上抛出了一个错误,我不知道为什么。我确信这非常明显,但我在这里或 java 文档示例中找不到解决方案。请在新的一年里提供帮助。
错误信息
The method assertThat(List<Flight>) is undefined for the type SpringDataOverviewApplicationTestsJava(67108964)
编码
package com.pluralsight.springdataoverview;
import java.time.LocalDateTime;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;
import com.pluralsight.springdataoverview.entity.Flight;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.context.SpringBootTest;
@DataJpaTest
class SpringDataOverviewApplicationTests {
@Autowired
private EntityManager entityManager;
@Test
public void verifyFlightCanBeSaved() {
final Flight flight = new Flight();
flight.setOrigin("Amsterdam");
flight.setDestination("New york");
flight.setScheduledAt(LocalDateTime.parse("2011-12-13T12:12:00"));
entityManager.persist(flight);
final TypedQuery<Flight> results = entityManager
.createQuery("SELECT f FROM Flight f", Flight.class);
final List<Flight> resultList = results.getResultList();
assertThat(resultList)
.hasSize(1)
.first()
.isEqualTo(flight);
}
}