deltaspike-users mailing list archives

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

yes i see the warnning.

So it will be possible to mock beans with Interceptors in next release? (in
our case the majority of beans have interceptors)

Thank you!

2015-04-09 18:29 GMT-03:00 Gerhard Petracek <gerhard.petracek@gmail.com>:

> 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 <rmpestano@gmail.com>:
>
> > 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>
> >
>



-- 
<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