From 57293e84a0aa7405c9688448483d811d707e199a Mon Sep 17 00:00:00 2001 From: Joss Armstrong Date: Thu, 21 Feb 2019 19:16:35 +0000 Subject: Test coverage in MetricRegistryImpl Added test coverage for MetricRegistryImpl Issue-ID: APPC-1478 Change-Id: I91eff5418ec14d294fa80af3d6d7025338b82072 Signed-off-by: Joss Armstrong --- .../onap/appc/metricservice/impl/MetricRegistryImpl.java | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'appc-metric/appc-metric-bundle/src/main') diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/impl/MetricRegistryImpl.java b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/impl/MetricRegistryImpl.java index af05285d0..48d1c6fac 100644 --- a/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/impl/MetricRegistryImpl.java +++ b/appc-metric/appc-metric-bundle/src/main/java/org/onap/appc/metricservice/impl/MetricRegistryImpl.java @@ -5,6 +5,8 @@ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs + * ================================================================================ + * Modifications Copyright (C) 2019 Ericsson * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,7 +40,7 @@ import org.onap.appc.metricservice.policy.impl.PolicyBuilderFactoryImpl; public class MetricRegistryImpl implements MetricRegistry { private String name; - private Map concurrentMetricMap=new ConcurrentHashMap(); + private Map concurrentMetricMap = new ConcurrentHashMap<>(); public MetricRegistryImpl(String name) { this.name = name; @@ -46,11 +48,7 @@ public class MetricRegistryImpl implements MetricRegistry { @Override public boolean register(Metric metric) { - if(concurrentMetricMap.get(metric.name())==null){ - concurrentMetricMap.put(metric.name(),metric); - return true; - } - return false; + return (concurrentMetricMap.putIfAbsent(metric.name(), metric) == null); } @Override @@ -70,11 +68,7 @@ public class MetricRegistryImpl implements MetricRegistry { @Override public Counter counter(String value) { - if(concurrentMetricMap.get(value)!=null ) - return (Counter)concurrentMetricMap.get(value) ; - else - return null; - + return (Counter)concurrentMetricMap.get(value); } @Override -- cgit 1.2.3-korg