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.Assert;
20  import org.junit.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                  "obsoleteDefaultBecauseAllBrowserExpectationsDefinedIndividually");
41      }
42  
43      /**
44       * @throws Exception if something goes wrong
45       */
46      @Test
47      @Alerts(DEFAULT = "redundant",
48              CHROME = "redundant")
49      public void redundantAlertChrome() throws Exception {
50          testFail("Redundant @Alerts for Chrome in AnnotationUtilsTest.redundantAlertChrome()",
51                  "redundantAlertChrome");
52      }
53  
54      /**
55       * @throws Exception if something goes wrong
56       */
57      @Test
58      @Alerts(DEFAULT = "redundant",
59              EDGE = "redundant")
60      public void redundantAlertEdge() throws Exception {
61          testFail("Redundant @Alerts for Edge in AnnotationUtilsTest.redundantAlertEdge()",
62                  "redundantAlertEdge");
63      }
64  
65      /**
66       * @throws Exception if something goes wrong
67       */
68      @Test
69      @Alerts(DEFAULT = "redundant",
70              FF = "redundant")
71      public void redundantAlertFf() throws Exception {
72          testFail("Redundant @Alerts for FF in AnnotationUtilsTest.redundantAlertFf()",
73                  "redundantAlertFf");
74      }
75  
76      /**
77       * @throws Exception if something goes wrong
78       */
79      @Test
80      @Alerts(DEFAULT = "redundant",
81              FF_ESR = "redundant")
82      public void redundantAlertFfEsr() throws Exception {
83          testFail("Redundant @Alerts for FF-ESR in AnnotationUtilsTest.redundantAlertFfEsr()",
84                  "redundantAlertFfEsr");
85      }
86  
87      /**
88       * @throws Exception if something goes wrong
89       */
90      @Test
91      @Alerts("redundant")
92      @HtmlUnitNYI("redundant")
93      public void redundantHtmlUnitNYI() throws Exception {
94          testFail("Redundant @HtmlUnitNYI for DEFAULT in AnnotationUtilsTest.redundantHtmlUnitNYI()",
95                  "redundantHtmlUnitNYI");
96      }
97  
98      /**
99       * @throws Exception if something goes wrong
100      */
101     @Test
102     @Alerts("redundant")
103     @HtmlUnitNYI(CHROME = "redundant")
104     public void redundantHtmlUnitNYIChrome() throws Exception {
105         testFail("Redundant @HtmlUnitNYI for Chrome in AnnotationUtilsTest.redundantHtmlUnitNYIChrome()",
106                 "redundantHtmlUnitNYIChrome");
107     }
108 
109     /**
110      * @throws Exception if something goes wrong
111      */
112     @Test
113     @Alerts("redundant")
114     @HtmlUnitNYI(EDGE = "redundant")
115     public void redundantHtmlUnitNYIEdge() throws Exception {
116         testFail("Redundant @HtmlUnitNYI for Edge in AnnotationUtilsTest.redundantHtmlUnitNYIEdge()",
117                 "redundantHtmlUnitNYIEdge");
118     }
119 
120     /**
121      * @throws Exception if something goes wrong
122      */
123     @Test
124     @Alerts("redundant")
125     @HtmlUnitNYI(FF = "redundant")
126     public void redundantHtmlUnitNYIFf() throws Exception {
127         testFail("Redundant @HtmlUnitNYI for FF in AnnotationUtilsTest.redundantHtmlUnitNYIFf()",
128                 "redundantHtmlUnitNYIFf");
129     }
130 
131     /**
132      * @throws Exception if something goes wrong
133      */
134     @Test
135     @Alerts("redundant")
136     @HtmlUnitNYI(FF_ESR = "redundant")
137     public void redundantHtmlUnitNYIFfEsr() throws Exception {
138         testFail("Redundant @HtmlUnitNYI for FF-ESR in AnnotationUtilsTest.redundantHtmlUnitNYIFfEsr()",
139                 "redundantHtmlUnitNYIFfEsr");
140     }
141 
142     /**
143      * @throws Exception if something goes wrong
144      */
145     @Test
146     @Alerts(DEFAULT = "",
147             CHROME = "redundant")
148     @HtmlUnitNYI(CHROME = "redundant")
149     public void redundantChromeHtmlUnitNYIChrome() throws Exception {
150         testFail("Redundant @HtmlUnitNYI for Chrome in AnnotationUtilsTest.redundantChromeHtmlUnitNYIChrome()",
151                 "redundantChromeHtmlUnitNYIChrome");
152     }
153 
154     /**
155      * @throws Exception if something goes wrong
156      */
157     @Test
158     @Alerts(DEFAULT = "",
159             EDGE = "redundant")
160     @HtmlUnitNYI(EDGE = "redundant")
161     public void redundantEdgeHtmlUnitNYIEdge() throws Exception {
162         testFail("Redundant @HtmlUnitNYI for Edge in AnnotationUtilsTest.redundantEdgeHtmlUnitNYIEdge()",
163                 "redundantEdgeHtmlUnitNYIEdge");
164     }
165 
166     /**
167      * @throws Exception if something goes wrong
168      */
169     @Test
170     @Alerts(DEFAULT = "",
171             FF = "redundant")
172     @HtmlUnitNYI(FF = "redundant")
173     public void redundantFfHtmlUnitNYIFf() throws Exception {
174         testFail("Redundant @HtmlUnitNYI for FF in AnnotationUtilsTest.redundantFfHtmlUnitNYIFf()",
175                 "redundantFfHtmlUnitNYIFf");
176     }
177 
178     /**
179      * @throws Exception if something goes wrong
180      */
181     @Test
182     @Alerts(DEFAULT = "",
183             FF_ESR = "redundant")
184     @HtmlUnitNYI(FF_ESR = "redundant")
185     public void redundantFfEsrHtmlUnitNYIFfEsr() throws Exception {
186         testFail("Redundant @HtmlUnitNYI for FF-ESR in AnnotationUtilsTest.redundantFfEsrHtmlUnitNYIFfEsr()",
187                 "redundantFfEsrHtmlUnitNYIFfEsr");
188     }
189 
190     /**
191      * @throws Exception if something goes wrong
192      */
193     @Test
194     @Alerts(CHROME = "redundant")
195     @HtmlUnitNYI(CHROME = "redundant")
196     public void redundantChrome2HtmlUnitNYIChrome() throws Exception {
197         testFail("Redundant @HtmlUnitNYI for Chrome in AnnotationUtilsTest.redundantChrome2HtmlUnitNYIChrome()",
198                 "redundantChrome2HtmlUnitNYIChrome");
199     }
200 
201     /**
202      * @throws Exception if something goes wrong
203      */
204     @Test
205     @Alerts(EDGE = "redundant")
206     @HtmlUnitNYI(EDGE = "redundant")
207     public void redundantEdge2HtmlUnitNYIEdge() throws Exception {
208         testFail("Redundant @HtmlUnitNYI for Edge in AnnotationUtilsTest.redundantEdge2HtmlUnitNYIEdge()",
209                 "redundantEdge2HtmlUnitNYIEdge");
210     }
211 
212     /**
213      * @throws Exception if something goes wrong
214      */
215     @Test
216     @Alerts(FF = "redundant")
217     @HtmlUnitNYI(FF = "redundant")
218     public void redundantFf2HtmlUnitNYIFf() throws Exception {
219         testFail("Redundant @HtmlUnitNYI for FF in AnnotationUtilsTest.redundantFf2HtmlUnitNYIFf()",
220                 "redundantFf2HtmlUnitNYIFf");
221     }
222 
223     /**
224      * @throws Exception if something goes wrong
225      */
226     @Test
227     @Alerts(FF_ESR = "redundant")
228     @HtmlUnitNYI(FF_ESR = "redundant")
229     public void redundantFfEsr2HtmlUnitNYIFfEsr() throws Exception {
230         testFail("Redundant @HtmlUnitNYI for FF-ESR in AnnotationUtilsTest.redundantFfEsr2HtmlUnitNYIFfEsr()",
231                 "redundantFfEsr2HtmlUnitNYIFfEsr");
232     }
233 
234     private void testFail(final String expectedMsg, final String methodName) throws Exception {
235         final Method method = getClass().getMethod(methodName, (Class[]) null);
236 
237         try {
238             AnnotationUtils.assertAlerts(method);
239             Assert.fail("AssertionError expected");
240         }
241         catch (final AssertionError e) {
242             Assert.assertEquals(expectedMsg, e.getMessage());
243         }
244     }
245 }