Skip to content
Advertisement

Tag: mockito

Mockito: Trying to spy on method is calling the original method

I’m using Mockito 1.9.0. I want mock the behaviour for a single method of a class in a JUnit test, so I have The problem is, in the second line, myClassSpy.method1() is actually getting called, resulting in an exception. The only reason I’m using mocks is so that later, whenever myClassSpy.method1() is called, the real method won’t be called and

Spring value injection in mockito

I’m trying to write test class for the following method I’m using the injected url value in one of the methods in the class. To test this i’ve written a junit class In applicationContext-test.xml I’m loading the property file using But the url value is not getting loaded in the CustomService on running the test. I was wondering if there

Testing Private method using mockito

How to test private method is called or not, and how to test private method using mockito? Answer You can’t do that with Mockito but you can use Powermock to extend Mockito and mock private methods. Powermock supports Mockito. Here’s an example.

Mockito/PowerMock: how to reset a mocked static variable in SUT?

I hate to introduce Unit-tests into a legacy code base, but I have to. Up untill now I successfully introduced unit-testing into the legacy code base using Mockito and PowerMock. Worked perfectly well until I met with this situation: in the SUT, there’re several static varibles (which I mocked with the help of PowerMock, mocking static methods and mocking constructors).

Using Mockito’s generic “any()” method

I have an interface with a method that expects an array of Foo: I am mocking this interface using Mockito, and I’d like to assert that doStuff() is called, but I don’t want to validate what argument are passed – “don’t care”. How do I write the following code using any(), the generic method, instead of anyObject()? Answer Since Java

Advertisement