我正在嘗試學習關于 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);
}
}
uj5u.com熱心網友回復:
確保靜態匯入使用的斷言方法:
import static org.assertj.core.api.Assertions.assertThat;
請注意,assertj 依賴項也需要存在,因此通過 gradle 宣告它: testImplementation("org.assertj:assertj-core:3.22.0")
https://assertj.github.io/doc/
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/403737.html
標籤:
