From 57850893ab80ef3e144e500f9342ed53bfe33823 Mon Sep 17 00:00:00 2001 From: pkaras Date: Fri, 12 Apr 2019 13:05:18 +0200 Subject: Junits for classes in util package Change-Id: If1d692b961533722ca72ec13707099858715542b Issue-ID: DMAAP-1159 Signed-off-by: piotr.karas --- .../org/onap/dmaap/dbcapi/util/DmaapConfig.java | 4 +- .../org/onap/dmaap/dbcapi/util/DmaapTimestamp.java | 43 ++++++++++------------ .../java/org/onap/dmaap/dbcapi/util/Graph.java | 4 +- .../org/onap/dmaap/dbcapi/util/RandomInteger.java | 21 +---------- 4 files changed, 23 insertions(+), 49 deletions(-) (limited to 'src/main') diff --git a/src/main/java/org/onap/dmaap/dbcapi/util/DmaapConfig.java b/src/main/java/org/onap/dmaap/dbcapi/util/DmaapConfig.java index cfcdc1c..a47c0bd 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/util/DmaapConfig.java +++ b/src/main/java/org/onap/dmaap/dbcapi/util/DmaapConfig.java @@ -37,10 +37,8 @@ public class DmaapConfig extends Properties { return(configfname); } private DmaapConfig() { - try { - InputStream is = new FileInputStream(configfname); + try (InputStream is = new FileInputStream(configfname)){ load(is); - is.close(); } catch (Exception e) { System.err.println("Unable to load configuration file " + configfname); org.apache.log4j.Logger.getLogger(getClass()).fatal("Unable to load configuration file " + configfname, e); diff --git a/src/main/java/org/onap/dmaap/dbcapi/util/DmaapTimestamp.java b/src/main/java/org/onap/dmaap/dbcapi/util/DmaapTimestamp.java index 776a4b4..f36df1c 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/util/DmaapTimestamp.java +++ b/src/main/java/org/onap/dmaap/dbcapi/util/DmaapTimestamp.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,30 +20,27 @@ package org.onap.dmaap.dbcapi.util; -import java.util.Calendar; -import java.util.Date; - import javax.xml.bind.annotation.XmlRootElement; - -import org.apache.log4j.Logger; +import java.util.Date; @XmlRootElement public class DmaapTimestamp { - static final Logger logger = Logger.getLogger(DmaapTimestamp.class); - private Calendar cal = Calendar.getInstance(); - private Date stamp; - - public DmaapTimestamp() { - - stamp = cal.getTime(); - } - - public void mark() { - stamp = cal.getTime(); - } - - public Date getVal() { - return stamp; - } + private Date stamp; + + public DmaapTimestamp() { + this(new Date()); + } + + DmaapTimestamp(Date stamp) { + this.stamp = new Date(stamp.getTime()); + } + + public void mark() { + stamp = new Date(); + } + + public Date getVal() { + return new Date(stamp.getTime()); + } } diff --git a/src/main/java/org/onap/dmaap/dbcapi/util/Graph.java b/src/main/java/org/onap/dmaap/dbcapi/util/Graph.java index 700c77f..ab40765 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/util/Graph.java +++ b/src/main/java/org/onap/dmaap/dbcapi/util/Graph.java @@ -53,19 +53,17 @@ public class Graph { if ( clients == null ) return; initGraph( clients, strict, "" ); - return; } public Graph( List clients, boolean strict, String group ) { if ( clients == null ) return; initGraph( clients, strict, group ); - return; } private void initGraph(List clients, boolean strict, String group ) { MR_ClusterService clusters = new MR_ClusterService(); - this.graph = new HashMap(); + this.graph = new HashMap<>(); this.hasCentral = false; for( MR_Client client: clients ) { if ( ! strict || client.isStatusValid()) { diff --git a/src/main/java/org/onap/dmaap/dbcapi/util/RandomInteger.java b/src/main/java/org/onap/dmaap/dbcapi/util/RandomInteger.java index ea8483f..1c9bc11 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/util/RandomInteger.java +++ b/src/main/java/org/onap/dmaap/dbcapi/util/RandomInteger.java @@ -25,7 +25,6 @@ import java.util.Date; // with some modifications import java.util.Random; - public final class RandomInteger { private static Random randomGenerator; private int range; @@ -39,24 +38,6 @@ public final class RandomInteger { public int next(){ return randomGenerator.nextInt(range); } - -/** Generate 10 random integers in the range 0..99. - public static final void main(String... aArgs){ - log("Generating 10 random integers in range 0..99."); - RandomInteger ri = new RandomInteger(100); - //note a single Random object is reused here - - for (int idx = 1; idx <= 10; ++idx){ - int randomInt = ri.next(); - log("Generated : " + randomInt); - } - - log("Done."); - } - - private static void log(String aMessage){ - System.out.println(aMessage); - } -*/ + } -- cgit 1.2.3-korg