View Javadoc
1   /*
2    * Copyright (c) 2002-2025 Gargoyle Software Inc.
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    * https://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  package org.htmlunit.junit.annotation;
16  
17  import java.lang.reflect.Method;
18  
19  import org.junit.jupiter.api.Assertions;
20  import org.junit.jupiter.api.Test;
21  
22  /**
23   * Tests for {@link AnnotationUtils}.
24   *
25   * @author Ronald Brill
26   */
27  public class AnnotationUtilsTest {
28  
29      /**
30       * @throws Exception if something goes wrong
31       */
32      @Test
33      @Alerts(DEFAULT = "default",
34              CHROME = "chrome",
35              EDGE = "edge",
36              FF = "ff",
37              FF_ESR = "ff esr")
38      public void obsoleteDefaultBecauseAllBrowserExpectationsDefinedIndividually() throws Exception {
39          testFail("Obsolete DEFAULT because all browser expectations defined individually "
40                      + "(org.htmlunit.junit.annotation.AnnotationUtilsTest"
41                      + ".obsoleteDefaultBecauseAllBrowserExpectationsDefinedIndividually "
42                      + "==> expected: <false> but was: <true>",
43              "obsoleteDefaultBecauseAllBrowserExpectationsDefinedIndividually");
44      }
45  
46      /**
47       * @throws Exception if something goes wrong
48       */
49      @Test
50      @Alerts(DEFAULT = "redundant",
51              CHROME = "redundant")
52      public void redundantAlertChrome() throws Exception {
53          testFail("Redundant @Alerts for Chrome in AnnotationUtilsTest.redundantAlertChrome()",
54                  "redundantAlertChrome");
55      }
56  
57      /**
58       * @throws Exception if something goes wrong
59       */
60      @Test
61      @Alerts(DEFAULT = "redundant",
62              EDGE = "redundant")
63      public void redundantAlertEdge() throws Exception {
64          testFail("Redundant @Alerts for Edge in AnnotationUtilsTest.redundantAlertEdge()",
65                  "redundantAlertEdge");
66      }
67  
68      /**
69       * @throws Exception if something goes wrong
70       */
71      @Test
72      @Alerts(DEFAULT = "redundant",
73              FF = "redundant")
74      public void redundantAlertFf() throws Exception {
75          testFail("Redundant @Alerts for FF in AnnotationUtilsTest.redundantAlertFf()",
76                  "redundantAlertFf");
77      }
78  
79      /**
80       * @throws Exception if something goes wrong
81       */
82      @Test
83      @Alerts(DEFAULT = "redundant",
84              FF_ESR = "redundant")
85      public void redundantAlertFfEsr() throws Exception {
86          testFail("Redundant @Alerts for FF-ESR in AnnotationUtilsTest.redundantAlertFfEsr()",
87                  "redundantAlertFfEsr");
88      }
89  
90      /**
91       * @throws Exception if something goes wrong
92       */
93      @Test
94      @Alerts("redundant")
95      @HtmlUnitNYI(CHROME = "redundant")
96      public void redundantHtmlUnitNYIChrome() throws Exception {
97          testFail("Redundant @HtmlUnitNYI for Chrome in AnnotationUtilsTest.redundantHtmlUnitNYIChrome()",
98                  "redundantHtmlUnitNYIChrome");
99      }
100 
101     /**
102      * @throws Exception if something goes wrong
103      */
104     @Test
105     @Alerts("redundant")
106     @HtmlUnitNYI(EDGE = "redundant")
107     public void redundantHtmlUnitNYIEdge() throws Exception {
108         testFail("Redundant @HtmlUnitNYI for Edge in AnnotationUtilsTest.redundantHtmlUnitNYIEdge()",
109                 "redundantHtmlUnitNYIEdge");
110     }
111 
112     /**
113      * @throws Exception if something goes wrong
114      */
115     @Test
116     @Alerts("redundant")
117     @HtmlUnitNYI(FF = "redundant")
118     public void redundantHtmlUnitNYIFf() throws Exception {
119         testFail("Redundant @HtmlUnitNYI for FF in AnnotationUtilsTest.redundantHtmlUnitNYIFf()",
120                 "redundantHtmlUnitNYIFf");
121     }
122 
123     /**
124      * @throws Exception if something goes wrong
125      */
126     @Test
127     @Alerts("redundant")
128     @HtmlUnitNYI(FF_ESR = "redundant")
129     public void redundantHtmlUnitNYIFfEsr() throws Exception {
130         testFail("Redundant @HtmlUnitNYI for FF-ESR in AnnotationUtilsTest.redundantHtmlUnitNYIFfEsr()",
131                 "redundantHtmlUnitNYIFfEsr");
132     }
133 
134     /**
135      * @throws Exception if something goes wrong
136      */
137     @Test
138     @Alerts(DEFAULT = "",
139             CHROME = "redundant")
140     @HtmlUnitNYI(CHROME = "redundant")
141     public void redundantChromeHtmlUnitNYIChrome() throws Exception {
142         testFail("Redundant @HtmlUnitNYI for Chrome in AnnotationUtilsTest.redundantChromeHtmlUnitNYIChrome()",
143                 "redundantChromeHtmlUnitNYIChrome");
144     }
145 
146     /**
147      * @throws Exception if something goes wrong
148      */
149     @Test
150     @Alerts(DEFAULT = "",
151             EDGE = "redundant")
152     @HtmlUnitNYI(EDGE = "redundant")
153     public void redundantEdgeHtmlUnitNYIEdge() throws Exception {
154         testFail("Redundant @HtmlUnitNYI for Edge in AnnotationUtilsTest.redundantEdgeHtmlUnitNYIEdge()",
155                 "redundantEdgeHtmlUnitNYIEdge");
156     }
157 
158     /**
159      * @throws Exception if something goes wrong
160      */
161     @Test
162     @Alerts(DEFAULT = "",
163             FF = "redundant")
164     @HtmlUnitNYI(FF = "redundant")
165     public void redundantFfHtmlUnitNYIFf() throws Exception {
166         testFail("Redundant @HtmlUnitNYI for FF in AnnotationUtilsTest.redundantFfHtmlUnitNYIFf()",
167                 "redundantFfHtmlUnitNYIFf");
168     }
169 
170     /**
171      * @throws Exception if something goes wrong
172      */
173     @Test
174     @Alerts(DEFAULT = "",
175             FF_ESR = "redundant")
176     @HtmlUnitNYI(FF_ESR = "redundant")
177     public void redundantFfEsrHtmlUnitNYIFfEsr() throws Exception {
178         testFail("Redundant @HtmlUnitNYI for FF-ESR in AnnotationUtilsTest.redundantFfEsrHtmlUnitNYIFfEsr()",
179                 "redundantFfEsrHtmlUnitNYIFfEsr");
180     }
181 
182     /**
183      * @throws Exception if something goes wrong
184      */
185     @Test
186     @Alerts(CHROME = "redundant")
187     @HtmlUnitNYI(CHROME = "redundant")
188     public void redundantChrome2HtmlUnitNYIChrome() throws Exception {
189         testFail("Redundant @HtmlUnitNYI for Chrome in AnnotationUtilsTest.redundantChrome2HtmlUnitNYIChrome()",
190                 "redundantChrome2HtmlUnitNYIChrome");
191     }
192 
193     /**
194      * @throws Exception if something goes wrong
195      */
196     @Test
197     @Alerts(EDGE = "redundant")
198     @HtmlUnitNYI(EDGE = "redundant")
199     public void redundantEdge2HtmlUnitNYIEdge() throws Exception {
200         testFail("Redundant @HtmlUnitNYI for Edge in AnnotationUtilsTest.redundantEdge2HtmlUnitNYIEdge()",
201                 "redundantEdge2HtmlUnitNYIEdge");
202     }
203 
204     /**
205      * @throws Exception if something goes wrong
206      */
207     @Test
208     @Alerts(FF = "redundant")
209     @HtmlUnitNYI(FF = "redundant")
210     public void redundantFf2HtmlUnitNYIFf() throws Exception {
211         testFail("Redundant @HtmlUnitNYI for FF in AnnotationUtilsTest.redundantFf2HtmlUnitNYIFf()",
212                 "redundantFf2HtmlUnitNYIFf");
213     }
214 
215     /**
216      * @throws Exception if something goes wrong
217      */
218     @Test
219     @Alerts(FF_ESR = "redundant")
220     @HtmlUnitNYI(FF_ESR = "redundant")
221     public void redundantFfEsr2HtmlUnitNYIFfEsr() throws Exception {
222         testFail("Redundant @HtmlUnitNYI for FF-ESR in AnnotationUtilsTest.redundantFfEsr2HtmlUnitNYIFfEsr()",
223                 "redundantFfEsr2HtmlUnitNYIFfEsr");
224     }
225 
226     private void testFail(final String expectedMsg, final String methodName) throws Exception {
227         final Method method = getClass().getMethod(methodName, (Class[]) null);
228 
229         try {
230             AnnotationUtils.assertAlerts(method);
231             Assertions.fail("AssertionError expected");
232         }
233         catch (final AssertionError e) {
234             Assertions.assertEquals(expectedMsg, e.getMessage());
235         }
236     }
237 }