diff --git a/jbehave-support-core/src/main/java/org/jbehavesupport/core/filtering/GroovyMetaFilterBuilder.java b/jbehave-support-core/src/main/java/org/jbehavesupport/core/filtering/GroovyMetaFilterBuilder.java index e5c9993e..a1f60d32 100644 --- a/jbehave-support-core/src/main/java/org/jbehavesupport/core/filtering/GroovyMetaFilterBuilder.java +++ b/jbehave-support-core/src/main/java/org/jbehavesupport/core/filtering/GroovyMetaFilterBuilder.java @@ -150,10 +150,10 @@ public void parse(String filterAsString) { */ public boolean match(Meta meta) { try { - Object matcher = this.groovyClass.newInstance(); + Object matcher = this.groovyClass.getDeclaredConstructor().newInstance(); this.metaField.set(matcher, meta); return (Boolean) this.match.invoke(matcher); - } catch (InstantiationException | InvocationTargetException | IllegalAccessException e) { + } catch (InstantiationException | InvocationTargetException | IllegalAccessException | NoSuchMethodException e) { throw new IllegalArgumentException("Can't instantiate dynamic groovy matcher", e); } } diff --git a/jbehave-support-core/src/main/java/org/jbehavesupport/core/internal/healthcheck/HttpHealthCheckImpl.java b/jbehave-support-core/src/main/java/org/jbehavesupport/core/internal/healthcheck/HttpHealthCheckImpl.java index 918d7b34..58676cda 100644 --- a/jbehave-support-core/src/main/java/org/jbehavesupport/core/internal/healthcheck/HttpHealthCheckImpl.java +++ b/jbehave-support-core/src/main/java/org/jbehavesupport/core/internal/healthcheck/HttpHealthCheckImpl.java @@ -5,7 +5,6 @@ import org.apache.hc.client5.http.classic.methods.HttpGet; import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider; import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; -import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; import org.apache.hc.client5.http.impl.classic.HttpClients; import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder; import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory; @@ -51,11 +50,14 @@ public void check() { .build(); HttpGet httpGet = new HttpGet(url); - CloseableHttpResponse response = httpclient.execute(httpGet); - if (response.getCode() != 200) { - throw new IllegalStateException( - "Status code is " + response.getCode() + ". " + response.getReasonPhrase()); - } + httpclient.execute(httpGet, response -> { + if (response.getCode() != 200) { + throw new IllegalStateException( + "Status code is " + response.getCode() + ". " + response.getReasonPhrase()); + } + return null; + }); + } catch (IOException | NoSuchAlgorithmException | KeyManagementException | KeyStoreException e) { throw new IllegalStateException(e); } diff --git a/jbehave-support-core/src/main/java/org/jbehavesupport/core/support/RequestFactory.java b/jbehave-support-core/src/main/java/org/jbehavesupport/core/support/RequestFactory.java index ced2c741..9af69e47 100644 --- a/jbehave-support-core/src/main/java/org/jbehavesupport/core/support/RequestFactory.java +++ b/jbehave-support-core/src/main/java/org/jbehavesupport/core/support/RequestFactory.java @@ -10,6 +10,7 @@ import java.beans.PropertyDescriptor; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.lang.reflect.ParameterizedType; @@ -144,7 +145,7 @@ public REQUEST createRequest() { prefix = requestClazz.getSimpleName(); } try { - REQUEST request = requestClazz.newInstance(); + REQUEST request = requestClazz.getDeclaredConstructor().newInstance(); factoryContext.put(prefix, request); handleKeys(); return request; @@ -223,7 +224,7 @@ private void handleCollectionIndexStep() throws ReflectiveOperationException { if (isAbstract(type)) { throw new UnsupportedOperationException("Abstract classes are not supported as generic"); } - Object value = type.newInstance(); + Object value = type.getDeclaredConstructor().newInstance(); Object collection = factoryContext.get(pathPrevious); ((Collection) collection).add(value); factoryContext.put(pathCurrent, value); @@ -239,7 +240,7 @@ private void handleNestedStep() throws ReflectiveOperationException { } else if (isAssignable(type, JAXBElement.class)) { value = resolveJaxbElement(testContext, pathCurrent, null); } else if (!isAbstract(type)) { - value = type.newInstance(); + value = type.getDeclaredConstructor().newInstance(); } else { throw new IllegalStateException( "Field " + pathCurrent + " is abstract. Please provide fully qualified class name in example table or register custom handler"); @@ -368,10 +369,10 @@ private XmlElementRef getXmlElementRef() { private Object instantiateClass(Class toInstantiate) { try { - return toInstantiate.newInstance(); + return toInstantiate.getDeclaredConstructor().newInstance(); } catch (IllegalAccessException e) { throw new IllegalStateException("Provided implementation is not accessible: " + toInstantiate.getSimpleName(), e); - } catch (InstantiationException e) { + } catch (InstantiationException | NoSuchMethodException | InvocationTargetException e) { throw new IllegalStateException("Provided implementation could not be instantiated: " + toInstantiate.getSimpleName(), e); } } diff --git a/jbehave-support-core/src/test/groovy/org/jbehavesupport/core/sql/CompareExpectedRowsFalseStrictMatch.groovy b/jbehave-support-core/src/test/groovy/org/jbehavesupport/core/sql/CompareExpectedRowsFalseStrictMatch.groovy index 9d2037f9..cca20916 100644 --- a/jbehave-support-core/src/test/groovy/org/jbehavesupport/core/sql/CompareExpectedRowsFalseStrictMatch.groovy +++ b/jbehave-support-core/src/test/groovy/org/jbehavesupport/core/sql/CompareExpectedRowsFalseStrictMatch.groovy @@ -19,8 +19,8 @@ class CompareExpectedRowsFalseStrictMatch extends Specification { def expectations = new ExamplesTable("| INT | DOUBLE | DECIMAL | STRING | DATE |\r\n" + "| 1 | 1.01 | 10.01 | fsa#df | 2010-10-10T10:10:10 |\r\n") def row = new HashMap(){{ - put("INT",new Integer(1)) - put("DOUBLE",new Double(1.01)) + put("INT", Integer.valueOf(1)) + put("DOUBLE", Double.valueOf(1.01)) put("DECIMAL",new BigDecimal("10.01")) put("STRING",new String("fsa#df")) put("DATE", LocalDateTime.of(2010, Month.OCTOBER, 10, 10, 10, 10))}}