deltaspike-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rafael Pestano <rmpest...@gmail.com>
Subject Test control and mock integration issue
Date Thu, 09 Apr 2015 14:01:04 GMT
Hi guys,

I cant get a simple mock to work with test control module, am I missing
something?

here is the failing test:

@RunWith(CdiTestRunner.class)
public class MockTest {

  @Inject
  private DynamicMockManager mockManager;

  @Inject
  private UserRepository userRepository; //will inject the mocked instance

  @Test
  public void shouldMockTest() {
    UserRepository mockedUserRepository = mock(UserRepository.class);
    when(mockedUserRepository.test()).thenReturn("mock");
    mockManager.addMock(mockedUserRepository);
    assertEquals(userRepository.test(), "mock");//is returning "test"
instead of "mock"

  }

}


here is test output:

org.junit.ComparisonFailure:
Expected :test
Actual   :mock
 <Click to see difference>
at org.junit.Assert.assertEquals(Assert.java:125)
at org.junit.Assert.assertEquals(Assert.java:147)
at org.os890.demo.ee6.test.MockTest.shouldMockTest(MockTest.java:32)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)



Shouldn't userRepository.test() return the *"mock"* string?



sources:
https://github.com/rmpestano/ee6-ds-demo/blob/master/src/test/java/org/os890/demo/ee6/test/MockTest.java#L32


thanks in advance.


-- 
<http://www.advancedit.com.br/>Att,

Rafael M. Pestano

Desenvolvedor Java Cia. de Processamento de Dados do Rio Grande do Sul
http://rpestano.wordpress.com/
@realpestano <https://twitter.com/realpestano>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message