Annotation Processor Testing
Creating an Annotation Processor means that you will likely also want to add tests, but this can be tricky since the runtime is the compilation process itself, meaning that you will have to invoke a compilation step during test execution. In this post I’d like to outline what you can do to ensure proper test coverage.
Annotation Processing
In Java, Annotations allow compile-time metaprogramming, meaning that it allows creating code based on other source code. I use this in Java - Lenses to create auxiliary classes for annotated records. These contain various instances and functions which need the type information of the annotated records, meaning that there is no way to this directly in the source code itself.
Ads on your Blog site
For a side project I had to add some advertisements, and while I was at it, I also added Google Ads onto my blog. Not so much as to make money (I don’t expect a lot of traffic here) but to learn how to do it in various environments. It can be a very useful skill if you are running a free website to cover hosting or if you want to provide this as a service to others.
Combining htmx with Bootstrap
Using htmx with Bootstrap is mostly a seamless experience, but I’ve encountered a few places where a bit of extra effort is needed to smooth everything out. Since I could not find a concise description of the required fix, I’ve created this quick post to outline the issue and the remedy.
Bootstrap
Since I work mostly on business-to-business administrative web applications, I need to build many interfaces, yet a slick or custom styling is usually not the highest priority. We need a well rounded set of standard component that enables data presentation with clarity. So let’s just pretend we still live in the ’10s and use Bootstrap. A benefit is that all the scraping-trained AI’s are now all Bootstrap experts, meaning that stamping out entire dashboards is trivial.
Json Unit Testing
Many applications have APIs consuming and returning JSON. If you do not cover the expected inputs and output of the API you risk introducing unintentional changes. Luckily it is not hard to create these valuable test cases. If you have types that are used both as symmetrical inputs and outputs this test pattern will provide full coverage and give you utility methods for other tests as well.
For this example I’ll be using a type Task
having just a name
and a description
field, both String
s:
j2html
For my full-stack projects I like to use Server-Side rendering with Javalin, j2html and htmx. Together, these libraries allow you to write interactive full-stack web applications in vanilla java. In this post I’d like to explain how the j2html library fits in this setup, go over a few benefits, and link a converter that I wrote to make building the user interface easier.
Server Side Rendering
While the last decade was dominated by client-side frameworks, many applications could perhaps have saved a lot of development time by using server-side rendering. This means that the resulting html is built on the server, including its data, styling and behaviour.
Lenses
Immutability
Using immutable types has a number of benefits. Since it eliminates mutation, it makes code easier to reason about. Also, it eliminates concurrent modification problems, thereby unlocking a lot of performance improvement opportunities. Java originally was fully Object-Oriented but it adapted to other paradigms. The language itself still lacks some features that makes it convenient to work with immutable data. In this post I’d like to show what can currently be done in vanilla Java and show a powerful concept to transform immutable data.
Awaitility
Writing tests on asynchronous code can be a challenge. Given an asynchronous process to test, we may try to use custom code to wait for the process to finish or reach a certain state. This may cause us to end up with tests that are flaky, slow, or hard to understand. It is not uncommon for legacy projects to have these setups, and perhaps they can be improved a little.
The Brainmade Mark
Generative models (colloquially: AI) are here and they will never leave again. The quality of generated material, especially text, has improved enough that has become hard to tell if it was (partially) generated by AI.
Since no rule exists mandating an indication what content is AI-generated, we are faced with choosing between not caring if something was artificially generated, assuming everything is AI-generated, or becoming experts at differentiating between AI and human made content, a battle which AI will likely win.
Link Swapping
If you’re on a website and you see a link, how do you figure out where that link will take you? Just hover over it right? Try to hovering this Totally Legitimate Link. If you dare, click it.
If you’ve clicked the link, welcome back! Refresh the page to have the link in it’s initial state again. Not everything is what it seems, and this is also very true when browsing the web.
Hugo
This website was made using Hugo, following the quick start tutorial and iterating from there. So far its been a lot of fun, and gradually expanding website functionality has been a very natural process.
Content
I use Obsidian to create my content, allowing me to write using MarkDown. Using Obsidian Linter I can automatically insert YAML properties that Hugo will pick up as metadata. Using this setup there is a nice separation between site content and site functionality.