Tales from the jar side: AssertJ and exceptions, Mockito book in beta, Help Your Boss Help You audiobook, Publishing scams, More about cheating in chess and elsewhere, and NASA clobbers an asteroid
I ordered a chicken and an egg at Amazon. I'll let you know.
Welcome, fellow jarheads, to Tales from the jar side, the Kousen IT newsletter, for the week of September 25 - October 2, 2022. This week I taught three NFJS Virtual Workshops: one on Spring Data and the Java Persistence API, one on JUnit 5, and one on Mockito. Also, my audiobook version of Help Your Boss Help You is now available through Pragmatic Programmers, and the second beta of my new book Mockito Made Clear was released.
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.
AssertJ and Exceptions
I spent a lot of time with Mockito this week. That’s partly because I taught an NFJS virtual workshop on it, and partly because the latest beta version of Mockito Made Clear came out this week. The web site at Pragmatic Programmers (linked to the book’s title in the previous sentence) doesn’t show any differences, but I expect that will change soon and I’ll have more to say when it does.
Since I was also teaching a Mockito class, I spent some time updating the GitHub repository for the book. One change I made was unrelated to Mockito directly. Instead it involved a code simplification that resulted from using the AssertJ testing library, which I’ve been ramping up on for some time now.
One of the advantages of using a stubbing tool like Mockito rather than writing your own fake classes is that it’s easier to model failure modes. One of my primary examples is my Astro system, where I access a RESTful web service that returns the astronauts currently in orbit, then group the data so I can see how many astronauts are aboard each craft. My integration test of the full system looks like:
The current output is:
3 astronauts aboard Tiangong
10 astronauts aboard ISS
and the test passes. I should mention that one of my reviewers pointed out that in my previous version of this test, I used
assertThat(number).isGreaterThan(0)
and that AssertJ already has a method called isPositive()
, so I’ve updated the test accordingly.
To test for a network failure, however, my previous version did this:
I thought this was pretty clever because I used the assertThrows
method from JUnit 5, which not only verifies the exception being thrown, but also returns the it, so I could also check its class and message. Sweet.
It turns out, however, that I can replace all the exception handling code with:
using the assertThatExceptionOfType
method (and the others chained from it) from AssertJ. That’s way simpler, and arguably easier to read as well. That’s the new version in my GitHub repository.
AssertJ is a huge library, and I’m still learning to use parts of it I didn’t know before.
New MMC Beta Available
Speaking of the new version of Mockito Made Clear, I spent a lot of time on this update. Among the changes are:
Several of the chapters have been almost completely rewritten.
All the examples that previously used features from Java 17 have been replaced with code that works with Java 11, or even Java 8. As one of my reviewers put it, “are you trying to teach the new features of Java 17, or teach the readers how to use Mockito?” That’s a good point. No need to add another hurdle for readers to overcome.
The previous beta used a class called
AddingMachine
to illustrate a dependency on ajava.util.List
. I did this in order to show examples that provided a mock list, which is something the Mockito documentation does a lot. That’s not a good idea. One of the general principles of Mockito is “don’t mock classes you don’t own,” and even the Mockito documentation says don’t mock a list, right before they do it anyway. My example was intended to “fix” the documentation, by showing how and why you might want to mock a list. A reviewer said, “if you want to fix the documentation, just go and fix the documentation.” Right. It’s not my book’s job to do that, so the example has been removed.I replaced it with a
HelloMockito
example, which eventually expands into aPersonService
/PersonRepository
example that grows throughout the book.
I think this version of the book is much better and much closer to the final product. Hopefully readers will agree.
If you decide to buy the book at the Pragmatic Programmers website, please use the (new) coupon code kkmockito35 for a 35% discount.
I admit I still have one missing subsection. Mockito lets you mock a constructor, though the syntax is a bit awkward. My problem is, I don’t know why you’d ever want to do that. The example they use in the documentation isn’t terribly motivating, and while I could just show the syntax and apply it to my own example, I’d rather explain what drove me to do it, rather than just include it for completeness. If you have any ideas, please let me know and I’ll add you to the Acknowledgements. :)
HYBHY Audiobook Available
My book Help Your Boss Help You is a so-called “soft skills” book, meaning it doesn’t contain any code. That makes it ideal for an audiobook. For a while, the publisher (Pragmatic Programmers again) had a handful of audiobooks listed on their web site, but when it came time to release my (text) version, they decided as a company not to do audiobooks any more. They were kind enough to release the audio rights to me, however, so I recorded it myself and released it on Audible last November.
I decided at the time to give Amazon (who owns Audible, in case you didn’t know) non-exclusive rights. That gave up a good share of the royalties (as I recall, that reduced it from 40% down to 25%), but I figured I might place the book elsewhere and I didn’t expect a huge number of sales anyway.
A couple months ago, Pragmatic Programmers changed their mind again and decided they were willing to sell audiobooks through their site. I therefore contacted them and asked if they wanted mine, which was, of course, already finished. They agreed.
Now the audiobook is available there as well. It was the primary subject of this week’s PragProg newsletter, where they also announced that if you buy both the audiobook and the ebook, use the coupon code KKMANAGEBUNDLE for a 40% discount. Here’s the announcement on Medium as well.
Speaking of Publishing…
You may know the name Dan Olsen, or more likely his YouTube channel (Folding Ideas) or his Twitter handle, @FoldableHuman. Earlier this year he created a video that was the ultimate takedown of cryptocurrency scams, called Line Goes Up - The Problem with NFTs.
It was really long (about 2 hours and 18 minutes), but it’s fantastic and completely went viral, with over 9.2 million views so far. I watched it over several sessions, and at some point I want to watch it again.
As you might expect for someone who publishes at that length, he doesn’t publish often. This week, however, he released a new video, called Contrepreneurs: The Mikkelsen Twins:
This one is only an hour and 15 minutes, but it involves a subject I care about: the publishing industry. The Mikkelsen Twins are two brothers who are trying to sell people on the idea of earning passive income by publishing tons of books you actual don’t have to write.
The (more or less) legal scam goes something like this:
Search Amazon and Audible (which they refer to as Amazon’s “best kept secret!” — sigh) for popular keywords.
String a few keywords together and write a couple sentence description of what your book will be about.
Hire a freelancer to ghostwrite the book for you.
Hire another freelancer to record the book for you.
Hire a publishing firm to package the text with cover art and other items.
Publish the book to Audible.
Repeat.
Of course, all of this is made easier if you buy their course describing the details, and work with the publishing company they recommend. As you might expect, there are upsales throughout the process, including access to a “private Facebook group” that clearly exists to trade favorable comments in the online listings, which already violates their terms of service, but who cares about those details?
For all their blather, these guys really are amateurs, as Olsen’s video shows. They show an image of what is supposed to be their own current catalog of roughly sixty books, but if you look closely you’ll see that many of the covers are duplicates and most have already been taken down or are not available. They claim that’s because they’re so busy they haven’t gotten around to publishing them yet. Yeah, sure.
Olsen in his video suggests that the brothers tried to publish alternate language editions of their books by simply running them through Google Translate, and that this was too much even for the vast cesspool that is Amazon, and they were banned and all their books removed.
The interesting part is how the entire scheme is an exploitation of the worst parts of the gig economy, especially the part where they hire freelancers to ghostwrite the book. Olsen decided to go through the process himself, hiring someone to write a ridiculous book called Treating Epilepsy with Self Hypnosis, by Brad Default (which he gave a French pronunciation). He complimented the poor writer who the publishing company found to write it through a freelance bidding process. The guy cranked out about 30K words in just under a month. Olsen notes that the standard rate for ghostwriters is about 10 cents a word, but for the package Olsen bought (which cost him around $600 for both writing and editing), the writer was paid about a penny a word. Yikes.
Then Olsen decided to see what it’s like to write at that pace himself. He wrote his own book called A Skeptic’s Guide to Hypnosis, a 25K word book which he tried to write in 25 days. He describes what we in the IT industry call a death march in great detail. You can almost watch his soul dying in real time as he writes a very low quality, very repetitive book.
The only way this model works, of course, is if it attracts a continual stream of victims to enroll in the courses and hire the publishing company (the one “recommended” was The Urban Writers), and they squeeze the contractor rates to the bone at every stage. As I say, the worst of the gig economy in all its forms.
Of course, the real question that any of my readers in the publishing industry are wondering is, did this disaster make any money? Olsen published his own self-written book, but didn’t do any link spam or other marketing. In the month since he published it, his book has sold exactly one copy. That’s the real problem — despite the sales pitch, all you’re producing is ebook spam, and there’s not a huge market for that.
Olsen also points out that the Mikkelsen Twins aren’t really selling this approach. They’ve already tried it and failed. They’re selling courses to teach you how to do it, with massively overhyped promises that are almost certain to put you into debt.
As a final note, I’m a technology person. What I’m wondering is, how long before you can use an artificial intelligence program to eliminate the writer entirely? You could probably produce garbage now, but in five years I wonder how close that garbage will be to what an overworked, underpaid, exhausted writer could churn out on any given bizarre topic, and the program could probably do it in a day, if not an hour.
Late-stage predatory capitalism is wonderful, right?
More on Cheating in Chess, Poker, and … Fishing?
The last few issues of this newsletter included updates on the accusations made by chess world champion Magnus Carlsen that 19-year-old GM Hans Niemann was cheating, and Magnus refused to play him. This week, as promised, Magnus released a statement:
Here is Magnus’s tweet about it:
You can read the complete statement, but basically he says that Niemann “has cheated more — and more recently — than he has publicly admitted,” among other things. He also linked Niemann to an admitted cheater, GM Maxim Dlugy, whose own story is (of course) complicated.
In addition, a YouTuber named Yosha Iglesias released another analysis of Niemann’s games using a tool that comes with the ChessBase program:
The tool she used estimates how often a player’s moves match those suggested by a computer. She claims that Magnus himself averages around 70%, and that Bobby Fischer at his peak did about the same. While it’s possible to do much better than that on an individual game, it’s rare if you’re not playing a known drawish line, or simply converting a big advantage against an inferior opponent.
She then claimed that in analyzing Hans’s games, he actually hit 100% a dozen times (!) over the past couple of years. As you might imagine, that too went viral.
The problem is, a solid assessment of indirect evidence (as opposed to an actual admission of guilt, which hasn’t happened) requires understanding of mathematical statistics, including comparisons to others and getting a big enough sample size to be significant. So far, I haven’t heard from anyone who is actually qualified to make those assessments. Instead you have a bunch of guys who are good at one thing (chess) arguing about knowledge in a different area (statistics), blithely assuming their expertise in one area makes them good in the other.
That’s my queue to say that I have no idea what any of that evidence really means. It sounds bad, but the whole point of statistics is to see through human biases to detect actual significance rather than perceived significance. In other words, let’s wait and see.
Meanwhile, a famous poker player alleged he was “clearly cheated” in a cash game, and a fishing contest was rocked by cheating charges after weights were found in winning catches.
Look, let’s just not, okay?
Cool News: We Shot A Moon
NASA’s DART mission clobbered Dimorphos, a moon of Didymos:
That was fun. While the video includes a few images from the impact, I haven’t seen any analyses yet about how much the orbit of the moon was changed. Hopefully it was enough to make it clear we won’t need Bruce Willis and the boys in the future.
(I wasn’t going to include this, but I can’t help myself:
Not sure what Batman (Ben Affleck) is doing hanging out with an elf (Liv Tyler), but okay. Now try to get that song out of your head.)
The best tweet about the impact I saw (which I can’t find, sorry) showed this image from the mission, which was the last picture the probe took before impact:
The tweet then said something like, “Please stop showing square images of the impact. It makes me worry we provoked a Borg ship.”
Awesome.
Tweets Expressing Truth
I’ve felt this way about TSA PreCheck for years:
In a nutshell. The user experiences on both are so bad that people will pay money to avoid them. I just keep my head down when going through TSA security theater. Otherwise I’ll say something (like, “I’d have to be the world’s stupidest terrorist to get caught this way”) and nothing good could come of that.
Regarding YouTube Premium, I’m already a Google Business user, so premium comes with it, thank goodness.
Here’s some excellent advice (or is it?):
Wow, yeah. I feel like the next time I’m asked for advice on a (Pretend To Be An) Expert Panel, I should drag out that gem. As they say, your mileage may vary.
Finally, after all the discussions of statistical independence and significance, some people are just lucky:
Have a great 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:
Spring Data and the Java Persistence API, an NFJS virtual workshop
Java Testing, Part 2: Mocks, Stubs, and Spies with Mockito, ditto again
This week:
Two presentations at ApacheCon in New Orleans, LA
<Rimshot>