Fix the Sonar Findings
[holmes/engine-management.git] / engine-d / src / test / java / org / onap / holmes / engine / dmaap / DMaaPAlarmPollingTest.java
1 /**
2  * Copyright 2017 ZTE Corporation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.onap.holmes.engine.dmaap;
17
18 import static org.hamcrest.core.IsEqual.equalTo;
19 import static org.junit.Assert.*;
20
21 import java.lang.reflect.Field;
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.junit.runner.RunWith;
25 import org.onap.holmes.dsa.dmaappolling.Subscriber;
26 import org.onap.holmes.engine.manager.DroolsEngine;
27 import org.powermock.api.easymock.PowerMock;
28 import org.powermock.core.classloader.annotations.PrepareForTest;
29 import org.powermock.modules.junit4.PowerMockRunner;
30
31 @PrepareForTest({Subscriber.class, DroolsEngine.class})
32 @RunWith(PowerMockRunner.class)
33 public class DMaaPAlarmPollingTest {
34
35     private DMaaPAlarmPolling dMaaPAlarmPolling;
36     private Subscriber subscriber;
37     private DroolsEngine droolsEngine;
38
39     @Before
40     public void setUp() {
41         subscriber = PowerMock.createMock(Subscriber.class);
42         droolsEngine = PowerMock.createMock(DroolsEngine.class);
43         dMaaPAlarmPolling = new DMaaPAlarmPolling(subscriber, droolsEngine);
44         PowerMock.replayAll();
45     }
46
47     @Test
48     public void test_stop_task_ok() throws Exception {
49         dMaaPAlarmPolling.stopTask();
50         Field field = DMaaPAlarmPolling.class.getDeclaredField("isAlive");
51         field.setAccessible(true);
52         assertThat(field.get(dMaaPAlarmPolling), equalTo(false));
53     }
54
55 }