fest-assert-2.x
fest-assert-2.x copied to clipboard
Implement ClassAssert
Assertions for Class objects.
It's of limited use but if you are writing a classloader or a code generation library it may be very convenient.
Good idea !
Do you have any assertions in mind ?
Yes, nice idea. it gives me some ideas :
// special methods
assertThat(Jedi.class).hasSubClass(HumanJedi.class);
assertThat(HumanJedi.class).inheritsFrom(Jedi.class);
// Wrap methods :
assertThat(Jedi.class).containsAnnotation(GreatPower.class, Good.class);
assertThat(Jedi.class).isNotInterface();
assertThat(GreatPower.class).isAnnotation() ;
assertThat(Jedi.class).hasFields("name","sabercolor");
assertThat(Jedi.class).hasDeclaredFields("secretField");
...
To resume, wrap most of is/get methods. Many for contains could uses Arrays to save time but their error messages are not the best for this usage.
@ash2k did you get another specials methods ?
@nfrancois, great example. Also extension points to take Conditions can be very usefull. I have a usecase where i want to check that a Class is annotated with an annotation, which is annotated with some specific annotation. And also only one such annotation shoud be on that Class. This is too complex to include in API, but can easily be implemented as a Condition.
@nfrancois that is a good start, let's do that !
@ash2k Unless I'm wrong, I think you will get Condition for free ClassAssert inherits from AbstractAssert