2014-02-07 4 views
1

최근에 EasyMock에서 이상한 문제가 발생했습니다. 여기에 내가 여기EasyMock을 사용하여 org.openide.nodes.Node 메소드 호출로 함수를 처리 할 수 ​​없습니다.

package com.test.junits; 

import org.openide.nodes.Node; 

public class IsRoot { 
    public boolean isRoot(Node node) { 
     Node parentNode = node.getParentNode(); 
     return (parentNode == null); 
    } 
} 

테스트 그리고 오전 클래스는 내가 그것을 실행하려고의 JUnit 클래스

package com.test.junits 

import static org.junit.Assert.assertNotNull; 

import org.easymock.EasyMock; 
import org.junit.Before; 
import org.junit.Test; 
import org.openide.nodes.Node; 

public class IsRootTest { 

private IsRoot isroot; 
private Node node; 

@Before 
public void setUp() { 
    isroot = new IsRoot(); 
    node = EasyMock.createMock(Node.class); 
} 

@Test 
public void gettingExpectationsForGetParentFromNode() { 
    Node node = EasyMock.createMock(Node.class); 
    Node parentNode = EasyMock.createMock(Node.class); 

    EasyMock.expect(node.getParentNode()).andReturn(parentNode); 

    EasyMock.replay(node); 
    isroot.isRoot(node); 
    EasyMock.verify(node); 
} 

인의 I를 제외하고 다음

java.lang.IllegalStateException: no last call on a mock available 
    at org.easymock.EasyMock.getControlForLastCall(EasyMock.java:521) 
    at org.easymock.EasyMock.expect(EasyMock.java:499) 
    at com.test.junits.IsRootTest.gettingExpectationsForGetParentFromNode(IsRootTest.java:47) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
    at java.lang.reflect.Method.invoke(Unknown Source) 
    at org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99) 
    at org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81) 
    at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34) 
    at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75) 
    at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45) 
    at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:71) 
    at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35) 
    at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42) 
    at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34) 
    at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52) 
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) 
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) 
(메이븐과 이클립스)를 얻을

여기에 뭔가가 빠졌습니까? 도움이 될 것입니다.

+1

http://stackoverflow.com/questions/3494969/easymock-3-0-mocking-class-throws-java-lang-illegalstateexception-no-last-call –

답변

-1

아마 당신이 Node 클래스와 어떤 모두 망신 시켰 있습니다을 node라는 지역 필드와 node 모두라는 클래스 변수를하는이 사실을 함께 할 수있는 뭔가입니다.

당신이 정말로

내 이전의 대답은 잘못 테스트 로컬 모의 node

편집을 원하고, 정말를 했어야 만약 내가 모두 node 현지 테스트를 제거하거나 이름을 바꿀 것

논평. 숨겨진 개체가 문제를 일으키지 않았습니다. (비록 내가 여전히 그들이 제거되었거나 이름이 바뀌어야한다고 생각한다.)

실제 문제는 당신이 모의하려는 방법이 final이고, 그렇기 때문에 조롱 될 수 없다는 것이다.

EasyMock이 메소드/클래스를 mock 할 때 확장/재정 의하여이를 수행합니다. 따라서 최종 클래스와 최종 메서드는 재정의 할 수 없으므로 EasyMock을 조롱 할 수 없습니다.

getParentNode() 메서드에 대한 호출이 조롱되지 않으므로 expectation 호출 내에서 레코드 상태 동안 등록되지 않았습니다.

+0

동일한 코드를 시도했습니다. 그 이름이나 변수와 관련된 문제가 아닙니다. Easymock에서 확인할 수 없습니다. –

+0

@RaghunandanKrishnamurthy 너 틀리지 않아. 나는 조롱당하는 방법이 최종적이고 나의 대답이 바뀌 었다는 것을 발견했다. 그런 말로 필드 감추는 것은 결코 테스트 에서조차 좋은 계획이 아닙니다. –