How to mock LocalDateTime.now() in java 8

Please, I am testing a functionality ABC that uses LocalDateTime.now(). In the methode ABC i’am comparing an entry date with the LocalDateTime.now() I want my test to be passed at any day so i have to …

Why the hang() method is only getting executed for one time?

class Demo{ static void hang(){ // Freezes/Hangs the program for some seconds. for(int i=0 ; i<100000 ; i++){ for(int j=0 ; j<10000 ; j++){ for(int k=0 ;...

Unit testing with inject annotation

How do I unit test a class that uses @inject annotation:class A{ @inject private B b; void foo(){ b.funcInClassB(); } I am new to unit testing and having troubles testing this function because …

Mocking a singleton with mockito

I need to test some legacy code, which uses a singleton in a a method call. The purpose of the test is to ensure that the clas sunder test makes a call to singletons method. I have seen similar …

mock instance is null after @Mock annotation

I try to run this test: @Mock IRoutingObjHttpClient routingClientMock; @Mock IRoutingResponseRepository routingResponseRepositoryMock; @Test public void testSendRoutingRequest() …

Mockito Error Is Not Applicable for the Arguments (void)

Mockito throws error “The method when(T) in the type Stubber is not applicable for the arguments (void)” for a class I’m mocking, can’t figure out why. the code in question is: Mockito.when(…

Mocking static methods with Mockito

I’ve written a factory to produce java.sql.Connection objects: public class MySQLDatabaseConnectionFactory implements DatabaseConnectionFactory { @Override public Connection getConnection() { …