генерировать исключение NoUniqueBeanDefinitionException при использовании @SpyBean в @SpringBootTest

Я использую Spring Boot 1.5.7. Я пытаюсь использовать @SpyBean в @SpringBootTest, но все еще получаю исключение NoUniqueBeanDefinitionException.

@MockBean в порядке с @SpringBootTest, @SpyBean происходит Вот код, который мы тестировали:

@RunWith (SpringRunner.class)
@SpringBootTest
public class CustomerServiceSpyTest {

    @Autowired
    private CustomerService customerService;

    @MockBean (name = "customerOrderRepository")
    private CustomerOrderRepository customerOrderRepository;

    @SpyBean (name = "httpSession")
    private HttpSession httpSession;

    @Test
    public void saveMyOrderProductCountInSession () throws Exception {

        // given
        Customer customer = new Customer ();

        given (httpSession.getAttribute ("loginUser"))
                .willReturn (customer);

        CustomerOrder order = new CustomerOrder ();
        order.addProduct (new Product ());
        order.addProduct (new Product ());

        given (customerOrderRepository.findAllByCustomer (customer))
                .willReturn (Stream.of (order));

        // when
        customerService.saveMyOrderProductCountInSession ();
        int count = (Integer) httpSession.getAttribute ("orderCount");

        // then
        assertThat (count, is (2));
    }
}

person jojoldu    schedule 22.09.2017    source источник
comment
См. stackoverflow.com/questions/ 22707031/   -  person Plog    schedule 22.09.2017
comment
Ух ты! Спасибо!   -  person jojoldu    schedule 23.09.2017