fest-assert-2.x icon indicating copy to clipboard operation
fest-assert-2.x copied to clipboard

Implement ClassAssert

Open ash2k opened this issue 13 years ago • 4 comments

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.

ash2k avatar May 27 '12 12:05 ash2k

Good idea !

Do you have any assertions in mind ?

joel-costigliola avatar May 28 '12 17:05 joel-costigliola

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 avatar May 29 '12 09:05 nfrancois

@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.

ash2k avatar May 29 '12 11:05 ash2k

@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

joel-costigliola avatar May 30 '12 08:05 joel-costigliola