Added Junit Class for CallableConsumer.java
[appc.git] / appc-adapters / appc-dmaap-adapter / appc-message-adapter-api / src / test / java / org / onap / appc / adapter / message / TestCallableConsumer.java
1 /*
2  * ============LICENSE_START==========================================
3  *  org.onap.music
4  * ===================================================================
5  *  Copyright (c) 2019 IBM.
6  * ===================================================================
7  *  Licensed under the Apache License, Version 2.0 (the "License");
8  *  you may not use this file except in compliance with the License.
9  *  You may obtain a copy of the License at
10  * 
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  *  Unless required by applicable law or agreed to in writing, software
14  *  distributed under the License is distributed on an "AS IS" BASIS,
15  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  *  See the License for the specific language governing permissions and
17  *  limitations under the License.
18  * 
19  * ============LICENSE_END=============================================
20  * ====================================================================
21  */
22 package org.onap.appc.adapter.message;
23
24 import static org.junit.Assert.assertEquals;
25
26 import java.util.ArrayList;
27 import java.util.List;
28
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.mockito.Mock;
33 import org.mockito.Mockito;
34 import org.mockito.runners.MockitoJUnitRunner;
35
36 @RunWith(MockitoJUnitRunner.class)
37 public class TestCallableConsumer {
38
39     CallableConsumer callableConsumer;
40
41     @Mock
42     private Consumer consumer;
43
44     private List<String> list;
45     private int waitMs = 15000;
46     private int limit = 1000;
47     private int maxLife = 25000;
48
49     @Before
50     public void setUp() {
51         list = new ArrayList<String>();
52         callableConsumer = new CallableConsumer(consumer, waitMs, limit);
53     }
54
55     @Test
56     public void testCallableConsumer() {
57         CallableConsumer callableConsumer = new CallableConsumer(consumer);
58         Mockito.when(consumer.fetch()).thenReturn(list);
59         assertEquals(list, callableConsumer.call());
60     }
61
62     @Test
63     public void testCall() {
64         Mockito.when(consumer.fetch()).thenReturn(list);
65         assertEquals(list, callableConsumer.call());
66     }
67
68     @Test
69     public void testGetMaxLife() {
70         assertEquals(maxLife, callableConsumer.getMaxLife());
71     }
72
73 }