Skip to content

Commit

Permalink
Add Java stub
Browse files Browse the repository at this point in the history
  • Loading branch information
bkaestner committed Aug 13, 2015
1 parent 3d0ae80 commit ce9ae3b
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion rules/0250-Java.md
Original file line number Diff line number Diff line change
@@ -1 +1,46 @@
<!--- this is only a placeholder -->
## Java
*Note:* This section is under construction and could use some help. Please
submit pull-requests.

### Beware of the assert arguments!
JUnit differs from the other frameworks. Very. Much. Well, overall it doesn't,
it still has `assertEquals`, `assertArrayEquals` and others. But the
order of arguments is swapped.

Where CoffeeScript, Ruby, Python and Haskell expect the first argument of
`Test.assert_equals`/`Test.assertEquals`/`shouldBe` to be the actual value and
the second to be the expected, JUnit swaps the order, see the documentation of
[Assert][assert-java]:

``` java
assertEquals(double expected, double actual); // note: use delta variant!
assertEquals(float expected, float actual); // note: use delta variant!
assertEquals(long expected, long actual);
// many other
```

For comparison, here's the syntax of an equality assert in the other languages:

``` haskell
-- Haskell
actual `shouldBe` expected
```
``` javascript
// Javascript
Test.assertEquals(actual, expected, message);
```
``` python
# Python
Test.assert_equals(actual, expected, message)
```
``` ruby
# Ruby
Test.assert_equals(actual, expected, message)
```

Keep this in mind. Your tests won't fail on correct solutions if you swap the
arguments, but they __will__ confuse anyone who fails them. By the way, CSharp
uses the same convention. This isn't surprising, since its testing framework
NUnit was inspired by JUnit.

[assert-java]: http://junit.org/javadoc/latest/org/junit/Assert.html

0 comments on commit ce9ae3b

Please sign in to comment.