6ee526e4fcdd073410b780027ca03ac464968eb2
[policy/drools-applications.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
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  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.controlloop.common.rules.test;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.fail;
25
26 import org.junit.AfterClass;
27 import org.junit.Ignore;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30
31
32 /**
33  * Tests NamedRunner. The tests don't do much, because all we really want to check is
34  * which tests are executed based on the {@link TestNames} annotation.
35  */
36 @RunWith(NamedRunner.class)
37 @TestNames(names = {"testAbc", "testDef", "testIgnore"}, prefixes = {"testGhi", "testJkl"})
38 public class NamedRunnerTest {
39
40     private static int testCount = 0;
41
42     @AfterClass
43     public static void tearDownAfterClass() {
44         assertEquals(5, testCount);
45     }
46
47     @Test
48     public void testAbc() {
49         checkTest();
50     }
51
52     @Test
53     public void testAbc2() {
54         fail("should not run");
55     }
56
57     @Test
58     public void testDef() {
59         checkTest();
60     }
61
62     /*
63      * Note: this test is purposely marked with the "Ignore" annotation to verify that the
64      * NamedRunner skips over it, hence the sonar issue is being suppressed.
65      */
66     @Test
67     @Ignore
68     @SuppressWarnings("java:S1607")
69     public void testIgnore() {
70         fail("should not run");
71     }
72
73     @Test
74     public void testGhi1() {
75         checkTest();
76     }
77
78     @Test
79     public void testGhi2() {
80         checkTest();
81     }
82
83     @Test
84     public void testJkl() {
85         checkTest();
86     }
87
88
89     private static void checkTest() {
90         ++testCount;
91     }
92 }