Writing tests for Instant.now and other current time functions

When using Instant.now(), new Date() or other methods that fetch the current time testing becomes a hassle since you can’t mock static methods easily and therefore can’t test a certain date but only use the current one. A good solution to this problem is using an interface that supplies you with current time and never call these methods directly. This way you can mock the interface in your tests and use a fixed time. I’ll show an example beneath.

Read More

Custom annotations with RESTEasy and Dynamic Feature

Custom annotations on endpoint's methods will let you run code before the endpoint method. This is good for example restricting a user from using a certain endpoint and returning 403 Forbidden before it even gets there like in this tutorial, making the code cleaner and easier to read.

Read More

Connecting a Christmas snowglobe to your Raspberry Pi

Christmas is around the corner and it is time for some geeky Christmas Crafts! Got an RaspberryPi from a hack night at iZettle and wanted to make something fun out of it, decided on "Git merge activated snowglobe". If the name doesn't say it all, it's an electronic snowglobe that is gonna start "snowing" and playing christmas music each time someone merges a pull request on Github.

Read More