From bb0da1b7db38e6db5b4d36d0fe6bf1020f9f0810 Mon Sep 17 00:00:00 2001 From: Jeremy Landis Date: Tue, 5 Mar 2024 09:59:32 -0500 Subject: [PATCH] [java] For java 9+ make sure we use non deprecated new instance (#1169) --- .../generators/integrations/helpers/WebAssertion.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/test/java/net/masterthought/cucumber/generators/integrations/helpers/WebAssertion.java b/src/test/java/net/masterthought/cucumber/generators/integrations/helpers/WebAssertion.java index 3ada5a612..5b5316349 100644 --- a/src/test/java/net/masterthought/cucumber/generators/integrations/helpers/WebAssertion.java +++ b/src/test/java/net/masterthought/cucumber/generators/integrations/helpers/WebAssertion.java @@ -2,6 +2,7 @@ import static org.assertj.core.api.Assertions.assertThat; +import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -81,10 +82,10 @@ public T[] allByClass(String cssClass, Class clazz) private T toAssertion(Element inner, Class clazz) { T assertion = null; try { - assertion = (T) clazz.newInstance(); + assertion = (T) clazz.getDeclaredConstructor().newInstance(); assertion.element = inner; return assertion; - } catch (InstantiationException | IllegalAccessException e) { + } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { throw new IllegalArgumentException(e); } } @@ -106,8 +107,8 @@ private T[] toArray(Elements inners, Class clazz) { for (Element element : inners) { T assertion = null; try { - assertion = (T) clazz.newInstance(); - } catch (InstantiationException | IllegalAccessException e) { + assertion = (T) clazz.getDeclaredConstructor().newInstance(); + } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { throw new IllegalArgumentException(e); } assertion.element = element;