What is the alternative to using the Deprecated Hamcrest method is()?

前端 未结 3 1588
走了就别回头了
走了就别回头了 2021-02-03 17:31

I use the following code at the moment to assert on a boolean value, however the method org.hamcrest.Matchers.is() is deprecated.

asser         


        
相关标签:
3条回答
  • 2021-02-03 17:40

    I had thought this was a transitive dependency issue, but it's really just a display issue in Eclipse where it marks the import as deprecated because one overloaded form is. The code should compile fine since the import will expose all forms.

    The deprecated form has been removed from the source and will not exist in the next release (1.4).

    Original Answer

    The problem is that JUnit includes a set of Hamcrest classes in its JAR. You can use junit-dep.jar for now, but newer versions (4.9 and 4.10 so far) of JUnit omit them.

    0 讨论(0)
  • 2021-02-03 17:47

    It is said, use instanceOf for class matcher in the document.

    http://junit.org/javadoc/latest/org/hamcrest/core/Is.html#isA(java.lang.Class)

    is(IOException.class);
    

    will be

    is(instanceOf(IOException.class));
    

    for example.

    0 讨论(0)
  • 2021-02-03 17:58

    Have you tried equalTo(T)?

    assertThat(someValue, equalTo(false));
    

    I don't see that is(T) is deprecated - is(Class) is deprecated however.

    0 讨论(0)
提交回复
热议问题