Tales from the jar side: Mocking constructors, Schadenfreude week, When James Bond dissed The Beatles, and Good Tweets/Toots
Man walks into a store and asks for a dozen bees. Owner counts out 13. Man says that's one too many. Owner says, "that's a freebee." <rimshot>
Welcome, fellow jarheads, to Tales from the jar side, the Kousen IT newsletter, for the week of November 7 - 13, 2022. This week I spoke at the NFJS conference in Austin, TX and taught an NFJS Virtual Workshop on Spring MVC.
Regular readers of this newsletter are affectionately known as jarheads, and are far more intelligent, sophisticated, and attractive than the average newsletter reader. If you wish to become a jarhead, please subscribe using this button:
As a reminder, when this message is truncated in email, click on the title at the top to open it in a browser tab formatted properly for both the web and mobile.
Many people are calling this week Schadenfreude Week, given that so many awful people suffered so much, both self-inflicted and otherwise. We’ll get to that, but this week I actually have something technical to talk about. As usual, if you’re not a technical person, or you’re simply not interested in the topic, feel free to skip the next section. This newsletter is called Tales from the jar side, however, so I feel I ought to at least try to include something from the Java world every now and then. :)
Mocking Constructors in Mockito
In my continuing effort to try to complete my latest book, Mockito Made Clear, I finally added one of the last sections I’ve been planning to include.
(“Trying?” I imagine my editor grumbling (though she’s not the type to do that at all). “Not trying hard enough.” Or maybe that was my internal editor, who tends to be a right b@st@rd.)
The new section is on mocking constructors. As I lamented in a previous newsletter, I was having trouble figuring out where you would use that capability, but I think I get it now.
Say I have a class called HelloMockito
(which I use in the first chapter) that has two dependencies: a PersonRepository
that lets me look up a Person
based on their id
, and a TranslationService
that lets me translate a greeting (like “Hello, World!”) into their preferred language. I want to test the greet
method, which uses both services:
Usually, I provide a constructor to inject the mocks into the class under test:
Say, however, that instead of requiring a TranslationService
as a constructor argument, I let the HelloMockito
class instantiate it on its own?
How am I going to mock the DefaultTranslationService
to get the behavior I want if it’s essentially a local variable? It turns out, that’s what mocking a constructor is for. Here’s what the code looks like, which I’ll explain after the listing:
The idea is to use the mockConstruction
method inside a try-with-resources block, so it will automatically be closed when the try block is completed. The mockConstruction
method takes two arguments: the class whose construction is being mocked, and a MockInitializer
, which is a functional interface. My lambda implementation says that when the translate
method is called on the translation service, it should reply with whatever argument was used in the call, plus the string “(translated)”
.
As long as the class I’m testing instantiates the service inside my try-with-resources block, the construction will be replaced with what I specified. It’s a bit involved, but it works.
Finally figuring this out inspired me to address the remaining issues left in the book, as well as completing the Preface and the Acknowledgements. The text has now been submitted for copyedit (yay!), so any further changes should be minor, and the book will be officially released soon.
I’ll let you know as the process unwinds, but it’s a relief to finally make it this far.
Schadenfreude Week
I’m not going to go into too much detail on these, since you can find lots of info on them elsewhere. Still, it’s been fun to watch some hateful people get what they deserve this week, at least in part.
Dan Snyder
Snyder is the worst owner in the NFL, and that’s a very high bar. He can truly be described as loathsome. The other owners have been trying to pressure him to sell his team, but until recently he fought that at every turn. That changed this week, however.
Why do they want him to sell? You might think it’s because this week the DC Attorney General Karl Racine sued the team, the league, and equally-despicable NFL commissioner Roger Goodell of colluding to deceive fans by lying about an inquiry into “sexual misconduct and a persistent hostile work environment” within the team.
You’d think that’s why the other owners want him to sell, but most observers think the real reason is that he’s lied so frequently and so blatantly to government officials that no one in DC, Maryland, or Virginia is willing to discuss building a new stadium for his team. From the owners’ point-of-view, being unable to bring in those stadium dollars is an unforgivable sin.
Anyway, couldn’t happen to a nicer guy, other than the fact that the eventual sale will probably bring in around $6 billion for him. Blech. But at least he’ll be gone.
That crypto bro that runs FTX
Sam Bankman-Fried (known online as SBF, because who wants to keep typing that?) announced that his crypto company FTX has declared bankruptcy.
The details are included in this most recent Reuter’s article about how at least $1 billion in funds vanished overnight after the bankruptcy claim. It’s all both ugly and sleazy, but his net worth really did supposedly go from $16 billion to zero practically overnight, that’s worth celebrating at least.
Another good summary, though focussed on sports, can be found at The Defector.
Also:
Somehow, I don’t think that will be last event like this.
Trump
I won’t comment on the midterms other than to say the anticipated “red wave” turned out to be a few ripples on the surface. FYI, my favorite commentator on all of this is a YouTuber who goes by the name Beau of the Fifth Column. He’s excellent. He cranks out three short (five minutes or less) videos every day, and they’re really good. I was going to recommend a particular one, but honestly you can start anywhere and get the idea.
That’s all I’m going to say about the elections, since I assume that’s not why you’re reading this newsletter, but it not exactly difficult to figure out where I stand.
Zuck lays off 11,000 people
As a subscriber, I’m allowed to share a few links to articles at the New York Times for free, so you might be interested in this article about the 11,000 employees laid off by Mark Zuckerberg at Meta (neé Facebook). Everyone said the process was “handled well,” but that’s only by comparing it with the ongoing chaos at the bird site.
Lyft is in the midst of layoffs, too, but that’s practically noise this week.
Elon, so much Elon
Where do I even begin? With laying off half the company and then begging some of them to come back, followed by this internal tweet by the Senior Director of Engineering:
In other words, let’s get rid of them because they’re lazy and stupid, but get some of them back so we can get what we need and lay them off again. If this is the sort of clown Musk is surrounding himself with, no wonder the site is melting down.
Then, of course, there was the fiasco of the $8 blue check mark subscription, which everybody (except apparently Elon) knew was going to be a disaster.
It did inspire some other humor:
I liked this one, too:
The one that’s going to cost him, though, is this one:
Eli Lilly’s stock dropped a few billion dollars before recovering at least a bit, and lawsuits are inevitable.
Of course, Musk doesn’t ever apologize for anything, because he never thinks he did anything wrong. This article at the Washington Post shows how easy it was for a reporter to acquire a “verified” handle impersonating Senator Ed Markey of Massachusetts (with permission!). When they asked Musk about it, he made a snarky reply about Markey’s real account seeming like a parody, which is exactly the sort of behavior that gets you called in to testify in front of congressional committees.
The verification program has been suspended, though Musk then tweeted that maybe companies will be able to verify other companies. That prompted this tweet:
Kind of says it all, really. Twitter is currently a giant game of Calvinball, at least for as long as the company survives.
Meanwhile, over at Mastodon:
Speaking of Mastodon, this excellent Medium article talks about how Mastodon is designed to be “anti-viral”. Any advertiser-supported site wants as many views as possible, so sites like that try to push everyone toward whatever is hot at the moment. That’s the heart of Twitter. Mastodon doesn’t have advertising, and is designed to keep virality from happening. Most of the founders were refugees from Twitter trying to escape the piling-on effect of too many people harassing others, and avoiding viral posts is one way to do that.
It’s a cultural thing over there, and one of the reasons it’s not really a Twitter replacement, though it often feels like one.
That Bizarre Moment When James Bond Dissed The Beatles
This seems like a total non-sequitur, and it is, but I reminded this week of a really odd moment in time.
Three characters in popular culture were so big in the 1960s that they were sometimes referred to as the “Three B’s,” which stood for The Beatles, James Bond, and — believe it or not — Adam West’s Batman. All were products of their time and haven’t aged all that well. The Beatles music still endures, but it really hurt when we lost John Lennon and then George Harrison. Paul McCartney is in his 80s still producing albums, but that’s somewhat of a mixed blessing. Ringo is (mostly) retired, which is just as well.
The Batman TV show (in color!), often referred to as Batman '66, was a staple of my early childhood. (In reruns. I’m old, but I’m not that old.)
Recently all the episodes of that series showed up on the Roku channel (with commercials, sigh), and my wife and I decided to watch them. I got way more of the subtle jokes this time around, of course, especially the great signs:
but I have to tell you, they never missed an opportunity to be sexist. It’s very jarring to a modern watcher. As much as the acting is still great and the over-the-top villains (from the Joker to the Penguin to the Riddler to Catwoman) rule, you have to prepare yourself for the casual misogyny in virtually every episode. Still, it was a fun rewatch, if you can overlook those parts.
That’s nothing against Adam West, btw, who everyone loved and was an excellent actor, as this simple, one-minute “dialog” demonstrates. People say this scene should be the required monologue for any actor hoping to play Batman.
Moving on to Bond, James Bond, I was too young to watch the original Sean Connery James Bond movies when they came out. I came in roughly when Roger Moore took over in Live and Let Die, which today would be called a Blaxploitation film (speaking of not aging well), featuring one of Paul McCartney’s biggest solo hits as the title song. Moore held on too long, but eventually gave way to Timothy Dalton (eh), then Pierce Brosnan (who I loved, but all his movies were unfortunately weak), and finally Daniel Craig, who did a great job for the most part. I would have loved to see Pierce Brosnan sink his teeth into a script like Casino Royale or Skyfall, but it was not to be.
I was reminded of all this when the news broke that Kevin Conroy passed away. Conroy was the voice of Batman in, among other things, the Batman animated series.
Many people wrote laments about Conroy’s passing. Here’s the best article I saw:
As I was reminded, for many millennials and younger, Conroy was their Batman. I get that. Since I have an HBO Max subscription, I took the time during the pandemic to watch all of those episodes, and they were solid, if not spectacular for me. (I also watched all the Batman Beyond episodes, which were pretty cool.)
Getting back to Bond, however, I have to tell you about an extraordinary moment in time when James Bond trashed The Beatles. Seriously. It’s in this YouTube clip:
It’s from Goldfinger, which is another movie that has not aged at all well. Connery says:
"My dear girl, there are some things that just aren't done; such as drinking Dom Perignon '53 above the temperature of 38 degrees Fahrenheit. That's as bad as listening to the Beatles without earmuffs”.
If you’re watching the movie, you probably have to pause and say, “Wait, what? Did he just say what I thought he said?” He’s complaining about listening to the Beatles. And these aren’t the late-era Beatles, of Happiness Is A Warm Gun or Why Don’t We Do It In The Road? This is the band of I Want To Hold Your Hand and She Loves You and I Feel Fine. These are the fresh-faced kids who dressed in suits, bowed at the end of each performance, were a bit snarky to the press (“On this first visit, how did you find America?” “Turn left at Greenland”) and were controversial only because they wore their hair a little long. That’s the version of the Beatles that James Bond can’t listen to without earmuffs. Whoa.
James Bond is a fictional character, of course, so this means the movie producers thought that he would naturally say that, and, even more, thought the audience for Bond movies would respond to it. Amazing.
The Beatles released their movie A Hard Day’s Night a couple months earlier, which was surprisingly successful. Their next movie was Help!, which is essentially a Bond parody, though it feels more like an episode of The Monkees, but that’s another story.
There you have it: the random moment when James Bond dissed the Beatles. A truly bizarre episode that jumps out at me every time. If you want more details, check out this post.
Miscellaneous
Let me throw in a few items until I run out of room.
Niemann’s Lawsuit
First, remember how in several issues of this newsletter back in September / October I talked about the chess cheating scandal involving 19-year-old Hans Niemann and world champion Magnus Carlsen? My favorite online lawyer, known as LegalEagle on his various channels, released a video discussing the whole situation. It’s currently a Nebula First video, meaning it was released on the streaming platform Nebula before he puts it on YouTube.
Nebula is fantastic. For about $15/year (that’s a year, not a month), you get both Curiosity Stream and Nebula together, and it’s owned by the creators. I’m a big fan.
The tl;dr on this video is that while real lawyers will never commit themselves beyond “it depends,” the bottom line is that Niemann’s lawsuit is doomed. Seriously, he has no chance. But it ought to be fun to watch it play out, at least from a spectator sport point of view.
I’m sure that video will wind up on YouTube eventually, but if this turns out to be your needed motivation to subscribe to Nebula, that’s a good thing.
Utopia
Saw this on Mastodon:
That’s a really good point. I always liked the gag that said the most amazing innovation of Star Trek is that their video conferencing software always worked the first time, even with aliens they’d never met before, but this is good too.
My Superpower
This tweet really hit home for me.
Whenever that silly question comes up (“What is your superpower?”), I say that anytime I go into the kitchen, no matter where I stand, I’m in the way.
It’s a gift, but I promise to only use it for good.
True Friendship
Finally, there’s this:
Have a great week, everybody. :) In case you need the link, on Mastodon I’m at https://mastodon.social/@kenkousen .
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:
The Spring MVC Framework, an NFJS Virtual Workshop
Turned in the final text of Mockito Made Clear, which now goes to copyedit. Yay!
This week:
Android Development Bootcamp (week 1), on the O’Reilly Learning Platform
Getting Started with Spring and Spring Boot, ditto, in the APAC time zones.