Mocked Dependency Object Is Null After Using Mockito @InjectMocks Annotation

Let me explain the problem first. We have a Java class under test. We are using Junit with Mockito framework to write the unit test cases.We have annotated our test class with @InjectMocks annotation as below: @InjectMocks private TestClass testClass; @Mock private Dependency1 dependency1; @Mock private Dependency2 dependency2; That should inject mocked dependencies to the … Read more

Log When JDBC Connection Is Acquired And Released

We are fond of one db session per request pattern. For web applications with JPA & Hibernate, it is good strategy in common cases. But for some long-running requests (definition of long-running depends on your use case, maybe 500 ms or 2 s), we need to tweak when we are actually acquiring a db connection … Read more

How To Solve XML Parsing Issue “Content is not allowed in prolog” In Java

If you have come to this post, then you are facing xml parsing issue in Java. Caused by: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.         at One common issue for this is BOM character. So what is a BOM (BYTE ORDER MARK) character? When you have … Read more

How To Fix “unable to find valid certification path to requested target” Error

If you are here, that means probably you have encountered below error: Caused by: PKIX path building failed: unable to find valid certification path to requested target         at         at         at         at     … Read more

Difference Between Wait And Park Methods In Java Thread

If you are familiar with thread dump or at least looked at it couple of times, probably you would have noticed WAITING  & WAITING (parking) states. So what’s the difference? In Java, we have Object.wait() and Unsafe.park() methods. Both of them will suspend the running thread & put it in waiting state. But these two methods work on different principles. Object.wait() results in WAITING state whereas Unsafe.park() method … Read more