Tales from the jar side: Mocking static methods, Notable people near me, and Pokémon cards through the ages via AI
Did you hear about the restaurant called Karma? There's no menu. You get what you deserve.
Welcome, fellow jarheads, to Tales from the jar side, the Kousen IT newsletter, for the week of July 17 - 24, 2022. This week I taught Week 2 of my Spring and Spring Boot in 3 Weeks class on the O’Reilly Learning Platform and my Spring MVC course as an NFJS Virtual Workshop.
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.
Mockito Made Clear
I spent a lot of time revising my latest book, Mockito Made Clear, currently in beta from Pragmatic Programmers. I’m starting to be happy with it.
NOTE: Use the coupon code mockito_medium_35 for a 35% discount!
I’ll have much more to say about the book as we get closer to the final release, but I’ll say this much now:
I like the coverage, which is a nice mix of old and newer features.
I wish I’d had this book when I was first learning the framework, which is a good sign.
The documentation for Mockito is not great. Arguably I should do something about that (it is, after all, an open source project), and maybe I will after my book is done.
To mention one random, if overly complicated, item, Mockito can mock static methods now with an odd syntax. For example, I have a class called BioService
that accesses Wikipedia and downloads articles. It looks like this:
The BioService
class invokes a static method called getWikipediaExtract
in a class I wrote called WikiUtil
, which does the actual networking and parsing of the downloaded text.
If I want to test the getBios
method, I need to mock getWikipediaExtract
. Here’s what the resulting test looks like:
That’s a mouthful. The notable parts are:
The
MockedStatic
instance is created within a try-with-resources block, so it’s closed automatically. That turns out to be important.The
when/thenAnswer
methods are the same as on regular mocks.The
thenAnswer
method lets you return an output based on the input. Here it returns “Bio for Anita Borg”, etc.The actual test is that for four inputs, we got back four bios.
This version of the
verify
method takes an argument of typeMockedStatic.Verification
, which is an interface with a single abstract method calledapply
that takes no arguments and returns nothing, so I can use the provided expression lambda for it.
This example, like all the others, is in the GitHub repository for the book.
Sod Poodles Update
Last week I mentioned that I was so taken with the name of the minor league baseball team in Amarillo, TX, the Sod Poodles, that I ordered one of their T-shirts. Sure enough, the shirt arrived this week. My wife took this picture:
I like it, but as with all my pictures these days, I often wonder how I would look in the Matrix.
Morpheus (to Neo): Your appearance now is what we call residual self image. It is the mental projection of your digital self.
All I can say is that my residual self image is thinner and has more hair. Nice T-shirt, though.
Notable People Near Me
One of the links that made the rounds this week was the Notable People map. If you click on it, you’ll see a zoomable map that contains data from Wikipedia and Wikidata to show the birthplaces of “notable” people around the world. The place names have been replaced by the most famous person to be born in that area.
As I’ve mentioned in earlier newsletters, I live in Marlborough, CT, a town small enough that we celebrated the arrival of our two (2) stoplights.
I’m reminded of Dudley Moore in the movie Arthur, when describing “Princess” Gloria (a call girl he just picked up) to his relatives in an elegant restaurant:
It’s a terribly small country. Rhode Island could beat the crap out of it in a war. That’s how small it is.
It’s 85 cents in a cab from one end to the other. This is NOT a big place.
They recently had the whole country carpeted. I’m talking SMALL.
Classic movie, and a great performance by Dudley Moore, matched only by Sir John Gielgud as Hobson, the butler. Liza Minnelli is good, too. For the record, the remake in 2011 featuring Russell Brand never happened.
If you open the map link on an actual computer (as opposed to a mobile device), you can easily zoom in to any location in the world. Here’s a map showing I live about halfway in between Katherine Hepburn and Benedict Arnold:
Apparently the most famous person from near me is A. J. Pollock, a Major League baseball player (center fielder) for the Chicago White Sox, who was born in Hebron, CT (about 15 minutes away) and went to RHAM (Regional Hebron, Andover, Marlborough) High School, like my son. He won a Gold Glove in 2015, no less. (Pollock, not my son.)
Never heard of him, though I guess I’ll keep an eye out now.
Have fun browsing around. I wasn’t able to zoom on my phone, but I didn’t spend a lot of time trying. It worked just fine in my browser, though.
Pokémon Cards By DALL-E
This one takes a bit of explanation.
Part 1: DALL-E
There’s an AI-driven image generator called DALL-E 2. It’s described as “a new AI system that can create realistic images and art from a description in natural language.” The idea is that you type in a phrase, and it generates a selection of images that fit the phrase.
The system was trained on “hundreds of millions of captioned images on the Internet,” but they’ve put “guardrails” in place to keep the generated images from violating their content policy. If this all sounds interesting to you, you can sign up for the waitlist for their beta here.
I’m only mildly interested. I tried out the much reduced mobile app, known as Craiyon (formerly DALL-E Mini) and wasn’t much impressed. Of course, they’re also planning to open the system to people who want it, for a small fee.
Part 2: Randall Munroe and XKCD
If you spend any time in the IT world, eventually you run across the webcomic XKCD, created by Randall Munroe. Randall releases a new comic every day, and they’re really funny if you get the references. Here’s a recent one:
The mouse-over text says, “These neutrinos were freshly produced by a local source just eight minutes ago,” which — if you get the reference — is referring to the Sun.
Randall also wrote a book called What If? Serious Scientific Answers to Absurd Hypothetical Questions that was incredibly successful. In it, he talks about what would happen in incredibly unlikely scenarios, like this question he received:
My son (5y) asked me today: If there were a kind of a fireman's pole from the Moon down to the Earth, how long would it take to slide all the way from the Moon to the Earth?
See this link for his answer, which is as wild as you would expect. I browsed through the book in hardcover (seriously) at my local Barnes & Noble, from which I had to take a picture of this image (which I can’t find, so here’s one from the Internet):
As the wolf said, “Dude.” When he’s funny, he’s really, really funny.
Part 3: Bringing Them Together
It seems that Randall Munroe is part of the beta of DALL-E 2, and if anyone can push that technology to it’s logical, but ridiculous, limit, it’s him. I saw a Twitter thread that started harmlessly enough:
He then followed up with the same prompt from the 2000s, 90s, 80’s, 70’s, 60’s, 50’s, 40’s:
Of course he kept going.
Let’s skip a bit:
Skip a bit more:
He kept going, because of course he did:
Just when you thought he was done:
Eventually he wound up all the way back to the Big Bang. Check out the thread for the details.
I must admit, it’s tweet threads like that the justify the existence of AI tools, Twitter, and maybe even the Internet itself.
As Long As I’m Already Over My Length Limit
Khan!!
Have a good week, everybody.
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:
Week 2 of Spring and Spring Boot in 3 Weeks, on the O’Reilly Learning Platform
The Spring MVC Framework, an NFJS Virtual Workshop
This week:
Week 3 of Spring and Spring Boot in 3 Weeks, on the O’Reilly Learning Platform