Org.mockito.exceptions.misusing.MissingMethodInvocationException:什么错了?

时间:2017-10-09 20:34:59

标签: java spring

我为此测试收到此错误,我的代码出了什么问题?我该怎么做才能理解这个问题

content-type

错误的完整错误说明,您有什么建议?

 @InjectMocks
        BookController controller;

        @Mock
        BookService bookService;  // will be inject to BookController

        MockMvc mockMvc;

        @Mock
        View mockView;

        @Before
        public void setUp() throws Exception {
            new BookController(bookService);
            MockitoAnnotations.initMocks(this);
            mockMvc = standaloneSetup(controller)
                    .setSingleView(mockView)
                    .build();
        }


        @Test
        public void showBookListPage() throws Exception {
            securityService.autologin("admin","admin");
            List<Book> expectedBookList =  new  ArrayList <Book>();
            BookService bookService = mock(BookService.class);
            when(bookService.findAll()).thenReturn(expectedBookList);

             mockMvc.perform(get(" /book/bookList"))
                    .andExpect(view().name("bookList"))
                    .andExpect(model().attributeExists("bookList"))
                    .andExpect(model().attribute("bookList", hasItems(expectedBookList.toArray())));
        }

一切似乎都正确,但我总是得到这个错误

0 个答案:

没有答案