Emacs is awesome!

Here’s an elisp function that will just underline your current text. It’s simple, awesome and I use it all the time for my titles. You can put it in the *scratch* and do a C-x C-e and then call it with M-x add-underlining.


JUnit Argument Captor — enhance your mock testing

When writing mock tests it is, sometimes, more convenient to assert the values with which the methods were called using the ArgumentCaptor
class instead of the more usual mockĀ verify.
Let’s see both in action.

We’ll take as sample a mock of the List interface.

Let’s see how verify-ing would work:

Or since we expect those to be called in that same exact order we could also:

Now let’s use ArgumentCaptor instead:

That seems more streamlined and readable IMO. As you can see the ArgumentCaptor will catch all arguments with which it was called.

If you expect a single value to be captured or if you’re only interested in the last value with which your method was called you can also call:

In our case that call will return “three”.