2016-07-08 3 views

답변

3

이 기능을 제공하는 기본 정규 표현식은 org.hamcrest.core.IsSame입니다. org.hamcrest.Matchers#sameInstance (언급 한대로)과 org.hamcrest.CoreMatchers#sameInstance에 숨길 수있는 편리한 방법이 있습니다.

주로 사용하는 환경 설정 문제입니다. 개인적으로, 나는 정적으로 "슬림"그냥 때문에, CoreMatchers에서 가져 오기 선호 :.

import static org.hamcrest.CoreMatchers.sameInstance; 
import static org.junit.Assert.assertThat; 

import org.junit.Test; 

public class SomeTest { 
    @Test 
    public void testSomething() { 
     Object o1 = new Object(); 
     Object o2 = o1; 

     assertThat(o1, sameInstance(o2)); 
    } 
} 
1

는 현재

assertThat(actual, isSame(expected)) 

로 전환하고자합니다.

+2

를 고정 수입'org.hamcrest.Matchers를 갖는 *;'나는 * *이 방법 isSame를 해결할 수를 참조하십시오. 그렇다면 무엇을 수입해야합니까? –

+0

CoreMatchers가 필요합니다. – GhostCat