/******************************************************************************
 *                                                                            *
 *                    Copyright 2017 Subterranean Security                    *
 *                                                                            *
 *  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.  *
 *  See the License for the specific language governing permissions and       *
 *  limitations under the License.                                            *
 *                                                                            *
 *****************************************************************************/
package com.sandpolis.core.util;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;

import org.junit.jupiter.api.Test;

public class NetUtilTest {

	@Test
	public void testDownload() throws IOException {
		// First download to memory
		assertNotNull(NetUtil.download("https://github.com/Subterranean-Security/Sandpolis/blob/master/.gitignore"));

		// Now download to a file
		File out = Files.createTempFile(null, null).toFile();
		assertEquals(0, out.length());
		NetUtil.download("https://github.com/Subterranean-Security/Sandpolis/blob/master/.gitignore", out);
		assertTrue(out.length() > 0);
		out.delete();
	}

	@Test
	public void testDownloadTooLarge() throws IOException {
		assertThrows(IllegalArgumentException.class,
				() -> NetUtil.download("http://old-releases.ubuntu.com/releases/11.04/ubuntu-11.04-desktop-amd64.iso"));
	}

	@Test
	public void testCheckPort() {
		assertTrue(NetUtil.checkPort("www.google.com", 80));
		assertFalse(NetUtil.checkPort("www.example.com", 81));
		assertFalse(NetUtil.checkPort("8.8.8.8", 80));
	}

}

@@ -1405,53 +1405,105 @@
 tic 
-org.junit.jupiter.api.Assertions.assertEquals
+com.sandpolis.core.util.NetUtil.checkPort;%0Aimport static com.sandpolis.core.util.NetUtil.download
 ;%0Aim
@@ -1747,29 +1747,8 @@
 e;%0A%0A
-import java.io.File;%0A
 impo
@@ -1803,105 +1803,250 @@
 es;%0A
-%0Aimport org.junit.jupiter.api.Test;%0A%0Apublic class NetUtilTest %7B%0A%0A%09@Test%0A%09public void testD
+import java.nio.file.Path;%0A%0Aimport org.junit.jupiter.api.DisplayName;%0Aimport org.junit.jupiter.api.Test;%0Aimport org.junit.jupiter.api.io.TempDir;%0A%0Aclass NetUtilTest %7B%0A%0A%09@Test%0A%09@DisplayName(%22Download a small file into memory%22)%0A%09void d
 ownload
+_1
 () t
@@ -2071,60 +2071,22 @@
 %7B%0A%09%09
-// First download to memory%0A%09%09assertNotNull(NetUtil.
+byte%5B%5D file = 
 down
@@ -2170,139 +2170,193 @@
 re%22)
-)
 ;%0A%0A%09%09
-// Now download to a 
+assertNotNull(
 file
+);
 %0A%09%09
-File out = Files.createTempFile(null, null).toFile();%0A%09%09assertEquals(0, out.length());%0A%09%09NetUtil.
+assertTrue(file.length %3E 0);%0A%09%7D%0A%0A%09@Test%0A%09@DisplayName(%22Download a small file to the filesystem%22)%0A%09void download_2(@TempDir Path temp) throws IOException %7B%0A%09%09
 down
@@ -2440,15 +2440,50 @@
 re%22,
- out
+%0A%09%09%09%09temp.resolve(%22test.txt%22).toFile()
 );%0A
+%0A
 %09%09as
@@ -2495,87 +2495,204 @@
 rue(
-out.length() %3E 0);%0A%09%09out.delete();%0A%09%7D%0A%0A%09@Test%0A%09public void testDownloadTooLarge
+Files.exists(temp.resolve(%22test.txt%22)));%0A%09%09assertTrue(Files.size(temp.resolve(%22test.txt%22)) %3E 0);%0A%09%7D%0A%0A%09@Test%0A%09@DisplayName(%22Try to download a file that is too big for this method%22)%0A%09void download_3
 () t
@@ -2768,24 +2768,16 @@
 %09%09() -%3E 
-NetUtil.
 download
@@ -2875,33 +2875,67 @@
 st%0A%09
-public void testC
+@DisplayName(%22Check some well-known ports%22)%0A%09void c
 heckPort
 () %7B
@@ -2930,16 +2930,18 @@
 heckPort
+_1
 () %7B%0A%09%09a
@@ -2950,24 +2950,16 @@
 ertTrue(
-NetUtil.
 checkPor
@@ -2994,32 +2994,24 @@
 assertFalse(
-NetUtil.
 checkPort(%22w
@@ -3017,13 +3017,12 @@
 www.
-examp
+goog
 le.c
@@ -3036,57 +3036,8 @@
 ));%0A
-%09%09assertFalse(NetUtil.checkPort(%228.8.8.8%22, 80));%0A
 %09%7D%0A%0A

Clean up NetUtilTest