Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stephenh/avow
a semi-fluent assertions library
https://github.com/stephenh/avow
Last synced: 2 days ago
JSON representation
a semi-fluent assertions library
- Host: GitHub
- URL: https://github.com/stephenh/avow
- Owner: stephenh
- Created: 2009-03-04T23:24:02.000Z (over 15 years ago)
- Default Branch: master
- Last Pushed: 2009-03-11T20:47:07.000Z (over 15 years ago)
- Last Synced: 2024-10-12T10:15:30.857Z (about 1 month ago)
- Language: Java
- Homepage:
- Size: 234 KB
- Stars: 2
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.markdown
Awesome Lists containing this project
README
A small library for doing assertions.
Example
=======String foo = "asdf";
Avow.that(foo).equals("asdf");List list = ...;
Avow.that(list).contains(item);This is a lot like separate `StringAssert`, `ListAssert`, etc., classes, which I had used before. `Avow.that` is just a hack to move the choosing of an `XxxAssert` class to the compiler based on method overloading instead of the programming typing each one out.
This is somewhat like [Hamcrest][1] (which was integrated into JUnit 4.4), but without the Matcher static import methods. Nothing against static import methods, but I like `that` returning the appropriate `StringAsserter`, `ListAsserter`, etc., just based on basic Java method overloading.
Granted, this approach cannot handle `or` type nested logical statements, but that is just fine with me. I like simple assertions.
[1]: http://code.google.com/p/hamcrest/
Extending
=========To extend and add your own assertion classes/methods, you should make your own `Avow` class, e.g.:
package com.yourapp;
public class Avow extends org.exigencecorp.avow.Avow {
public static YourStringAsserter that(String string) {
return new YourStringAsserter(string);
}
public static WidgetAsserter that(Widget widget) {
return new WidgetAsserter(widget);
}
}Then just have:
* `YourStringAsserter` extend `StringAsserter`, and
* `WidgetAsserter` extend `ObjectAsserter`And add your own assertion methods to each class.
Then when using `Avow.that` in your tests, just make sure you import your own `Avow` subclass instead of the base class.