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.

100 questions
33
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…
16
votes
2 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
  • 3,535
  • 2
  • 26
  • 46
13
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,078
  • 3
  • 12
  • 30
7
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
  • 391
  • 1
  • 5
  • 18
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
  • 3,587
  • 7
  • 22
  • 30
6
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,134
  • 8
  • 37
  • 72
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
  • 2,853
  • 6
  • 33
  • 50
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
  • 441
  • 7
  • 17
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
  • 2,670
  • 6
  • 35
  • 53
4
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,356
  • 3
  • 39
  • 73
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…
4
votes
2 answers

Mock JmsTemplate for integration testing

Need to mock JmsTemplate for integration testing in my application. In my appcontext.xml
sp_user123
  • 490
  • 2
  • 6
  • 25
4
votes
2 answers

JUnit: Unable to mock the RestTemplate object to call postForObject method

I am new to Mockito as well as Spring's RestTemplate. I am working on JUnit tests for a functionality which sends a request to a web-service and gets the response through the use of RestTemplate. I want the server to respond with a response that i…
Ash Ash
  • 393
  • 4
  • 5
  • 15
4
votes
1 answer

@ReplaceWithMock not mocking using Springmockito-annotations

I have a class which I am trying unit test. I am trying to test it using Mockito, and to resolve the spring injection with mockito I am using Springockito and Springockito-annotations. @ContextConfiguration(loader =…
Xetius
  • 39,461
  • 24
  • 80
  • 118
3
votes
1 answer

PowerMockito calls real method on Mocked Object when defining second "when" clause

I am trying to define some different mocked behaviours when a method is called with different parameters. Unfortunately, I find that the second time I try to mock the given method on a (mocked) class, it runs the actual method, causing an exception…
Borzi
  • 351
  • 3
  • 15
1
2 3 4 5 6 7