org.assertj.core.api
Class AbstractClassAssert<S extends AbstractClassAssert<S>>

java.lang.Object
  extended by org.assertj.core.api.AbstractAssert<S,Class<?>>
      extended by org.assertj.core.api.AbstractClassAssert<S>
Type Parameters:
S - the "self" type of this assertion class. Please read "Emulating 'self types' using Java Generics to simplify fluent API implementation" for more details.
All Implemented Interfaces:
Assert<S,Class<?>>, Descriptable<S>, ExtensionPoints<S,Class<?>>
Direct Known Subclasses:
ClassAssert

public abstract class AbstractClassAssert<S extends AbstractClassAssert<S>>
extends AbstractAssert<S,Class<?>>

Base class for all implementations of assertions for Classes.

Author:
William Delanoue, Mikhail Mazursky

Field Summary
 
Fields inherited from class org.assertj.core.api.AbstractAssert
actual, info, myself
 
Constructor Summary
protected AbstractClassAssert(Class<?> actual, Class<?> selfType)
           
 
Method Summary
 S hasAnnotation(Class<? extends Annotation> annotation)
          Verifies that the actual Class has the given Annotation.
 S hasAnnotations(Class<? extends Annotation>... annotations)
          Verifies that the actual Class has the given Annotations.
 S hasDeclaredFields(String... fields)
          Verifies that the actual Class has the declared fields.
 S hasFields(String... fields)
          Verifies that the actual Class has the fields.
 S isAnnotation()
          Verifies that the actual Class is an annotation.
 S isAssignableFrom(Class<?>... others)
          Verifies that the actual Class is assignable from others Class
 S isInterface()
          Verifies that the actual Class is an interface.
 S isNotAnnotation()
          Verifies that the actual Class is not an annotation.
 S isNotInterface()
          Verifies that the actual Class is not an interface.
 
Methods inherited from class org.assertj.core.api.AbstractAssert
as, as, describedAs, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, equals, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, inBinary, inHexadecimal, is, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, overridingErrorMessage, usingComparator, usingDefaultComparator
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractClassAssert

protected AbstractClassAssert(Class<?> actual,
                              Class<?> selfType)
Method Detail

isAssignableFrom

public S isAssignableFrom(Class<?>... others)
Verifies that the actual Class is assignable from others Class
     class Jedi {}
     class HumanJedi extends Jedi {}
 
 Should pass if :
     assertThat(Jedi.class).isAssignableFrom(HumanJedi.class);
 
 Should fail if :
     assertThat(HumanJedi.class).isAssignableFrom(Jedi.class);
 
 

Parameters:
others - Class who can be assignable from.
Returns:
this assertion object.
Throws:
AssertionError - if the actual Date is null.
NullPointerException - if other Date is null.
AssertionError - if the actual Date is not before or equals to the given one.
See Also:
Class.isAssignableFrom(Class)

isNotInterface

public S isNotInterface()
Verifies that the actual Class is not an interface.
     interface Jedi {}
     class HumanJedi implements Jedi {}
 
 Should pass if :
     assertThat(HumanJedi.class).isNotInterface();
 
 Should fail if :
     assertThat(Jedi.class).isNotInterface();
 
 

Throws:
AssertionError - if actual is null.
AssertionError - if the actual Class is not an interface.

isInterface

public S isInterface()
Verifies that the actual Class is an interface.
     interface Jedi {}
     class HumanJedi implements Jedi {}
 
 Should pass if :
     assertThat(Jedi.class).isInterface();
 
 Should fail if :
     assertThat(HumanJedi.class).isInterface();
 
 

Throws:
AssertionError - if actual is null.
AssertionError - if the actual Class is not an interface.

isAnnotation

public S isAnnotation()
Verifies that the actual Class is an annotation.
     public @interface Jedi {}
 
 Should pass if :
     assertThat(Jedi.class).isAnnotation();
     assertThat(Override.class).isAnnotation();
     assertThat(Deprecated.class).isAnnotation();
 
 Should fail if :
     assertThat(String.class).isAnnotation();
 
 

Throws:
AssertionError - if actual is null.
AssertionError - if the actual Class is not an annotation.

isNotAnnotation

public S isNotAnnotation()
Verifies that the actual Class is not an annotation.
     public @interface Jedi {}
 
 Should pass if :
     assertThat(String.class).isNotAnnotation();
 
 Should fail if :
     assertThat(Jedi.class).isNotAnnotation();
     assertThat(Override.class).isNotAnnotation();
     assertThat(Deprecated.class).isNotAnnotation();
 
 

Throws:
AssertionError - if actual is null.
AssertionError - if the actual Class is an annotation.

hasAnnotations

public S hasAnnotations(Class<? extends Annotation>... annotations)
Verifies that the actual Class has the given Annotations.

Parameters:
annotations - annotations who must be attached to the class
Throws:
AssertionError - if actual is null.
AssertionError - if the actual Class doesn't contains all of these annotations.

hasAnnotation

public S hasAnnotation(Class<? extends Annotation> annotation)
Verifies that the actual Class has the given Annotation.

Parameters:
annotation - annotations who must be attached to the class
Throws:
AssertionError - if actual is null.
AssertionError - if the actual Class doesn't contains all of these annotations.

hasFields

public S hasFields(String... fields)
Verifies that the actual Class has the fields.
     class MyClass {
         public String fieldOne;
         private String fieldTwo;
     }
 
 This one should pass :
    assertThat(MyClass.class).hasFields("fieldOne");
 
 This one should fail :
    assertThat(MyClass.class).hasFields("fieldTwo");
    assertThat(MyClass.class).hasDeclaredFields("fieldThree");
 

Parameters:
fields - the fields who must be in the class.
Throws:
AssertionError - if actual is null.
AssertionError - if the actual Class doesn't contains all of the field.
See Also:
Class.getField(String)

hasDeclaredFields

public S hasDeclaredFields(String... fields)
Verifies that the actual Class has the declared fields.
     class MyClass {
         public String fieldOne;
         private String fieldTwo;
     }
 
 This one should pass :
    assertThat(MyClass.class).hasDeclaredFields("fieldOne", "fieldTwo");
 
 This one should fail :
    assertThat(MyClass.class).hasDeclaredFields("fieldThree");
 

Parameters:
fields - the fields who must be declared in the class.
Throws:
AssertionError - if actual is null.
AssertionError - if the actual Class doesn't contains all of the field.
See Also:
Class.getDeclaredField(String)


Copyright © 2013–2015 AssertJ. All rights reserved.