Tales from the jar side: Misleading Mockito documentation, the Java Champions conference, A creepy Zillow castle near me, Kiss A Ginger Day, and a 50s cover for the ages
Dad joke: The first rule of passive aggressive club is ... you know what? It's fine. Never mind.
Welcome, fellow jarheads, to Tales from the jar side, the Kousen IT newsletter, for the week of January 9 - 16, 2021. This week I taught a course on the Latest Features In Java as an NFJS virtual workshop, and a course on Functional Programming In Java on the O’Reilly Learning Platform.
If you wish to become a jarhead, subscribe using this button:
I should also mention that whenever my newsletter becomes too long for email, you can see the full version online. If you miss an issue, the entire archive is there as well, and everything is free.
Mockito: Unintentionally Misleading Documentation
I mentioned in earlier newsletters that I’ve been spending a lot of time with the Mockito testing framework. Here’s how that happened, which is also a description of how I wind up overcommitted.
Periodically I teach a course on writing true unit tests in Java using the Mockito testing framework. Here’s the idea: when you test a system, you provide inputs as though the system was a black box (i.e., you don’t know anything about how it works inside) and check the outputs. If the outputs match what you expected, the test passes and you have confidence the whole system works as you expect.
If the test fails, however, it might be hard to figure out why. The trick is to isolate each component of the system and test that part individually, so if a test fails you know exactly where and why. Mockito makes it easy to isolate the part you’re testing from the rest of the system by generating fake objects that emulate what the rest does.
It’s like saying, when I buy an item at some site, I don’t want to use a real credit card charger during testing. I also don’t want failures in the credit card charger to affect whether I have the check-out process implemented correctly. So I make a fake object to stand in for the credit card service, and say something like, if I call the service with this credit card info, here is what I want it to return. Then I use the fake object with the part I actually want to test, and if the test fails, it must be due to a problem in the what I wrote, not the credit card service.
Here’s the problem I run into when teaching this stuff. When I show the students the documentation on the Mockito site, it immediately shows code like this:
That code is right, and it works, but it’s totally misleading. Yes, you use Mockito to create the mock, as this sample does with the mock method. Also, at the end you can verify that the mock did what you wanted, as this does with the verify method.
The part that’s a problem is the lines with the comment “using [the] mock object.” In this snippet, the calls to add and clear are on the mock itself, but in an actual test, the tester isn’t supposed to write that code! Instead, you plug the mock into the class you’re actually testing (not shown here at all), and when you call a method on that object, it turns around and calls add and clear on the mock. This snippet, like almost all the snippets in the documentation, makes it look like you need to test the mock itself, and that’s completely wrong.
Look, I get it. The docs are not trying to teach you about testing. They’re trying to teach you how to make Mockito do what you want, and they do a good job of that. The problem is unless you already know how to use mocks, you don’t understand what the mocks are actually for and how they should be used. That’s the mental leap going on here. If you’re already a tester accustomed to mock objects, you know that without thinking. If you’re not (and in my experience most people adopting Mockito are not familiar with those ideas), you get the completely wrong impression from the documentation and don’t know what to do next.
Somebody, somewhere, needs to explain all that. Ideally that discussion would be part of the overall documentation, or part of a tutorial included in the documentation, or — worst and most time-intensive of all — it would be part of a short book on writing tests with Mockito. That, of course, is where I come in, because I saw a need and I’m tired of explaining the same problem every time I show the docs to a new group of students.
Not that I have time for a new book project, of course, but that’s how I get overcommitted. More about that in future newsletters.
To conclude this section, here’s the best tweet I’ve ever seen to explain mocks:
I wish I’d thought of that when my son was that age. I also dearly want to include that in my own materials, but I’ll have to think about how first.
Java Champions This Week
The online, free Java Champions conference is Thursday/Friday this week and Monday/Tuesday of next week. My talk is on Thursday:
From what I hear, there are already over 4000 people registered for the conference, and there are no simultaneous tracks, so I could wind up with a lot of attendees. I guess it’s a good thing every session has a moderator. I usually like to be my own moderator, but when the number of attendees get about 400 to 500, you can’t keep up with the questions without interrupting the session too much.
I have no idea how many people will attend, but if any jarheads make to the talk, please say hi. :)
Tweets And Other Miscellaneous Items
First Wordle Word
Last week I mentioned this article discussing the best first-word guess on the game Wordle. I linked to the author’s (Matt Rickard) tweet thread about it, and promised I’d show you the word this week.
In the tweets, he recommended the word RAISE as best. I just checked, however, and in his article (part of his newsletter), he now recommends SOARE, which according to an online dictionary is an obsolete word for a young hawk. His strategy in choosing the starting word was to eliminate the most possible remaining solutions.
He also claims from examining the source code that there are about 13,000 valid guess words, but only 2315 potential solutions, probably because the author didn’t want to use too obscure a word for the solution. I’m okay with that.
I think what you really need, however, is a good pair for the first two words with no overlapping letters. That would eliminate a ton of possibilities, making it likely you can guess the answer in three tries. Rickard did provide a link to his GitHub repository, but the code is all in the Go programming language and I don’t know that, nor am I ambitious enough to port it to a language I do know, at least not at the moment.
Ronnie Spector
I wasn’t much of a Motown person, though of course I appreciated the excellent music. But when Ronnie Spector, lead singer of the girl group The Ronettes, passed away this week, it reminded me of a routine my wife and I have been doing for years (borrowed from an obscure radio commercial):
Me : (yelling to her in another room) Yo, Rapunzel!
Her: WHAT?
Me : Be my, be my baby!
Her: Your one and only baby?
Me : Be my baby now!
Her: Okay!
(I have no idea what the Rapunzel part was about any more, but it’s a good clue to my wife about what’s coming.)
Ronnie Spector had the evil misfortune to be married to dangerous psychopath Phil Spector. It’s a testimony to her strength of character that she eventually escaped and succeeded anyway. It’s all documented in her biography, Be My Baby: How I Survived Mascara Miniskirts and Madness, or My Life as a Fabulous Ronette.
Kiss A Ginger Day
Speaking of my wife, January 12 was apparently Kiss A Ginger Day. My wife isn’t a red-head. Her name is Virginia, however, and her friends have always called her Ginger.
I made sure my wife knew about it. I know on the internet it’s usually “pics or it didn’t happen,” but I doubt my readers are into pictures of old people making out. And if you are, fine, you do you, but I don’t think I want to participate.
Speaking of kissing, however, try this cover of another 50s song on for size:
Isn’t that awesome? I heard this way back when KISS still kind of mattered (assuming you were a preteen boy in middle school) totally forgot about it. This week I remembered it, and lo and behold, there it was on YouTube. Truly, we live in magical times.
(I must admit, when I think about what the dreaded YouTube algorithm is going to offer me now based on that search, I cringe, but you can’t make an omelet, etc.)
The New England Patriots…
… have been eliminated from the NFL playoffs. And by “eliminated,” I mean “obliterated,” or “terminated with extreme prejudice.”
The Patriots lost to Bills QB Josh Allen. I think there might have been other Bills players on the field, but if so, they didn’t need them.
Hey, we had a twenty-year run. So be it. Now that my team is eliminated, I can freely root for or against others without really caring any more. My favorite “Loki, God of Mischief” scenario would be for Green Bay to make the Super Bowl against Buffalo, and then, two days before the game, idiot, lying anti-vaxxer Aaron Rodgers would come down with a serious enough case of COVID that he can’t play. The NFL and all of its new best friend betting houses would have a collective bird. It would also potentially give Buffalo their first (tainted) NFL championship, which their fans would still be completely obnoxious about. I think that would manage to upset pretty much everybody (outside of Buffalo). Works for me. Burn it all down.
A Creepy Zillow Find Too Near Me
I may have mentioned this property in an earlier newsletter, but a tweet thread came up about it that was too bizarre for words:
You have to read that thread to the end to get the real impact. I was absorbed in the story long before I got to the weird parts, or remembered that the castle is in my state.
It’s called Chris Mark Castle and is in Woodstock, CT. Here’s the Zillow listing, which currently values the property at $35,000,000, or only $189,418/month.
That means it’s only about an hour from me:
I was tempted to sign up for the tour, but that may be a bit too brazen even for me. Besides, the pictures in that Zillow listing (not to mention the Twitter thread) are probably enough. Besides, it only has 12 fireplaces (for 9 bedrooms?) covering 18,777 square feet on 75 acres. The $80K/year in taxes feels a bit high, too.
I think I’ll hold off for the time being. I’d hate to have to start charging for this newsletter just to make those monthly payments.
As a reminder, you can see all my upcoming training courses on the O’Reilly Learning Platform here and all the upcoming NFJS Virtual Workshops here.
Last week:
Latest Features In Java, an NFJS Virtual Workshop
Functional Programming In Java, on the O’Reilly Learning Platform
Work on my Mockito-related project.
Work on Intro Java materials for a private client.
This week:
Introduction to the Gradle Build Tool, online for Gradle, Inc.
Kotlin Fundamentals, on the O’Reilly Learning Platform