mockito Questions
3
I want to use testng + powermock + spring to run test code,my jar version is:
powermock = 1.6.2
powermock-module-testng = 1.6.2
mockito = 1.10.19
testng = 6.8.7
spring = 4.1.1.RELEASE
JDK = 1.8.0...
Pinzler asked 7/3, 2016 at 5:51
3
I am trying to write unit tests for Quarkus using Mockito, but I fail mocking things.
Here is a minimal (not) working example :
package com.my.package;
import io.quarkus.test.junit.QuarkusTest;
im...
Parfitt asked 23/9, 2020 at 15:59
4
Solved
I'm in trouble with mockito.spy method.
I'm recently arrived on a "old" project and my first task is to add mockito in it, and to do real unit test :)
the project has many conception problems but...
5
Solved
I have a simple Java method, I would like to check that it does not throw any exceptions.
I have already mocked the parameters etc, however I am not sure how to use Mockito to test that no except...
Boutwell asked 10/8, 2016 at 8:56
6
Solved
I'm trying to mock up some mongo classes so that I don't need a connection (fairly standard stuff) but the following code gives me problems:
when(dbCollection.find(isA(DBObject.class))).thenReturn...
10
Solved
I have the following Logger I want to mock out, but to validate log entries are getting called, not for the content.
private static Logger logger =
LoggerFactory.getLogger(GoodbyeController.clas...
8
Solved
I have a function that uses the current time to make some calculations. I'd like to mock it using mockito.
An example of the class I'd like to test:
public class ClassToTest {
public long getDou...
Hunan asked 9/8, 2012 at 16:24
7
Solved
I have a method in the class AppleProcessor which I would like to test:
public void process(Fruit fruit) {
if(fruit.getType() == Fruit.APPLE) {
fruitBasket.add(((AppleFruit) fruit).getApple());
...
2
I am using Mockito to mock spring beans.
It works fine when I mock an interface.
In our application, there are few @Component beans which do not implement any interface.
When I try to mock such ...
Ecclesiology asked 5/2, 2017 at 7:8
1
I tried out the mock-maker-inline "Incubation" feature of Mockito to be able to mock a final class (problem described and discussed here). Since then other tests fail with:
org.mockito.exceptions...
11
Solved
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
final MyClass myClassSpy = Mockito.spy(myInstance);
Mockito.when(myClassSpy.method1())....
4
I am using Mockito for service later unit testing. I am confused when to use doAnswer vs thenReturn.
Can anyone help me in detail? So far, I have tried it with thenReturn.
21
Solved
I have a service in which I need to ask an outside server via rest for some information:
public class SomeService {
public List<ObjectA> getListofObjectsA() {
List<ObjectA> objectAL...
Evermore asked 14/9, 2016 at 9:6
6
Solved
I'm trying to have one of my mocked objects throw a checked Exception when a particular method is called. I'm trying the following.
@Test(expectedExceptions = SomeException.class)
public void thro...
16
Solved
I need to simulate a test scenario in which I call the getBytes() method of a String object and I get an UnsupportedEncodingException.
I have tried to achieve that using the following code:
Strin...
Endocentric asked 3/7, 2009 at 12:55
4
Solved
My target is to mock Build.Version.SDK_INT with Mockito. Already tried:
final Build.VERSION buildVersion = Mockito.mock(Build.VERSION.class);
doReturn(buildVersion.getClass()).when(buildVersion).g...
Photographic asked 28/10, 2016 at 7:51
4
My tests seems to pass whether I use
@BeforeEach
void initMocks() {
MockitoAnnotations.initMocks(this);
}
or not and I don't understand why since in the "Pivotal Certified Professional Core Sp...
14
Solved
public class A {
public void method(boolean b){
if (b == true)
method1();
else
method2();
}
private void method1() {}
private void method2() {}
}
public class TestA {
@Test
public voi...
6
Solved
Consider this code:
public class DummyClass {
public List<? extends Number> dummyMethod() {
return new ArrayList<Integer>();
}
}
public class DummyClassTest {
public void testMoc...
Triboelectricity asked 9/9, 2011 at 18:59
2
Solved
Is it possible to mock (with mockito) method with signature Set<? extends Car> getCars() without supress warnings? i tried:
XXX cars = xxx;
when(owner.getCars()).thenReturn(cars);
but no m...
6
Solved
I have the following code:
@Component
public class Wrapper
{
@Resource
private List<Strategy> strategies;
public String getName(String id)
{
// the revelant part of this statement i...
Phenacaine asked 20/2, 2017 at 17:44
25
I would like to inject a Mockito mock object into a Spring (3+) bean for the purposes of unit testing with JUnit. My bean dependencies are currently injected by using the @Autowired annotation on p...
Doriedorin asked 16/3, 2010 at 18:58
4
Solved
I'm using the Mockito framework to create Mock objects in my JUnit tests. Each mock knows what methods have been called on it, so during my tests I can write
verify(myMock, atLeastOnce()).myMethod(...
4
Solved
The below code shows my problem. Effectively, I am trying to use Mockito's ArgumentCaptor to verify that a method was called once with a certain concrete class. I would like to use ArgumentCaptor h...
Tholos asked 23/3, 2011 at 10:19
5
I want to mock the System.getenv() method. I found only solutions for JUnit4 and PowerMockito.
I use the following dependency:
<dependency>
<groupId>org.mockito</groupId>
<a...
Fibrin asked 8/11, 2020 at 22:26
© 2022 - 2025 — McMap. All rights reserved.