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 …

I’m trying to mock a list of strings but it’s not working. I’m not able to figure out the problem

This is the class and the corresponding test I have written for it. Can someone please help me understand why System.out.println(a.size()) prints 0 , when it should print 1000? WorkingwithLists.java …

How to Mock LdapTemplate in Java and get full code coverage

I am trying to get full coverage on a very simple junit test using Mockito and am striking out. My disclaimer is that I am new to Mockito though what I am trying to do would seem pretty …

Mockito doThrow() method makes my test fail with the given exception

I’m testing the error case for when my injected StatefulBeanToCsv dependency throws an exception. However, Mockito’s doThrow() method is just making my test fail, rather than allowing that exception …

Null pointer exception when using Mockito to mock interface

I’m using Mockito to test the following method: protected void produceProducedFieldValue(Target target) throws ValueProducerCreationException { String mappedValue = (String) valueProducerFactory….

How to stop main method calling sleep() method, when testing it with Junit?

I am testing a method which contain sleep in side it.What is the way to stop invoke sleep() as it makes testing slow?? public void fun(Integer timeToWait) { TimeLimiter timeLimiter = new …

No mapping for request with mockmvc

Currently struggling with problem when I get ‘mapping error for request’ with following controller/test configuration. Controller: @Slf4j @Validated @RestController @RequiredArgsConstructor public …

Mockito Spy Does Not See Correct Primitive Value

I am facing the below problem where, when indirectly updating the fields on a spy object, the spy does NOT see updates on primitive fields, whereas it sees on reference once. As an example: import org….

Trying to mock IntConsumer with Mockito fails

I’m trying to mock IntConsumer: class TickerServiceImplTest { @Test void testRunIterations() { TickerServiceImpl tickerService = new TickerServiceImpl(); int ticksToRun = 100; …

Ignoring only embedded member in AssertJ

I have two classes to test with JUnit/Mockito: public class ClassA { private int sk; // getters and setters } public class ClassB { private int sk; private List