aboutsummaryrefslogtreecommitdiffstats
path: root/utils/src/test/java/org/onap/policy/common/utils/network/NetworkUtilTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'utils/src/test/java/org/onap/policy/common/utils/network/NetworkUtilTest.java')
-rw-r--r--utils/src/test/java/org/onap/policy/common/utils/network/NetworkUtilTest.java19
1 files changed, 15 insertions, 4 deletions
diff --git a/utils/src/test/java/org/onap/policy/common/utils/network/NetworkUtilTest.java b/utils/src/test/java/org/onap/policy/common/utils/network/NetworkUtilTest.java
index a0b8353d..4019ca79 100644
--- a/utils/src/test/java/org/onap/policy/common/utils/network/NetworkUtilTest.java
+++ b/utils/src/test/java/org/onap/policy/common/utils/network/NetworkUtilTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* policy-utils
* ================================================================================
- * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,8 +20,10 @@
package org.onap.policy.common.utils.network;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -67,7 +69,7 @@ public class NetworkUtilTest {
public void testAllocPort_testAllocPortString__testAllocPortInetSocketAddress() throws Exception {
// allocate wild-card port
int wildCardPort = NetworkUtil.allocPort();
- assertTrue(wildCardPort != 0);
+ assertNotEquals(0, wildCardPort);
// verify that we can listen on the port
try (ServerSocket wildSocket = new ServerSocket(wildCardPort)) {
@@ -78,10 +80,10 @@ public class NetworkUtilTest {
// allocate port using host name
int localPort = NetworkUtil.allocPort(LOCALHOST);
- assertTrue(localPort != 0);
+ assertNotEquals(0, localPort);
// the OS should have allocated a new port, even though the first has been closed
- assertTrue(localPort != wildCardPort);
+ assertNotEquals(wildCardPort, localPort);
try (ServerSocket localSocket = new ServerSocket()) {
localSocket.bind(new InetSocketAddress(LOCALHOST, localPort));
@@ -90,6 +92,15 @@ public class NetworkUtilTest {
}
}
+ @Test
+ public void testGenUniqueName() {
+ String name = NetworkUtil.genUniqueName(LOCALHOST);
+ assertThat(name).isNotBlank().isNotEqualTo(LOCALHOST);
+
+ // second call should generate a different value
+ assertThat(NetworkUtil.genUniqueName(LOCALHOST)).isNotEqualTo(name);
+ }
+
/**
* Thread that accepts a connection on a socket.
*/