Thursday 5 April 2018

Hamcrest: isA: Check whether object is of given type

By using ‘isA’ method, you can create a matcher that is used to check whether the object is type given class or not.

Ex
Employee emp = new Employee();
assertThat("emp must be of type Employee class", emp, isA(Employee.class));

TestApp.java
package com.sample.tests;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.isA;

import org.junit.Test;

import com.sample.model.Employee;

public class TestApp {

 @Test
 public void testmethod() {
  Employee emp = new Employee();

  assertThat("emp must be of type Employee class", emp, isA(Employee.class));
 }
}



Previous                                                 Next                                                 Home

No comments:

Post a Comment