Thursday, 5 April 2018

Hamcrest: typeCompatibleWith: Check the compatibility of one type with other

By using ‘typeCompatibleWith’ function, you can create a matcher that matches when the specified baseType is assignable from the examined class.

Ex
assertThat("Intger class must be assigned to Number class", Integer.class, typeCompatibleWith(Number.class));

TestApp.java

package com.sample.tests;

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

import org.junit.Test;

public class TestApp {

 @Test
 public void testmethod() {
  assertThat("Intger class must be assigned to Number class", Integer.class, typeCompatibleWith(Number.class));
 }
}




Previous                                                 Next                                                 Home

No comments:

Post a Comment