Blog Archives
1 2 3 4 5

03: Mockito interview Q&As & examples on @Mock, Mockito.mock(…) and @MockBean

Unlike a @Spy where you are spying on a real object, when you mock, you are creating a complete mock or fake object. Q: What are the different ways to mock an object? A: There are 3 ways to mock a dependent class that is sed by the class under...

This content is for 100-Day-Full-Access, 200-Day-Full-Access, 365-Day-Full-Access, and 2-Year-Full-Access members only. Register 50+ Free Java FAQs 50+ Free Big Data FAQs
Already a member? Log in here


03: Mockito to fully mock the DAO layer

This extends Part 1: Unit testing with JUnit, Mockito & Spring by mocking the DAO layer with the Mockito framework. Step 1: Service and DAO layer interfaces and implementations Service Layer

DAO Layer This layer will be mocked by Mockito in the next step. … Read more ›...

This content is for 100-Day-Full-Access, 200-Day-Full-Access, 365-Day-Full-Access, and 2-Year-Full-Access members only. Register 50+ Free Java FAQs 50+ Free Big Data FAQs
Already a member? Log in here


04: JMockit interview Q&As & examples on @Injectable vs @Mocked

This extends 01: JMockit interview Q&As on @Injectable Vs @Mocked Vs @Tested. The purpose of mocking objects is to return an expected value to test the logic of the class under test. This can be achieved with JMockit Expectations. Q1. … Read more ›...

This content is for 100-Day-Full-Access, 200-Day-Full-Access, 365-Day-Full-Access, and 2-Year-Full-Access members only. Register 50+ Free Java FAQs 50+ Free Big Data FAQs
Already a member? Log in here


04: Mockito interview Q&As & examples – PowerMock for mocking private & static methods

Let’s look at step by step to understand how to mock private & static methods with PowerMock & JUnit. pom.xml Step 1: The pom.xml file should have Mockito & Powermock libraries.

Config & Service classes to test Step 2: The implementation classes that need to be tested. … Read...

This content is for 100-Day-Full-Access, 200-Day-Full-Access, 365-Day-Full-Access, and 2-Year-Full-Access members only. Register 50+ Free Java FAQs 50+ Free Big Data FAQs
Already a member? Log in here


04: Mockito partially mocking with @Spy

This extends Part 2: Mockito to fully mock the DAO layer by modifying the service layer to demonstrate partial mocking with “Mockito.spy”. In the “SimpleServiceImpl” we are interested in only testing the method “processUser(int id)” and want to mock the method “getUserById(int id)” by always returning “Sam”. So, … Read...

This content is for 100-Day-Full-Access, 200-Day-Full-Access, 365-Day-Full-Access, and 2-Year-Full-Access members only. Register 50+ Free Java FAQs 50+ Free Big Data FAQs
Already a member? Log in here


05: JMockit interview Q&As & examples on Partial Mocking with Expectations(Object..)

This extends Mockit interview Q&As & examples on @Injectable Vs @Mocked Vs @Capturing Vs @Tested. Why partial mocking? All methods that can be called on a mocked instance get mocked. This is appropriate for most tests, but in some situations we might need to select only certain methods to be...

This content is for 100-Day-Full-Access, 200-Day-Full-Access, 365-Day-Full-Access, and 2-Year-Full-Access members only. Register 50+ Free Java FAQs 50+ Free Big Data FAQs
Already a member? Log in here


05: Mockito & PowerMock partially mocking private methods with @Spy

This extends Part 3: Mockito partially mocking with @Spy by making the method “processUser(int id)” as a private method. Mockito framework cannot mock “private” methods, hence the “PowerMock” framework is added to the pom.xml file Step 1: Add “PowerMock” … Read more ›...

This content is for 100-Day-Full-Access, 200-Day-Full-Access, 365-Day-Full-Access, and 2-Year-Full-Access members only. Register 50+ Free Java FAQs 50+ Free Big Data FAQs
Already a member? Log in here


06: JMockit interview Q&As & examples on Partial Mocking with MockUp

In the last post we looked at partial mocking with Expectations(Object..) and in this post use MockUp to partially mock the constructors, private methods and/or static methods of a class. What is MockUp<T>? In the JMockit toolkit, the Faking API provides support for the creation of fake implementations. … Read...

This content is for 100-Day-Full-Access, 200-Day-Full-Access, 365-Day-Full-Access, and 2-Year-Full-Access members only. Register 50+ Free Java FAQs 50+ Free Big Data FAQs
Already a member? Log in here


06: Mockito & PowerMock for mocking static methods

This extends Part 4: Mockito & PowerMock for partially mocking private methods to mock “static” methods.

How to use both Spring JUnit and PowerMock runners?

By using the “@PowerMockRunnerDelegate” from the “powermock-module-junit4” jar.

So, need to use compatible “Mockito”

Read more ›



07: JMockit interview Q&As & examples on replaying with result field, returns(…) method & Delegate interface

When using JMockit, there are 3 different ways of defining the expected result of the invocation of a mocked method. 1) result field, which we have been using the previous posts. It could be a value:

or an exception:

2) returns(Object…) method is a syntactic sugar for returning...

This content is for 100-Day-Full-Access, 200-Day-Full-Access, 365-Day-Full-Access, and 2-Year-Full-Access members only. Register 50+ Free Java FAQs 50+ Free Big Data FAQs
Already a member? Log in here


08: JMockit interview Q&As & examples on MockUp with Invocation.proceed()

This extends 06: JMockit interview Q&As & examples on Partial Mocking with MockUp. What is MockUp<T>? In the JMockit toolkit, the Faking API provides support for the creation of fake implementations. JMockit’s mockit.MockUp<T>, where T is the type to be faked. … Read more ›...

This content is for 100-Day-Full-Access, 200-Day-Full-Access, 365-Day-Full-Access, and 2-Year-Full-Access members only. Register 50+ Free Java FAQs 50+ Free Big Data FAQs
Already a member? Log in here


09: JMockit interview Q&As & examples on matching of argument values

JMockit offers a set of utility fields for making argument matching more generic. 1) anyX fields like anyInt, anyBoolean, anyString, etc. There is one for each primitive type, and the corresponding wrapper class, … Read more ›...

This content is for 100-Day-Full-Access, 200-Day-Full-Access, 365-Day-Full-Access, and 2-Year-Full-Access members only. Register 50+ Free Java FAQs 50+ Free Big Data FAQs
Already a member? Log in here


10: JMockit interview Q&As & examples on matching anyX field and withX() methods

JMockit offers a set of utility fields & methods for making argument matching more generic. This extends 09: JMockit interview Q&As & examples on matching of argument values 1) anyX fields like anyInt, anyBoolean, … Read more ›...

This content is for 100-Day-Full-Access, 200-Day-Full-Access, 365-Day-Full-Access, and 2-Year-Full-Access members only. Register 50+ Free Java FAQs 50+ Free Big Data FAQs
Already a member? Log in here


1 2 3 4 5

300+ Java Interview FAQs

Tutorials on Java & Big Data