git://git.nikiroo.be
/
nikiroo-utils.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Update to version 1.5.0 (breaking Bundle/Meta)
[nikiroo-utils.git]
/
src
/
be
/
nikiroo
/
utils
/
test
/
TestCase.java
diff --git
a/src/be/nikiroo/utils/test/TestCase.java
b/src/be/nikiroo/utils/test/TestCase.java
index b37ea987ffca27677a32eb5d31d05e2632974c52..243acac2b28243a781c5de9eef56b31ab76e5a9e 100644
(file)
--- a/
src/be/nikiroo/utils/test/TestCase.java
+++ b/
src/be/nikiroo/utils/test/TestCase.java
@@
-15,6
+15,10
@@
abstract public class TestCase {
class AssertException extends Exception {
private static final long serialVersionUID = 1L;
class AssertException extends Exception {
private static final long serialVersionUID = 1L;
+ public AssertException(String reason, Exception source) {
+ super(reason, source);
+ }
+
public AssertException(String reason) {
super(reason);
}
public AssertException(String reason) {
super(reason);
}
@@
-109,8
+113,8
@@
abstract public class TestCase {
/**
* Check that 2 {@link Object}s are equals.
*
/**
* Check that 2 {@link Object}s are equals.
*
- * @param
th
e
- * error message to display if they differ
+ * @param
errorMessag
e
+ *
the
error message to display if they differ
* @param expected
* the expected value
* @param actual
* @param expected
* the expected value
* @param actual
@@
-121,14
+125,15
@@
abstract public class TestCase {
*/
public void assertEquals(String errorMessage, Object expected, Object actual)
throws AssertException {
*/
public void assertEquals(String errorMessage, Object expected, Object actual)
throws AssertException {
-
- if (errorMessage == null) {
- errorMessage = generateAssertMessage(expected, actual);
- }
-
if ((expected == null && actual != null)
|| (expected != null && !expected.equals(actual))) {
if ((expected == null && actual != null)
|| (expected != null && !expected.equals(actual))) {
- throw new AssertException(errorMessage);
+ if (errorMessage == null) {
+ throw new AssertException(generateAssertMessage(expected,
+ actual));
+ } else {
+ throw new AssertException(errorMessage, new AssertException(
+ generateAssertMessage(expected, actual)));
+ }
}
}
}
}
@@
-150,8
+155,8
@@
abstract public class TestCase {
/**
* Check that 2 {@link Object}s are equals.
*
/**
* Check that 2 {@link Object}s are equals.
*
- * @param
th
e
- * error message to display if they differ
+ * @param
errorMessag
e
+ *
the
error message to display if they differ
* @param expected
* the expected value
* @param actual
* @param expected
* the expected value
* @param actual
@@
-184,8
+189,8
@@
abstract public class TestCase {
/**
* Check that 2 {@link Object}s are equals.
*
/**
* Check that 2 {@link Object}s are equals.
*
- * @param
th
e
- * error message to display if they differ
+ * @param
errorMessag
e
+ *
the
error message to display if they differ
* @param expected
* the expected value
* @param actual
* @param expected
* the expected value
* @param actual
@@
-218,8
+223,8
@@
abstract public class TestCase {
/**
* Check that 2 {@link Object}s are equals.
*
/**
* Check that 2 {@link Object}s are equals.
*
- * @param
th
e
- * error message to display if they differ
+ * @param
errorMessag
e
+ *
the
error message to display if they differ
* @param expected
* the expected value
* @param actual
* @param expected
* the expected value
* @param actual
@@
-236,8
+241,8
@@
abstract public class TestCase {
/**
* Check that given {@link Object} is not NULL.
*
/**
* Check that given {@link Object} is not NULL.
*
- * @param
th
e
- * error message to display if it is NULL
+ * @param
errorMessag
e
+ *
the
error message to display if it is NULL
* @param actual
* the actual value
*
* @param actual
* the actual value
*
@@
-247,12
+252,16
@@
abstract public class TestCase {
public void assertNotNull(String errorMessage, Object actual)
throws AssertException {
if (actual == null) {
public void assertNotNull(String errorMessage, Object actual)
throws AssertException {
if (actual == null) {
+ String defaultReason = String.format("" //
+ + "Assertion failed!\n" //
+ + "Object should have been NULL: [%s]", actual);
+
if (errorMessage == null) {
if (errorMessage == null) {
- errorMessage = String.format("" //
- + "Assertion failed!\n" //
- + "Object should have been NULL: [%s]", actual);
+ throw new AssertException(defaultReason);
+ } else {
+ throw new AssertException(errorMessage, new AssertException(
+ defaultReason));
}
}
- throw new AssertException(errorMessage);
}
}
}
}