How to make fun of the object that creates in the test method?

I have ContextListener which inject in ServletContext object for work with database. And this DBJoint object create in method which test: @WebListener public class ContextListener implements ServletContextListener { @Override public void contextIniti

Make fun of an abstract method, but not the class builder

I have a scenario where I have an abstract class similar to the below. I want to mock out the RandomNumberGenerator instance that is supplied via the constructor and I want to write a unit test to test the logic in the doSomethingRandomLotsOfTimes me

JUnit Mockito SpringMVC 404

while testing spring mvc controller with JUnit and Mockito got this line WARNING: No mapping found for HTTP request with URI [application] in DispatcherServlet with name '' Does that mean that DispatcherServlet was not loaded? How to configure it pro

Mockito - how to respond with a custom object

Trying to test the construction like this: @RequestMapping(value = "/test", method = POST) public ResponseEntity test(@RequestBody TestRequest request, Errors errors) { testValidator.validate(request, errors); // Spring Validator interface impl

Start the cucumber test with Mockito

I'm trying to run a JUnit Cucumber test that uses Mockito. Here's the issue I'm running into. In my Cucumber Runner class, I have @RunWith(Cucumber.class) And in my regular JUnit tests I have @RunWith(Mockito.class) Given that I can only have one @Ru

How to call Mockito.given with private method

I found my method using ReflectionUtils Method myMethod=ReflectionUtils.findMethod(myMockClass.getClass(), "myMethod", myArg.class) Now I would like to drive this method to return a specified value. Normally, if myMethod would be public I would

Android unit test with Retrofit2 and Mockito or Robolectric

Can I test real response from retrofit2beta4? Do i need Mockito or Robolectic? I don't have activities in my project, it will be a library and I need to test is server responding correctly. Now I have such code and stuck... @Mock ApiManager apiManage

URL testing and URLConnection

I don't know how should I test this without really taking connection to real url to server. I have read few articles about using Mockito in this kind of situation and tried to search around, but can not find good tutorial or advices how should I make

mockito can not match the overloaded method

I am trying to mock a SimpleDateFormat object but Mockito says I have the wrong number of args. Code: SimpleDateFormat spyDateFormat = spy(new SimpleDateFormat(DateFormatManager.MAIN_ACTIVITY_TITLE_FORMAT)); // exception points to below line when(spy

Mockito servlet test: can not use answer - it is not engaged

I've made a basic test for servlet to test it's response status code, but it doesn't work - it's always 0, although I've set the response status code inside the servlet to 200. public class TestMyServlet extends Mockito { @Test public void test() thr

Mocking method getJdbcTemplate

My scenario is as below: I have no setter methods in SampleDao interface and no direct field in SampleDaoImpl class reference: How to mock getJdbcTemplate().queryForObject()? public interface SampleDao { // some methods } public class SampleDaoImpl e

How to call put method in REST assured

I have a put method that accepts inputstream. I want to call this method using rest assured in JUnit. This is what I used: with().body(inpustream).put("/service/1"); // i got error 404 forbidden. Actually, you are doing well but sending multipar

Why can not I use Mock and InjectMocks together?

valid construction: @InjectMocks SomeClass sc = mock(SomeClass.class); Invalid construction: @InjectMocks @Mock SomeClass sc; I want to inject mocks to another mock. I want to use only annotation style. Why was in Mockito forbid second construction ?

Mockito does not allow Matchers.any () with Integer.class

I am trying to unit test this method: /** * finds all widget descriptions containing specified text * @param searchText * @return */ @Transactional public List<Integer> returnWidgetIdsFromSearchWord(String searchText){ List<Integer> widgetIds

Mockito - Creating Nested Nested Objects

I'm learning Mockito. I am facing problem while creating mock for nested objects. See public interface BaseManager { public Query createQuery(String queryString); } and an implementation class for that public class BaseManagerImpl implements BaseMana

Unable to mock Glassfish Jersey Customer Response Item

I am having problems with creating a mock Response object to use with my unit tests. I am using org.glassfish.jersey.core.jersey-client version 2.3.1 to implement my RESTful client and mockito version 1.9.5 to help me with mock objects. Here is my te

How to find the methods in the Java API in Eclipse

I started to use Mockito, but when i call a method like when(); Eclipse didnĀ“t show me the import class option, so, i was wondering if Eclipse have a way to search the methods in jar and know wich i can import. I know in Delphi we can find, typing th

Refactoring to write & ldquo; pretty & rdquo; JUnit tests

I want to clarify refactoring in scope of TDD. Before: class Somclass{ public void sendMessage(){ WebServiceStub stub = new WebServiceStub(); ... stub.sendMsg(); } } After: class Somclass{ private WebServiceStub stub; public void sendMessage(){ ... i

Mockito simulacra of SecurityManager throwing an exception

I'm trying to mock the SecurityManager class. When I run the following code, Mockito throws an exception: @After public void tearDown() { SecurityManager securityManagerMock = mock(SecurityManager.class); System.setSecurityManager(securityManagerMock