December 10th, 2019

That's Improbable!

So I wrote a new method for the project that I've been working on. It wasn't an overly complex method, but it was slightly annoying to write and might actually have been written in some "doomed to fail" way by mistake, so I said to myself, "Well, self, why don't you just write a unit test and make sure that it works?"

This was a good question with a simple answer, so I wrote the unit test. After a bit of futzing around with types (generics were in play), I got the unit test to work and determined that the new method was putting out what it was supposed to given the inputs I had given it. Good enough.

Let me go add it to the list of unit tests so that it will get run when I check this mess in again.

Hey, as long as I'm adding the unit test to the list, let's run the subset of unit tests that exercise my code.

Why are these unit tests failing?

It turns out that I had made a change that converted an ISO currency code I was using from upper case to lower case. This would seem harmless and -- in some better universe -- it would be. However, the Java Currency.getInstance() method stubbornly insists that it is only going to play nice if the currency code is in upper case.

I have patched the code so that the currency code is now upper case again.

Sheesh.

So much to my surprise, a unit test has done what it was supposed to do. This is a first in my experience...