It is necessary in the test to verify that a particular object has a certain type.

boolean res = (desc[2][7] instanceof Place); assertThat(res,is(true)); 

Something like that not to write ... Is there any method in util?

  • one
    I'm not sure about assertInstanceOf, but assertTrue would help a lot here - etki

2 answers 2

Need to use org.hamcrest.CoreMatchers.instanceOf

Answer: https://stackoverflow.com/a/12404813/4828657

  • Thank! You really helped! - Pavel

Example:

 import org.junit.Test; import static org.hamcrest.CoreMatchers.instanceOf; import static org.junit.Assert.assertThat; abstract class AbstractClass { } class ClassImp extends AbstractClass { } public class InstanceOfTest { @Test public void testInstanceOf() { final AbstractClass subClass = new ClassImp(); assertThat(subClass, instanceOf(AbstractClass.class)); } }