Using JUnit rules to test exceptions

First attempt to use JUnit exception rules. Related to #808.