Questions tagged [springmockito]

Springockito is a small extension to spring that simplifies the creation of mockito mocks in the intergation tests' related context xml files.

Springockito is a small extension to spring that simplifies the creation of mockito mocks in the intergation tests' related context xml files.

140 questions
40
votes
3 answers

Mockito.any() for

I want to mock a method with signature as: public T documentToPojo(Document mongoDoc, Class clazz) I mock it as below: Mockito.when(mongoUtil.documentToPojo(Mockito.any(Document.class), Mockito.any(WorkItemDTO.class))) But I get error…
Rajesh Kolhapure
  • 741
  • 1
  • 10
  • 21
23
votes
3 answers

Using @MockBean in tests forces reloading of Application Context

I have several integration tests running on Spring Framework that extend the base class called BaseITCase. Like this: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = {AppCacheConfiguration.class, TestConfiguration.class},…
dvelopp
  • 4,095
  • 3
  • 31
  • 57
14
votes
1 answer

Spring MVC Controller Exception Test

I have the following code @RequestMapping(value = "admin/category/edit/{id}",method = RequestMethod.GET) public String editForm(Model model,@PathVariable Long id) throws NotFoundException{ Category category=categoryService.findOne(id); …
Agung Setiawan
  • 1,134
  • 3
  • 13
  • 32
11
votes
1 answer

When to use and not use @Mock annotation, @MockBean annotation, @InjectMock annotation & @Autowired annotation in a spring webflux reactive project

Can you please explain when to use below annotations and when not to use those. I am pretty new to testing frameworks and confused with all the answers in the web. @Mock private Resource resource; @MockBean private Resource…
11
votes
1 answer

How can you possibly write test case for boolean in mockito, spring mvc environment

How can I possibly write test case for boolean in mockito, spring mvc environment For e.g, like the following response MockHttpServletResponse: Status = 200 Error message = null Headers =…
yas
  • 486
  • 1
  • 8
  • 23
8
votes
1 answer

JUnit testing: Difference between never() and times(0)

I just want to know that what is the difference between times(0) and never() in JUnit testing. For example I have the test line code for saving data in mongoDB: verify(mockRepository,never()).save(any(User.class)); if I write it as:…
Shahzeb Khan
  • 3,582
  • 8
  • 45
  • 79
6
votes
1 answer

How to use Spring WithMockUser annotation with TestNG

I am using Spring Boot for my web app and TestNG for unit testing. Following is the unit test I'm trying @ContextConfiguration public class AuthorizerTest extends AbstractTestNGSpringContextTests { @InjectMocks private Authorizer authorizer…
TechCrunch
  • 2,924
  • 5
  • 45
  • 79
6
votes
5 answers

How to mock JdbcTemplate.queryForObject() method

My method looks like this: public class Decompile extends JdbcDaoSupport public void getRunner(){ String val = this.getJdbcTemplate().queryForObject(sql,String.class, new Object[]{1001}); } } Please suggest how I would mock this.
buttowski
  • 4,657
  • 8
  • 27
  • 33
5
votes
1 answer

@SpyBean and Mockito.any() during verify

I'm experiencing following problem. I've got a spring boot test, where I inject and spy the mongoDbChannel bean. Then I try to start the normal workflow and verify if the method send is called on the…
Roman T
  • 1,400
  • 5
  • 18
  • 31
5
votes
0 answers

Can't run Spring unti test, NoSuchMethodError createLinkedMapIfPossible

I'm trying to run a unit test against a Spring Controller: @RunWith (SpringJUnit4ClassRunner.class) @WebAppConfiguration @ContextConfiguration ({"classpath*:WEB-INF/spring/app-config.xml", "classpath*:WEB-INF/spring/mvc-config.xml", …
Greg Dougherty
  • 3,281
  • 8
  • 35
  • 58
5
votes
2 answers

Springockito how to?

I want to mock DAO bean using Springockito in one of my IT. In my IT I have to use spring context.xml to autowire some services and also mockApplication.xml to mock the DAOs. So, how can I use both the xml configuration files at the same…
Rajib Deka
  • 551
  • 1
  • 7
  • 22
5
votes
1 answer

How to test ehcache using mockito?

Im helper method use ehcache, to reduce queries to Db. Now want to implement JUnit+Mockito test to ensure that ehcache works properly. Have such variant of test: @Autowired private DBService service; @Autowired private DiscountHelper…
sphinks
  • 3,048
  • 8
  • 39
  • 55
4
votes
1 answer

I can't autowire Service class in Spring Boot Test

I created Dao Repository that uses jdbc for working with DB. I autowired this repository in my Service class. Then I try to autowire my service class in my test class. @SpringBootTest public class ServiceTest { @MockBean private Dao dao; …
4
votes
2 answers

How to use the mapper created by Mapstruct as @Mock during testing

The context I have a simple test method testFindByUserName. I use mockito library. I have @Mock UserMapper which is created by Mapstruct library. The problem Mocito doesn't handle Static method INSTANCE which I use to mapping user to userDto. I have…
John Wind
  • 69
  • 2
  • 7
4
votes
1 answer

End to End Test case for Spring batch job

I'm having an application where i'm using spring batch. I want to write a test case which can test the batch job end to end. I have been exploring various options for the same. I checked if concordion test cases can be useful but i'm not sure if…
ATR
  • 2,160
  • 4
  • 22
  • 43
1
2 3
9 10