How to avoid call to super class constructors/methods using JMockit?

When you work with legacy codebase, sometime you would like to avoid the call to super constructor and super methods so that you can focus on covering sub class. package com.ourownjava.tdd.jmockit; /** * * @author Sanju Thomas * */ public class BaseClass { public BaseClass(final String name){ throw new IllegalArgumentException(name); } } package com.ourownjava.tdd.jmockit; /** […]
Continue reading…

 

JMockit — Verify arguments passed to mocks using withCapture

While you test using mocks it would be necessary sometime to capture the arguments passed into mocked behavior. JMockit Verification.withCapture method can be used to capture the argument passed into a mocked behavior. The complete source code for this article can be found in the github   package com.ourownjava.tdd.mockit; import javax.naming.AuthenticationException; /** * * @author […]
Continue reading…

 

How to mock exceptions using Mockito?

In the previous post I shared a sample program to mock exception conditions using JMockit. Today we will look into exception mocking with Mockito. As I mentioned in the earlier post, during the development time, testing an exception scenario without the help of the second party/third party service developer is not an easy task. However […]
Continue reading…

 

Mocking exception using JMockit

In today’s post I would talk about mocking exceptions using JMockit. You would like to test exception scenarios, especially when you deal with third party services. This will help you to fine tune your code to deal with the exception. During the development time testing an exception scenario without the help of the second party/third […]
Continue reading…

 

Vending Machine Kata – Java

Recently one of the companies asked me to solve Vending Machine Kata given here (https://github.com/guyroyse/vending-machine-kata) as their first level of screening. Though I couldn’t solve it completely in less than three hours I have covered most of the usecases. You can find my solution here. (https://github.com/sanjuthomas/vending-machine) You will have to add logic to complete the […]
Continue reading…