Search in sources :

Example 1 with ProducerInstance

use of org.apache.rocketmq.logappender.common.ProducerInstance in project rocketmq-externals by apache.

the class AbstractTestCase method mockLoggerAppender.

@Before
public void mockLoggerAppender() throws Exception {
    DefaultMQProducer defaultMQProducer = spy(new DefaultMQProducer("loggerAppender"));
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
            Message message = (Message) invocationOnMock.getArgument(0);
            messages.add(message);
            return null;
        }
    }).when(defaultMQProducer).sendOneway(any(Message.class));
    ProducerInstance spy = mock(ProducerInstance.class);
    Field instance = ProducerInstance.class.getDeclaredField("instance");
    instance.setAccessible(true);
    instance.set(ProducerInstance.class, spy);
    doReturn(defaultMQProducer).when(spy).getInstance(anyString(), anyString());
}
Also used : Field(java.lang.reflect.Field) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DefaultMQProducer(org.apache.rocketmq.client.producer.DefaultMQProducer) ProducerInstance(org.apache.rocketmq.logappender.common.ProducerInstance) Before(org.junit.Before)

Example 2 with ProducerInstance

use of org.apache.rocketmq.logappender.common.ProducerInstance in project rocketmq by apache.

the class AbstractTestCase method mockLoggerAppender.

@Before
public void mockLoggerAppender() throws Exception {
    DefaultMQProducer defaultMQProducer = spy(new DefaultMQProducer("loggerAppender"));
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
            Message message = (Message) invocationOnMock.getArgument(0);
            messages.add(message);
            return null;
        }
    }).when(defaultMQProducer).sendOneway(any(Message.class));
    ProducerInstance spy = mock(ProducerInstance.class);
    Field instance = ProducerInstance.class.getDeclaredField("instance");
    instance.setAccessible(true);
    instance.set(ProducerInstance.class, spy);
    doReturn(defaultMQProducer).when(spy).getInstance(anyString(), anyString());
}
Also used : Field(java.lang.reflect.Field) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DefaultMQProducer(org.apache.rocketmq.client.producer.DefaultMQProducer) ProducerInstance(org.apache.rocketmq.logappender.common.ProducerInstance) Before(org.junit.Before)

Aggregations

Field (java.lang.reflect.Field)2 DefaultMQProducer (org.apache.rocketmq.client.producer.DefaultMQProducer)2 ProducerInstance (org.apache.rocketmq.logappender.common.ProducerInstance)2 Before (org.junit.Before)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2