1717
1818package org .openqa .selenium .support .events ;
1919
20- import static org .assertj .core .api .Assertions .assertThat ;
21- import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
22- import static org .assertj .core .api .Assertions .assertThatNoException ;
20+ import static org .assertj .core .api .Assertions .*;
2321import static org .mockito .ArgumentMatchers .any ;
2422import static org .mockito .Mockito .doNothing ;
2523import static org .mockito .Mockito .mock ;
@@ -1050,6 +1048,29 @@ public void beforeAnyCall(Object target, Method method, Object[] args) {
10501048 assertThatNoException ().isThrownBy (decorated ::getWindowHandle );
10511049 }
10521050
1051+ @ Test
1052+ void shouldReThrowExceptionInBeforeAnyCall () {
1053+ WebDriver driver = mock (WebDriver .class );
1054+ WebDriverListener listener =
1055+ new WebDriverListener () {
1056+
1057+ @ Override
1058+ public boolean throwsExceptions () {
1059+ return true ;
1060+ }
1061+
1062+ @ Override
1063+ public void beforeAnyCall (Object target , Method method , Object [] args ) {
1064+ throw new RuntimeException ("listener" );
1065+ }
1066+ };
1067+
1068+ WebDriver decorated = new EventFiringDecorator <>(listener ).decorate (driver );
1069+
1070+ assertThatExceptionOfType (WebDriverListenerException .class )
1071+ .isThrownBy (decorated ::getWindowHandle );
1072+ }
1073+
10531074 @ Test
10541075 void shouldSuppressExceptionInBeforeClassMethodCall () {
10551076 WebDriver driver = mock (WebDriver .class );
@@ -1066,6 +1087,29 @@ public void beforeAnyWebDriverCall(WebDriver driver, Method method, Object[] arg
10661087 assertThatNoException ().isThrownBy (decorated ::getWindowHandle );
10671088 }
10681089
1090+ @ Test
1091+ void shouldReThrowExceptionInBeforeClassMethodCall () {
1092+ WebDriver driver = mock (WebDriver .class );
1093+ WebDriverListener listener =
1094+ new WebDriverListener () {
1095+
1096+ @ Override
1097+ public boolean throwsExceptions () {
1098+ return true ;
1099+ }
1100+
1101+ @ Override
1102+ public void beforeAnyWebDriverCall (WebDriver driver , Method method , Object [] args ) {
1103+ throw new RuntimeException ("listener" );
1104+ }
1105+ };
1106+
1107+ WebDriver decorated = new EventFiringDecorator <>(listener ).decorate (driver );
1108+
1109+ assertThatExceptionOfType (WebDriverListenerException .class )
1110+ .isThrownBy (decorated ::getWindowHandle );
1111+ }
1112+
10691113 @ Test
10701114 void shouldSuppressExceptionInBeforeMethod () {
10711115 WebDriver driver = mock (WebDriver .class );
@@ -1082,6 +1126,29 @@ public void beforeGetWindowHandle(WebDriver driver) {
10821126 assertThatNoException ().isThrownBy (decorated ::getWindowHandle );
10831127 }
10841128
1129+ @ Test
1130+ void shouldReThrowExceptionInBeforeMethod () {
1131+ WebDriver driver = mock (WebDriver .class );
1132+ WebDriverListener listener =
1133+ new WebDriverListener () {
1134+
1135+ @ Override
1136+ public boolean throwsExceptions () {
1137+ return true ;
1138+ }
1139+
1140+ @ Override
1141+ public void beforeGetWindowHandle (WebDriver driver ) {
1142+ throw new RuntimeException ("listener" );
1143+ }
1144+ };
1145+
1146+ WebDriver decorated = new EventFiringDecorator <>(listener ).decorate (driver );
1147+
1148+ assertThatExceptionOfType (WebDriverListenerException .class )
1149+ .isThrownBy (decorated ::getWindowHandle );
1150+ }
1151+
10851152 @ Test
10861153 void shouldSuppressExceptionInAfterAnyCall () {
10871154 WebDriver driver = mock (WebDriver .class );
@@ -1098,6 +1165,29 @@ public void afterAnyCall(Object target, Method method, Object[] args, Object res
10981165 assertThatNoException ().isThrownBy (decorated ::getWindowHandle );
10991166 }
11001167
1168+ @ Test
1169+ void shouldReThrowExceptionInAfterAnyCall () {
1170+ WebDriver driver = mock (WebDriver .class );
1171+ WebDriverListener listener =
1172+ new WebDriverListener () {
1173+
1174+ @ Override
1175+ public boolean throwsExceptions () {
1176+ return true ;
1177+ }
1178+
1179+ @ Override
1180+ public void afterAnyCall (Object target , Method method , Object [] args , Object result ) {
1181+ throw new RuntimeException ("listener" );
1182+ }
1183+ };
1184+
1185+ WebDriver decorated = new EventFiringDecorator <>(listener ).decorate (driver );
1186+
1187+ assertThatExceptionOfType (WebDriverListenerException .class )
1188+ .isThrownBy (decorated ::getWindowHandle );
1189+ }
1190+
11011191 @ Test
11021192 void shouldSuppressExceptionInAfterClassMethodCall () {
11031193 WebDriver driver = mock (WebDriver .class );
@@ -1115,6 +1205,30 @@ public void afterAnyWebDriverCall(
11151205 assertThatNoException ().isThrownBy (decorated ::getWindowHandle );
11161206 }
11171207
1208+ @ Test
1209+ void shouldReThrowExceptionInAfterClassMethodCall () {
1210+ WebDriver driver = mock (WebDriver .class );
1211+ WebDriverListener listener =
1212+ new WebDriverListener () {
1213+
1214+ @ Override
1215+ public boolean throwsExceptions () {
1216+ return true ;
1217+ }
1218+
1219+ @ Override
1220+ public void afterAnyWebDriverCall (
1221+ WebDriver driver , Method method , Object [] args , Object result ) {
1222+ throw new RuntimeException ("listener" );
1223+ }
1224+ };
1225+
1226+ WebDriver decorated = new EventFiringDecorator <>(listener ).decorate (driver );
1227+
1228+ assertThatExceptionOfType (WebDriverListenerException .class )
1229+ .isThrownBy (decorated ::getWindowHandle );
1230+ }
1231+
11181232 @ Test
11191233 void shouldSuppressExceptionInAfterMethod () {
11201234 WebDriver driver = mock (WebDriver .class );
@@ -1131,6 +1245,29 @@ public void afterGetWindowHandle(WebDriver driver, String result) {
11311245 assertThatNoException ().isThrownBy (decorated ::getWindowHandle );
11321246 }
11331247
1248+ @ Test
1249+ void shouldReThrowExceptionInAfterMethod () {
1250+ WebDriver driver = mock (WebDriver .class );
1251+ WebDriverListener listener =
1252+ new WebDriverListener () {
1253+
1254+ @ Override
1255+ public boolean throwsExceptions () {
1256+ return true ;
1257+ }
1258+
1259+ @ Override
1260+ public void afterGetWindowHandle (WebDriver driver , String result ) {
1261+ throw new RuntimeException ("listener" );
1262+ }
1263+ };
1264+
1265+ WebDriver decorated = new EventFiringDecorator <>(listener ).decorate (driver );
1266+
1267+ assertThatExceptionOfType (WebDriverListenerException .class )
1268+ .isThrownBy (decorated ::getWindowHandle );
1269+ }
1270+
11341271 @ Test
11351272 void shouldSuppressExceptionInOnError () {
11361273 WebDriver driver = mock (WebDriver .class );
0 commit comments