summaryrefslogtreecommitdiffstats
path: root/dcae-analytics/dcae-analytics-test/src/main
diff options
context:
space:
mode:
authorParshad Patel <pars.patel@samsung.com>2019-05-22 19:39:03 +0900
committerParshad Patel <pars.patel@samsung.com>2019-05-22 20:03:48 +0900
commite082ec51afc604500b10f246b16811e03ed4b7ea (patch)
treeecf14d2ae1ad5c4e4438abcf93b338d615904024 /dcae-analytics/dcae-analytics-test/src/main
parentddb39820395d7fcb8a898eff9e08bc725680e3c2 (diff)
Fix sonar issues in dcaegen2-analytics-tca-gen2
Fix Extract this nested try block into a separate method Fix Either log or rethrow this exception Fix Remove this throw statement from this finally block Issue-ID: DCAEGEN2-1384 Change-Id: Icb9a376a57d0ec2466c679f821fb0d346df769e7 Signed-off-by: Parshad Patel <pars.patel@samsung.com>
Diffstat (limited to 'dcae-analytics/dcae-analytics-test/src/main')
-rw-r--r--dcae-analytics/dcae-analytics-test/src/main/java/org/onap/dcae/analytics/test/BaseAnalyticsTest.java38
1 files changed, 15 insertions, 23 deletions
diff --git a/dcae-analytics/dcae-analytics-test/src/main/java/org/onap/dcae/analytics/test/BaseAnalyticsTest.java b/dcae-analytics/dcae-analytics-test/src/main/java/org/onap/dcae/analytics/test/BaseAnalyticsTest.java
index 8b2958e..955cab8 100644
--- a/dcae-analytics/dcae-analytics-test/src/main/java/org/onap/dcae/analytics/test/BaseAnalyticsTest.java
+++ b/dcae-analytics/dcae-analytics-test/src/main/java/org/onap/dcae/analytics/test/BaseAnalyticsTest.java
@@ -216,22 +216,21 @@ abstract class BaseAnalyticsTest {
final Class<?> objectClass = object.getClass();
try {
final Field privateField = objectClass.getDeclaredField(fieldName);
- try {
- // mark private field to be accessible for testing purposes
- AccessController.doPrivileged((PrivilegedAction) () -> {
- privateField.setAccessible(true);
- return null;
- });
+ // mark private field to be accessible for testing purposes
+ AccessController.doPrivileged((PrivilegedAction) () -> {
+ privateField.setAccessible(true);
+ return null;
+ });
- return privateFieldClass.cast(privateField.get(object));
+ return privateFieldClass.cast(privateField.get(object));
- } catch (IllegalAccessException e) {
- logger.error("Unable to access field: {}", fieldName);
- throw new IllegalStateException(e);
- }
+ } catch (IllegalAccessException e) {
+ logger.error("Unable to access field: {}", fieldName);
+ throw new IllegalStateException(e);
} catch (NoSuchFieldException e) {
- logger.error("Unable to locate field name: {} in class: {}", fieldName, objectClass.getSimpleName());
+ logger.error("Unable to locate field name: {} in class: {}", fieldName,
+ objectClass.getSimpleName());
throw new IllegalStateException(e);
}
@@ -272,22 +271,14 @@ abstract class BaseAnalyticsTest {
*/
public static <T> T deserializeJsonFileToModel(final String jsonFileLocation, final Class<T> modelClass,
final ObjectMapper objectMapper) {
- final InputStream jsonFileInputStream =
- BaseAnalyticsTest.class.getClassLoader().getResourceAsStream(jsonFileLocation);
- assertThat(jsonFileInputStream).as("Input JSON File location must be valid").isNotNull();
- try {
+ try( final InputStream jsonFileInputStream =
+ BaseAnalyticsTest.class.getClassLoader().getResourceAsStream(jsonFileLocation)) {
+ assertThat(jsonFileInputStream).as("Input JSON File location must be valid").isNotNull();
return objectMapper.readValue(jsonFileInputStream, modelClass);
} catch (IOException ex) {
logger.error("Error while doing assert Json for fileLocation: {}, modelClass: {}, Exception {}",
jsonFileLocation, modelClass, ex);
throw new RuntimeException(ex);
- } finally {
- try {
- jsonFileInputStream.close();
- } catch (IOException e) {
- logger.error("Error while closing input stream at file location: {}", jsonFileLocation);
- throw new RuntimeException(e);
- }
}
}
@@ -417,6 +408,7 @@ abstract class BaseAnalyticsTest {
Map<String, String> cienv = (Map<String, String>) theCaseInsensitiveEnvironmentField.get(null);
cienv.putAll(testEnvironmentVariables);
} catch (NoSuchFieldException e) {
+ logger.error("NoSuchFieldException in setEnvironmentVariables", e);
Class[] classes = Collections.class.getDeclaredClasses();
Map<String, String> env = System.getenv();
for (Class cl : classes) {