Author: David

Loading test data with ScalaTest + Play

comment 1
Dev

The ScalaTest + Play library provides a couple of useful traits for when your ScalaTest Play Framework functional tests need a running application for context. The OneAppPerSuite trait will share the same Application instance across all tests in a class whereas the OneAppPerTest trait gives each test its own Application instance. These traits will ensure you have a running application for your tests but if you want to test code that operates on a database […]

A systemd unit file for Play Framework

comments 8
Ops

New for Ubuntu 16.04 (Xenial Xerus) is systemd which replaces Upstart as the default init system. systemd basics The basic object that systemd manages is the unit which can be of different types but when it comes to running our Play app we will need to create a service. The systemctl command is used to manage systemd services, similar to the old service command. E.g. to start Nginx you now type: sudo systemctl start nginx.service […]

Rich Interfaces In Java

Leave a comment
Dev

One of the new features added to Java 8 is default methods. In previous versions of Java, adding a new method to an interface would break existing implementations. This made it very hard to evolve your public API without disrupting your clients. Java 8 now allows implementations of methods in an interface. This was needed because Java 8 introduced many new methods on existing interfaces such as sort in List or stream in Collection . […]

Filtering with flatMap

Leave a comment
Dev

Checked exceptions are annoying. They are especially annoying when they may be thrown inside a lambda where they can really interrupt the flow. What if you wanted to map a function over a list to collect values but a checked exception might get thrown in the process? In that case you don’t want the whole stream to stop executing but perhaps just log it and carry on with the next element. Here’s how you might […]

Rules for dates and times

Leave a comment
Dev

Dates and times, like character encoding, are tricky to get right. In real life the concept of time is not something we usually think about much (except when we skipped breakfast this morning and it’s still only 10:30) but once you start storing and manipulating dates and times with computers you begin to run into all sorts of complications like time zones and durations and leap seconds and when is it really the ‘start of […]