Home » Archives for Ted Vinke

Author Archives: Ted Vinke

Ted is a Java software engineer with a passion for Web development and JVM languages and works for First8, a Java Web development company in the Netherlands.

Mockito: Why You Still Should Appreciate InjectMocks Annotation

Anyone who has used Mockito for mocking and stubbing Java classes, probably is familiar with the InjectMocks-annotation. I seemed a little harsh in an article a few years back about why you should not use @InjectMocks to auto-wire fields, even though I actually consider Mockito to be one of the most brilliant mocking frameworks for unit testing in Java. Every ...

Read More »

Mockito: Cannot instantiate @InjectMocks field: the type is an abstract class

Anyone who has used Mockito for mocking and stubbing Java classes, probably is familiar with the InjectMocks-annotation. Use this annotation on your class under test and Mockito will try to inject mocks either by constructor injection, setter injection, or property injection. This magic succeeds, it fails silently or a MockitoException is thrown. I’d like to explain what causes the “MockitoException: ...

Read More »

Mockito: Cannot instantiate @InjectMocks field: the type is an interface

Anyone who has used Mockito for mocking and stubbing Java classes, probably is familiar with the InjectMocks-annotation. Use this annotation on your class under test and Mockito will try to inject mocks either by constructor injection, setter injection, or property injection. This magic succeeds, it fails silently or a MockitoException is thrown. I’d like to explain what causes the “MockitoException: ...

Read More »

Local records or classes to improve the readability of stream operations

Java 14 came with the preview language feature of Records — a special lightweight class, comparable to similar constructs in other languages, such as record classes in C#, data classes in Kotlin and case classes in Scala. There’s A) already numerous blog posts explaining Java 14 records and B) numerous articles comparing usage of records with Project Lombok’s @Value (for ...

Read More »

Functional Java by Example | Part 8 – More Pure Functions

This is part 8, the last instalment of the series called “Functional Java by Example”. The example I’m evolving in each part of the series is some kind of “feed handler” which processes documents. In the last instalment we’ve seen some pattern matching, using the Vavr library, and treated failures as data too, e.g. take an alternative path and return ...

Read More »

Functional Java by Example | Part 7 – Treat Failures as Data Too

This is part 7 of the series called “Functional Java by Example”. The example I’m evolving in each part of the series is some kind of “feed handler” which processes documents. We’ve already dealt with exceptional situations before, but we’re going to take care of them, more ehm,…functionally — as data. If you came for the first time, it’s best ...

Read More »

Functional Java by Example | Part 6 – Functions as Parameters

This is part 6 of the series called “Functional Java by Example”. The example I’m evolving in each part of the series is some kind of “feed handler” which processes documents. In previous part we tried to make our functions as pure possible by moving as much of the side-effects, such as IO, to the outside of the system. Now ...

Read More »

Functional Java by Example | Part 5 – Move I/O to the Outside

This is part 5 of the series called “Functional Java by Example”. In previous part we stopped mutating our documents and returned copies of the data. Now, we need to move some I/O away. If you came for the first time, it’s best to start reading from the beginning. It helps to understand where we started and how we moved ...

Read More »

Functional Java by Example | Part 4 – Prefer Immutability

This is part 4 of the series called “Functional Java by Example”. In previous part we talked a bit about side effects and I’d like to elaborate a bit more about how we can prevent having our data manipulated in unexpected ways by introducing immutability into our code. If you came for the first time, it’s best to start reading ...

Read More »