FEST-Assert 1.0a1 released!
FEST-Assert is an "assertThat" library that provides a fluent interface for writing assertions. Its main goal is to improve test code readability and make maintenance of tests easier.
Example:
int removed = employees.removeFired(); assertThat(removed).isZero(); ListnewEmployees = employees.hired(TODAY); assertThat(newEmployees).hasSize(6) .contains(frodo, sam); String[] newHires = employees.newHiresNames(); assertThat(newHires).containsOnly("Gandalf", "Arwen", "Gimli"); assertThat(yoda).isInstanceOf(Jedi.class) .isEqualTo(foundJedi) .isNotEqualTo(foundSith);
Changelog:
-
Exceptions thrown by methods
satisfiesanddoesNotSatisfyinclude the name ofConditionclass if the Condition's description is not specified. For example, the following code listing will fail with the message "actual value:<'hello'> should satisfy condition:<UpperCase>":assertThat("hello").satisfies(new UpperCase());where
UpperCaseis defined as:class UpperCase extends Condition<String> { public boolean matches(String value) { if(isEmpty(value)) return false; return value.equals(value.toUpperCase()); } } -
Added method
doesNotSatisfyto all assertions. Fixes issue 46. Many thanks to Mark Derricutt. -
Patch: Added support for
BigDecimal. Fixes issue 107. Many thanks to Ted Young and David DIDIER. -
Method
hasSameContentAs(File)inFileAssertnow includes all the differences found when comparing the contents of two files (previously it only showed the first difference.) -
Added method
isEmptyOrNulltoBooleanArrayAssert,ByteAssertArray,CharArrayAssert,CollectionAssert,DoubleArrayAssert,FloatArrayAssert,IntArrayAssert,LongArrayAssert,MapAssert,ShortArrayAssertandStringAssert. - Added fest-mocks-0.1 and fest-test-0.1 as a 'test' scoped dependencies.
-
Added method
messagetoThrowableAssert. This method returns aStringAssert. -
Added method
hasMessage(String)toThrowableAssert. -
Added method
sizetoFileAssert. This method returns aLongAssert. -
Fixed bug in
FileContentComparatorwhere EOF (end of file) was determined at the wrong time. -
Replaced methods
hasCauseAsAncestorandhasExactCauseAsAncestorinThrowableAssertwith the methodshasCauseOfTypeandhasCauseOfExactTypeinCauseHierarchyAssert. To get aCauseHierarchyAssert, users need to call the methodcauseHierarchyinThrowableAssert. For example, the following code listing:assertThat(catchedException).causeHierarchy().hasCauseOfType(IOException.class);
now replaces:
assertThat(catchedException).hasCauseAsAncestor(IOException.class);
Although the new version is longer, its purpose is easier to understand (that is, to verify if the
catchedExceptionhas a cause of typeIOExceptionin its hierarchy of causes.) -
Replaced method
hasCauseOfTypeinThrowableAssertwith methodcause, which returns anotherThrowableAssertfor the cause of the actualThrowable. Users can callisInstanceOfin the returnedThrowableAssert. -
Method
isInstanceOfinObjectAssertandThrowableAssertthrowsIllegalArgumentExceptionif the givenClassisnull. -
Method
isInstanceOfAnyinObjectAssertthrowsIllegalArgumentExceptionif the givenClassarray is null or if any element in the givenClassarray isnull. -
Fixed typos in Javadocs for class
PrimitiveFail. Many thanks to Ted Young. - Removed dependency on Apache Velocity.
- Removed code generators for assertions for primitive arrays and failure methods for primitives.
- Added missing declaration of exceptions in Javadocs.
- Eliminated inconsistencies and typos in exception messages.
- Added more tests, from 540 to 1523, with code coverage of 99.7%.
You can download the latest release here (file fest-assert-1.0a1.zip.) FEST-Assert requires Java SE 5.0 or later.
Here are some useful links:
Feedback is always appreciated
