3

Надо в тесте проверить что определенный объект имеет определенный тип.

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

Что-бы вот так не писать... Есть ли какой-то метод в util?

1
  • 1
    не уверен насчет assertInstanceOf, но assertTrue здесь бы здорово помог
    – etki
    19 ноя 2016 в 13:47

2 ответа 2

2

Нужно использовать org.hamcrest.CoreMatchers.instanceOf

Ответ: https://stackoverflow.com/a/12404813/4828657

1
  • Спасибо! Вы очень помогли!
    – Pavel
    19 ноя 2016 в 16:13
2

Пример:

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));
    }
}

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.