hi rafael, this feature is deactivated per default, because there are some limitations. (since v1.3.0 it should be possible to use a new workaround, however, so far it wasn't done.)
one of the limitations is that you can't mock beans with interceptors. -> you should see the following warning: "Skip mocking intercepted bean" [class-name] -> remove all interceptors in UserRepository and your test will pass. regards, gerhard http://www.irian.at Your JavaEE powerhouse - JavaEE Consulting, Development and Courses in English and German Professional Support for Apache MyFaces, DeltaSpike and OpenWebBeans 2015-04-09 16:01 GMT+02:00 Rafael Pestano <[email protected]>: > 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> >
