【问题标题】:Cannot find symbol symbol method of() location interface java.util.list, unittests找不到符号符号方法 of() 位置接口 java.util.list,单元测试
【发布时间】:2020-10-31 13:48:43
【问题描述】:

我目前正在开发一个 Spring Boot 应用程序,我现在正在编写单元测试。但是当我运行命令'mvn test'时,我收到以下错误:

这是代码

BoardServiceTest.java

@Test
public void testGetBoards() {
    Set<Lists> list =  new HashSet<Lists>();
    
    List<Board> expectedBoards = List.of(
        new Board(1, "Studie", list),
        new Board(2, "Todo Applicatie", list)
    );
    
    when(this.boardRepo.findAll()).thenReturn(expectedBoards);
    
    var receivedBoards = this.boardService.getBoards();
    assertEquals(expectedBoards, receivedBoards);
    verify(this.boardRepo, times(1)).findAll();
}

ListsServiceTest.java

@Test
public void testGetLists() throws Exception {   
    int boardId = 1;
    Set<Task> task = new HashSet<>();

    List<Lists> expectedLists = List.of(
        new Lists(1, "registered", new Board(), task),
        new Lists(2, "open", new Board(), task)
    );
    
    when(this.listRepository.findAll()).thenReturn(expectedLists);
    
    var receivedLists = this.listService.getLists(boardId);
    
    assertEquals(expectedLists, receivedLists);
    verify(this.listRepository, times(1)).findAll();
}

【问题讨论】:

  • 以后请不要发布错误信息的截图,而是将错误信息本身作为文本发布。
  • @JoachimSauer 我现在没有这样做,但我无法复制完整的错误。这就是我截屏的原因。但我以后不会这样做了

标签: java list spring-boot


【解决方案1】:

List.of 已添加到Java 9,您需要确保使用 JDK 9+ 来编译源代码,并且在 maven pom.xml 中设置了适当的 java 版本。

【讨论】:

  • 感谢您的评论。我在 pom.xml 中看到我使用 java 1.8。我会更新的
猜你喜欢
  • 2011-08-12
  • 2019-04-03
  • 2023-03-24
  • 2019-05-31
  • 1970-01-01
  • 1970-01-01
  • 2015-02-03
  • 2015-01-19
  • 2021-05-21
相关资源
最近更新 更多