Linked Questions

Popular Questions

I am trying to write a JUnit test case for a method whose job is to change a single entry in a block of information. We don't have a lot of JUnit tests here for me to look at as examples and I myself don't have much experience with JUnit. I am doing a when().thenReturn method call but noticed that I am only getting back a nullException. I can't finish testing the method when that is thrown.

I will be using semi pseudo code for my example but all code in the program is written in Java 8. I currently have 2 when().thenReturn() calls:

when(Class.readInfo(any(), anyString(), any())).thenReturn(INFO);

The first when call is to a method call inside the method being referenced in the second when. It looks something like this:

getInformation(final String){
   Database call;

   final Information info = readInfo(connection, String, Enum); <---returns a nullException

   return info;
 } catch(Exception e){
 } finally {
 return null;

The method readInfo call is to a method in an Interface located in our .gradle file. Do I need to try to mock the insides of that Interface as well? I've tried Googling this but Google thinks I'm asking about making a mock that WILL throw an Exception while I'm trying to stop it from doing so. I have heard about using Spy but a senior developer/ kinda manager told me not to use Spy. Also in similar questions I see something that looks like a solution using EasyMock but I don't have access to that I am not allowed to add more dependencies.

Related Questions