Blog Archives
1 2 3 4

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 30-Day-Full-Access, 100-Day-Full-Access, 200-Day-Full-Access, and 365-Day-Full-Access members only. Register 80+ Free Java FAQs 80+ 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 30-Day-Full-Access, 100-Day-Full-Access, 200-Day-Full-Access, and 365-Day-Full-Access members only. Register 80+ Free Java FAQs 80+ 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 30-Day-Full-Access, 100-Day-Full-Access, 200-Day-Full-Access, and 365-Day-Full-Access members only. Register 80+ Free Java FAQs 80+ 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 30-Day-Full-Access, 100-Day-Full-Access, 200-Day-Full-Access, and 365-Day-Full-Access members only. Register 80+ Free Java FAQs 80+ 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 30-Day-Full-Access, 100-Day-Full-Access, 200-Day-Full-Access, and 365-Day-Full-Access members only. Register 80+ Free Java FAQs 80+ 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 30-Day-Full-Access, 100-Day-Full-Access, 200-Day-Full-Access, and 365-Day-Full-Access members only. Register 80+ Free Java FAQs 80+ Free Big Data FAQs
Already a member? Log in here


11: JMockit interview Q&As & examples on matching withArgThat(org.hamcrest.Matcher)

This extends Mockit 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. 1) anyX fields like anyInt, … Read more ›...

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


12: JMockit interview Q&As & examples on matching with(Delegate)

JMockit offers a set of utility fields & methods 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 30-Day-Full-Access, 100-Day-Full-Access, 200-Day-Full-Access, and 365-Day-Full-Access members only. Register 80+ Free Java FAQs 80+ Free Big Data FAQs
Already a member? Log in here


13: JMockit interview Q&As & examples on Deencapsulation utility class

This extends JMockit interview Q&As & examples on Partial Mocking with MockUp. What is Deencapsulation utility class used for? Mocking and testing of private methods or inner classes is often not considered good practice. Earlier we had looked at the Faking API with MockUp<T> to mock private methods. … Read...

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


14: JMockit interview Q&As & examples on Mocking a super class

There are times you want to Mock the superclass & test only the subclass. Superclass that should not be invoked The BaseService.java:

Subclass to be tested The MyService.java:

JUnit test class The BaseService.java will be mocked as shown below. … Read more ›...

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


15: JMockit interview Q&As & examples on Mocking a Singleton

We often write code that depends on Singletons. Writing unit tests in this case could be tricky. Here is an example demonstrating how to solve the problem with JMockit. Is Singleton pattern an anti-pattern? The Singleton pattern is a design pattern that restricts the instantiation of a class to one...

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


5 Java unit testing interview Questions and Answers

Q1 Why use mock objects in unit testing? A1 Unit testing is widely accepted as a “best practice” for software development. When you write an object, you must also provide an automated test class containing methods by calling its various public methods with various parameters and making sure that the...

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


1 2 3 4

300+ Java Interview Questions - FAQs

Tutorials on Java & Big Data