Tales from the jar side: WireMock tests, Movies to know me, Get Back comments, and good tweets
Dad joke: They're developing a mind-controlled air freshener. It makes scents when you think about it. (rimshot)
Welcome, fellow jarheads, to Tales from the jar side, the Kousen IT newsletter, for the week of December 26 — January 2, 2021. This week I had no classes, but I did a fair amount of writing and learned about the WireMock project.
If you wish to become a jarhead, subscribe using this button:
I should also mention that when my newsletter becomes too long for email (which is happening a lot these days, sorry), you can always see the full version online. If you ever miss an issue, the entire archive is there as well, and everything is free.
WireMock Tests
Last week I talked about an example project I’ve been building to talk about Mockito, and identified a part of the project where I shouldn’t do any mocks. My project uses a service to pull data from a gateway. The gateway accesses a restful web service that produces JSON data and converts it to Java records. The service then processes those records to give me a map of spacecraft to the number of astronauts aboard each.
When I call the getAstroData method on my AstroService, the result is:
7 astronauts aboard ISS
3 astronauts aboard Shenzhou 13
I have several tests for the AstroService, but the interesting issue was how to test the AstroGateway. The gateway makes the remote network call and converts the results, so its behavior is dependent on the networking library and on the JSON parser I use. My main test, therefore, is an integration test:
To make this into a true unit test, I would need to provide fake objects for the networking parts (currently, HttpClient, HttpRequest, and HttpResponse from Java’s standard library) and the JSON parser (currently the JsonMapper class from Jackson 2). That seemed like a lot of work, especially because the methods I had to mock might lead to additional mocks down the road, and would be tied to those specific implementations.
When I looked at the How to write good tests entry on the Mockito wiki page, the recommendation in cases like that is:
Don’t mock a type you don’t own.
I found that very interesting, and said so last week.
One awesome jarhead (but I repeat myself) called Marcin Erdmann sent me a message in reply. He pointed out (I’m paraphrasing) that one thing I could do was to create a mock server that produced the JSON data I wanted. He recommended the WireMock project, which is specifically designed to do that.
I’d heard about WireMock for years, but hadn’t used it. Marcin is an outstanding developer and is very active in the Groovy community, with contributions to Groovy, Spock, Ratpack, Geb (where he’s the lead developer), and more (see his GitHub repository here), so I was already going to take his recommendations seriously even before I reminded myself about his accomplishments. In fact, I’m happy I followed up before checking his details, because they’re rather intimidating. :)
WireMock, like many open source projects, is modern, powerful, and has documentation whose quality is mixed to say the least. Most of the examples I found online were for older versions, which happens a lot on active projects. It took me longer than I think it should have to figure out what to do (I had to dig into the source code a bit), but I eventually did.
Here’s my new, simple WiremockGatewayTest:
(Did you notice the astronauts? “Open the pod bay doors, HAL.” “I’m afraid I can’t do that, Dave.” More about movies, science fiction and otherwise, below.)
The code looks more complicated than it is. The @WireMockTest annotation starts up a mock server for me at the beginning, runs the tests, and shuts down the server when they’re done. I configure the server inside my @BeforeEach method, using the stubFor method from WireMock to respond to an HTTP GET request. The server responds with a success and sends the JSON data shown.
(Note I could have simplified that by putting the JSON data in a file and having the server send its contents, but I couldn’t resist the urge to use a Java TextBlock. Plus that way I could look at the data while writing my test.)
That’s all it took. In my test, I use an argument of type WireMockRuntimeInfo, which gives me the base URL WireMock chose to start up the server. All I needed to do was to modify my AstroGateway so it took a String URL as an argument, make the getResponse call, and the rest is just checking the details.
The assertions, by the way, are from the AssertJ testing library. I’m using this project as an excuse to learn more about that library, which is very popular among the core Spring development team. That’s where I get calls like assertThat, extracting, and containsExactly.
The refactored AstroGateway and the new tests are in my GitHub repository, as usual.
Incidentally, it’s a bad idea to lie to HAL. It confuses him, and the results aren’t pretty.
It is simply amazing how much of that movie (2001: A Space Odyssey, in the wildly unlikely case you didn’t get the reference from 1968 (!)) still holds up. For all his brilliance, Arthur C. Clark wasn’t great at writing characters. After all, who, if anybody, do you remember from that movie? Probably only HAL, or maybe this scene:
I must admit, one of the best things about working on a project like this is that I get to pick examples from different science fiction movies and TV shows for my mock objects. So far I’ve used Babylon 5 (of course), the Rocinante (from The Expanse), the USS Cerritos (from Star Trek: Lower Decks), the Nostromo (poor Ellen Ripley — avoid LV-426 if you can), the Jupiter 2, Discovery One (see above) and Voyager. I haven’t used the Millennium Falcon, Serenity, or Spaceball I yet, but I will.
Movies To Know Me
Speaking of movies, I saw this meme make the rounds recently:
I didn’t reply, but I’ve been giving this some thought, and this seems to be the week for introspection. With that in mind, here is my preliminary list, in no particular order, but with some explanations:
Mystery Men. I still think this is one of the great overlooked movies of the 90s. Mr. Furious. The Bowler. The Blue Raja. Casanova Frankenstein, which is one of the greatest villain names ever. Plus this line from The Shoveler: “We’re on a blind date with destiny, and it looks like she ordered the lobster.”
Every line from the Sphinx is priceless. “He who questions training only trains himself at asking questions.” “When you can balance a tack hammer on your head, you can head off your foes with a balanced attack.” And, best of all, “We’re number one! All others are number two, or lower.” Truer words were never spoken.
Addams Family Values. Christina Ricci as Wednesday Addams is brilliant, and Joan Cusack as Debbie Jellinsky is a treasure.
This scene:
Desk sergeant: [after being asked to arrest Debbie] Just leave, leave quietly, leave now. Don't make me call Ringling Brothers.
Gomez: [shouting] Has the planet gone mad? My brother, passion's hostage. I seek justice - denied! I shall not submit! I shall conquer! I shall rise! My name is Gomez Addams, and I have seen evil!
[Grandmama waves Pubert in the air]
Gomez: I have seen horror!
[Lurch waves]
Gomez: I have seen the unholy maggots which feast in the dark recesses of the human soul!
Morticia: They're at camp.
Gomez: I have seen all this, officer. But until today, I had never seen... *you*!
Desk sergeant: Hook him, book him, cook him. *Now*!
Also, the movie came out when my son was barely a year old. When my wife and I saw it in the theater, this scene cracked us up:
[Morticia is reading "The Cat in the Hat" to Pubert, who has golden curls and rosy cheeks]
Morticia: Are you enjoying this?
[sadly]
Morticia: To think, a child of mine!
[turns the page]
Morticia: "I know it is wet, and the sun is not sunny. But we can have lots of good fun... that is funny."
[flipping to the last page]
Morticia: Oh, no. He lives.
Heaven Can Wait. My favorite movie growing up. Warren Beatty, QB for the Los Angeles Rams, dies prematurely because Buck Owens thought his accident was going to be too painful, so James Mason puts him back in the body of a billionaire who buys the team. Of course, the billionaire was murdered by his wife Dyan Cannon and his personal private secretary Charles Grodin. Beatty falls in love with Julie Christie.
Seriously, see it if you can. I practically have the whole movie memorized.
The Adventures of Buckaroo Banzai: Across the Eighth Dimension. I was living in Princeton, NJ, when this movie came out, so all the New Jersey references were a riot. Peter Weller is wonderful. John Lithgow as Lord John Whorfin at his maniacal best. All the lectroids had a first name of John. A very young Ellen Barkin as Penny Priddy. Christopher Lloyd as John Bigbooté. Jeff Goldblum as New Jersey. Clancy Brown, Dan Hedaya, Robert Ito, and more. “Declaration of War: The Short Form.” The fact that (spoiler) the black lectroids broke through the dimension barrier on Halloween in 1938 and when Orson Welles said there was an invasion from Mars, they forced him to cover it up. Then they formed a defense contractor called Yoyodyne Propulsion Systems in Grover’s Mill, NJ.
You have to have the right frame of mind to really appreciate this movie, and I loved it.
Spider-Man: Into the Spider-Verse. By far the best superhero movie ever made, and it’s not even close.
Many people in my undergrad dorm were into comic books, so I started collecting them (Marvel, not DC) as well and did so through much of the 80s. When they brought Phoenix from X-Men back yet again I finally gave up. My favorite book was always X-Men, but those movies range from adequate to awful. Into the Spider-Verse is the closest any comic book movie has come to the wonder of the original books.
A few hundred of those old comics are still sitting in bags inside boxes in my basement, probably worth nothing.
Monty Python and the Holy Grail. One of the all-time most quotable movies. Arthur: “I am your king!” Old woman: “Well, I didn’t vote for you.” Peasant: “She turned me into a newt!” Sir Gawain: “A newt?” Peasant: “I got better.” The whole scene with the Black Knight. Arthur: “Your whole arms off!” Knight: “It’s but a scratch.” Arthur: “You have no arms left!” Knight: “It’s just a flesh wound.” Answering the bridge keeper. Keeper: “What is your favorite color?” Sir Galahad: “Blue. No, green! Aaahh!” Sir Robin, who bravely ran away. The killer rabbit. Brother Maynard: “Lobbest thou thy Holy Hand Grenade of Antioch towards thy foe, who, being naughty in my sight, shall snuff it.”
The Rocky Horror Picture Show. Saw this at a midnight showing in Boston in 1979 at age 17, and was appropriately shocked. Went back the next night. Still own the soundtrack. Fell in love with Susan Sarandon. Had no idea what to make of Tim Curry, but I could tell he was amazing. Loved Riff-Raff. “What, Meat Loaf again?” Sure, it drags a bit in the third act (especially at 2 in the morning) and it all seems pretty tame now, but I enjoyed it at the time and still appreciate it now.
The Caine Mutiny. Had a huge impact on me when I first saw it in my 20s, and I still watch it every time it comes on. Formed the basis of a lot of my Help Your Boss Help You book.
Animal House. The first R-rated movie I saw in a theater, and I picked a classic. Great performances all around. Bluto: “Was it over when the Germans bombed Pearl Harbor?” Otter: “Germans?” Boon: “Forget it, he’s rolling.” Toga party. Double secret probation. Otis Day and the Knights. Senator John Blutarsky. Bluto smashing the guitar (“Sorry”). If you visit Universal Studios, ask for Babs, though I believe they have discontinued that promotion by now.
Mr. Holland’s Opus. I was still a research scientist when I saw this movie in the theaters, and it convinced me to re-train as a teacher. I attended the Connecticut Alternate Route to Certification program the next summer, which allowed professionals without a teaching degree to qualify to be hired by CT high schools. Did some substitute teaching, but ultimately decided being a high school teacher wasn’t for me (the fact that the resulting salary drop meant I probably would have had to declare bankruptcy at the same time also had something to do it). Still, I was prepared and waiting when the opportunity to teach technical training classes came along, and this movie was the catalyst.
Incidentally, one my first ever blog posts wonders why Rowena didn’t come back for Mr. Holland’s farewell party. I get comments on that to this day, and I still don’t have a good answer.
The Matrix. I loved the original so much I bought it on DVD before I owned a DVD player. Shame about the sequels. Resurrections was okay.
Amadeus. I know its resemblance to actual history is tenuous at best, but both F. Murray Abraham and Tom Hulce were fantastic as Salieri and Mozart. The absurd, ahistorical, obnoxious laugh by Mozart as the dramatic “mocking laughter of the gods” at Salieri makes perfect dramatic sense. Of course the whole notion of Salieri destroying and ultimately killing Mozart is ridiculous, but I enjoyed the rivalry anyway. Apparently on Broadway the roles were played by Ian McKellen and Tim Curry. I would have loved to see that.
Incidentally, I have the extended cut of the movie, and I’m glad they cut every additional scene in it.
Back in the early 90s, I sang the tenor role in the quartet as part of a Mozart Requiem (one of my few “professional” roles), so I knew all the music by heart. I also loved the theme of talent recognizing (and envying) genius, though I believe genius is obvious to lots of people.
(Yeah, for those keeping count that’s twelve movies instead of ten, and I could have added several more. What about Groundhog Day? Or Caddyshack? Or even the original Star Wars? Oh well. Enough is enough.)
Speaking of genius, that reminds me Peter Jackson’s The Beatles: Get Back documentary and our own, modern day Mozart: Paul McCartney. My wife and I watched all 8+ hours. Basically, we were the target audience.
I was too young for the initial bout of Beatlemania. I became a Beatles fan in late high school and college, and collected all the McCartney albums after the breakup, from McCartney (1970) to Press to Play (1989). With every album, my reaction was always:
(Amazement) Wow, how could anybody write this?
(Horror) Wow, how could anybody write this?
That’s the thing about Sir Paul. To this day, he seems to feel that he should publish everything he writes, and that includes some really bad stuff. Every time he released an album, I’d say, “Please, Paul, don’t embarrass me for buying this,” and there would be something wonderful and something horrible every time.
In the documentary, we see him at the peak of his powers, simply oozing talent. One moment he’s creating the song Get Back out of nothing live on camera, then he’s coming up with The Long and Winding Road, Let It Be, and more. It’s all part of an extended burst of creativity that would have been legendary if the original director hadn’t had it in for him. I think this tweet sums it up nicely:
That’s the frustrating thing about Paul. He’s got so much talent that you keep waiting for the good songs to become great, or great ones to become phenomenal. Sure, he could write fun pop tunes like Listen To What The Man Said (“So won’t you listen to what the man said? He said, do do do, do do do do do.” Wait, Paul, what did the many actually say? That’s a placeholder. That line isn’t supposed to be in the final version, is it?), Let 'Em In, Silly Love Songs, With A Little Luck, and even Live And Let Die. He can also be experimental, like with Uncle Albert / Admiral Halsey (seriously, there’s like four different themes in there, each of which could have been the basis of a hit, but Paul happily uses and discards them one by one in a veritable orgy of waste), Band On The Run, Jet (“I thought the major was a lady suffragette.” Huh? I have questions), and one of my lesser-known deep-cut favorites, Nineteen Hundred And Eighty Five. But where is Paul’s Don Giovanni? For that matter, where is his Requiem? I know he has it in him, or at least I think he does. It’s probably time to stop waiting, though.
Sir Paul is 79 years old. When he passes away, it’s going to hit me really hard, and the retrospective look at his music will play songs all day long and those are just the hits. Best to appreciate him while we still can.
A few more random thoughts on Get Back:
The director of the original Let It Be film must have really been angry with Paul. Let It Be makes him look awful, bossy, and joyless, and doesn’t even include the creation of the song Get Back, which may be the most memorable part of the documentary. I have no idea what the original director’s problem was.
Judging by the documentary, Yoko was a total non-factor in the breakup of the Beatles, which is completely against the popular conception. During the film, she just sat there quietly. She interrupted only once, after she got the call to announce her divorce was final, and all four Beatles congratulated her.
One scene does remind us, though, to never let her near an open mic.
The parts where each Beatle played with little Heather (Linda McCartney’s little daughter) were charming.
Billy Preston never got he credit he deserved, and the recording of the rooftop concert criminally leaves him out. He was crucial to everything. Again I have no idea what the original director was thinking.
George definitely needed his own solo album. Probably Paul and John did as well. These days that would have been a no-brainer, without having to break up the band to do it. Would that have kept them together? I doubt it. John had already fallen in love with Allen Klein, and there was no overcoming that.
It’s long, and I doubt I’ll watch it again, but I really enjoyed it.
Good Tweets
A couple more tweets to wrap things up. This tweet thread is really interesting:
JMS was way ahead of the pandemic when it first started, and he carefully follows the medical literature. His opinions are always well-informed. His tweet storm this week basically says that the hyper-contagiousness of the Omicron variant combined with the mild nature of the associated sickness and the quick way it burns itself out means we may be done with the pandemic by March. It’s the beginning of the end. I hope he’s right.
Next, Batman saves the world:
Not what you want to see in your space telescope:
What is apparently becoming a weekly critical comment about NFTs:
On a similar subject, here’s an excellent summary of the disastrous state of cryptocurrencies:
Finally, this is entertaining:
Happy New Year 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:
Work on my Mockito-related project.
Work on Intro Java materials for a private client.
This week:
No classes, before the online work kicks in again.
Work on my Mockito-related project.
Work on Intro Java materials for a private client.