Skip to content
This repository has been archived by the owner on Mar 5, 2023. It is now read-only.

Commit

Permalink
StringUtilTest: Remove Hamcrest String matcher
Browse files Browse the repository at this point in the history
Currently, in StringUtilTest#getDetails_exceptionGiven, we use
Hamcrest's string matching and assert libraries.
This library was introduced in [1], however no justification was
given on why we specifically used these Hamcrest libraries. In fact,
this is the only instance in the entire project where we use this
dependency.

We are only using the assertThat and contains API of the Hamcrest
library, whose corresponding functionality is already implemented in
JUnit#assertTrue and Java String#contains. The only extra benefit that
this Hamcrest library provides is in its more detailed error message
when tests fail [2]. While convenient, this functionality is not
absolutely critical. This is because developers can use the debugger
to inspect the state of messages right before the error.

There is more value in this case to standardise the usage of our
assert statements. The Hamcrest library introduces a new API that
developers of AB4 will have to learn. New developers might be confused
why we use two different APIs to conduct tests. By standardising to
use the JUnit assertTrue, we remove the need to learn multiple APIs,
while achieving the same outcome.

Hence, let's remove the Hamcrest libraries and replace them with their
equivalent Java and JUnit APIs.

[1] 75942c9
[2] https://github.com/junit-team/junit4/wiki/matchers-and-assertthat
  • Loading branch information
sijie123 authored and pyokagan committed Mar 20, 2019
1 parent 7c2e953 commit 1cb12c6
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/test/java/seedu/address/commons/util/StringUtilTest.java
@@ -1,7 +1,5 @@
package seedu.address.commons.util;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

Expand Down Expand Up @@ -145,8 +143,8 @@ public void containsWordIgnoreCase_validInputs_correctResult() {

@Test
public void getDetails_exceptionGiven() {
assertThat(StringUtil.getDetails(new FileNotFoundException("file not found")),
containsString("java.io.FileNotFoundException: file not found"));
assertTrue(StringUtil.getDetails(new FileNotFoundException("file not found"))
.contains("java.io.FileNotFoundException: file not found"));
}

@Test
Expand Down

0 comments on commit 1cb12c6

Please sign in to comment.