From e3b40e4556a7a0c3dc5ef8462f516a1670ab900f Mon Sep 17 00:00:00 2001 From: Egima profile Date: Tue, 1 Nov 2016 22:45:01 +0300 Subject: [PATCH] fixed network interface tetst (#797) * made changes to java reflection * removed redundant method makeSound in Animal abstract class * added project for play-framework article * added project for regex * changed regex project from own model to core-java * added project for routing in play * made changes to regex project * refactored code for REST API with Play project * refactored student store indexing to zero base * added unit tests, removed bad names * added NIO Selector project under core-java module * requested changes made * added project for nio2 * standardized exception based tests * fixed exception based tests * removed redundant files * added network interface project * used UUID other than timestamps * fixed network interface tests * removed filetest change --- .../interfaces/NetworkInterfaceTest.java | 23 +++++++++---------- .../java/com/baeldung/java/nio2/FileTest.java | 19 +++++++++------ 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/core-java/src/test/java/com/baeldung/java/networking/interfaces/NetworkInterfaceTest.java b/core-java/src/test/java/com/baeldung/java/networking/interfaces/NetworkInterfaceTest.java index 743180d57f..4a8ef57b8f 100644 --- a/core-java/src/test/java/com/baeldung/java/networking/interfaces/NetworkInterfaceTest.java +++ b/core-java/src/test/java/com/baeldung/java/networking/interfaces/NetworkInterfaceTest.java @@ -1,8 +1,6 @@ package com.baeldung.java.networking.interfaces; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import java.net.InetAddress; import java.net.InterfaceAddress; @@ -18,44 +16,44 @@ public class NetworkInterfaceTest { @Test public void givenName_whenReturnsNetworkInterface_thenCorrect() throws SocketException { NetworkInterface nif = NetworkInterface.getByName("lo"); - assertFalse(nif == null); + assertNotNull(nif); } @Test public void givenInExistentName_whenReturnsNull_thenCorrect() throws SocketException { NetworkInterface nif = NetworkInterface.getByName("inexistent_name"); - assertTrue(nif == null); + assertNull(nif); } @Test public void givenIP_whenReturnsNetworkInterface_thenCorrect() throws SocketException, UnknownHostException { byte[] ip = new byte[] { 127, 0, 0, 1 }; NetworkInterface nif = NetworkInterface.getByInetAddress(InetAddress.getByAddress(ip)); - assertFalse(nif == null); + assertNotNull(nif); } @Test public void givenHostName_whenReturnsNetworkInterface_thenCorrect() throws SocketException, UnknownHostException { NetworkInterface nif = NetworkInterface.getByInetAddress(InetAddress.getByName("localhost")); - assertFalse(nif == null); + assertNotNull(nif); } @Test public void givenLocalHost_whenReturnsNetworkInterface_thenCorrect() throws SocketException, UnknownHostException { NetworkInterface nif = NetworkInterface.getByInetAddress(InetAddress.getLocalHost()); - assertFalse(nif == null); + assertNotNull(nif); } @Test public void givenLoopBack_whenReturnsNetworkInterface_thenCorrect() throws SocketException, UnknownHostException { NetworkInterface nif = NetworkInterface.getByInetAddress(InetAddress.getLoopbackAddress()); - assertFalse(nif == null); + assertNotNull(nif); } @Test public void givenIndex_whenReturnsNetworkInterface_thenCorrect() throws SocketException, UnknownHostException { NetworkInterface nif = NetworkInterface.getByIndex(0); - assertFalse(nif == null); + assertNotNull(nif); } @Test @@ -112,12 +110,13 @@ public class NetworkInterfaceTest { public void givenInterface_whenGetsMacAddress_thenCorrect() throws SocketException, UnknownHostException { NetworkInterface nif = NetworkInterface.getByName("lo"); byte[] bytes = nif.getHardwareAddress(); - assertFalse(bytes == null); + assertNotNull(bytes); } @Test public void givenInterface_whenGetsMTU_thenCorrect() throws SocketException, UnknownHostException { - NetworkInterface nif = NetworkInterface.getByName("lo"); + NetworkInterface nif = NetworkInterface.getByName("net0"); int mtu = nif.getMTU(); + assertEquals(1500, mtu); } } diff --git a/core-java/src/test/java/com/baeldung/java/nio2/FileTest.java b/core-java/src/test/java/com/baeldung/java/nio2/FileTest.java index 96509945d7..f1cb572d9b 100644 --- a/core-java/src/test/java/com/baeldung/java/nio2/FileTest.java +++ b/core-java/src/test/java/com/baeldung/java/nio2/FileTest.java @@ -1,14 +1,20 @@ package com.baeldung.java.nio2; -import org.junit.Test; - -import java.io.IOException; -import java.nio.file.*; -import java.util.UUID; - import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import java.io.IOException; +import java.nio.file.DirectoryNotEmptyException; +import java.nio.file.FileAlreadyExistsException; +import java.nio.file.Files; +import java.nio.file.NoSuchFileException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; +import java.util.UUID; + +import org.junit.Test; + public class FileTest { private static final String HOME = System.getProperty("user.home"); @@ -155,7 +161,6 @@ public class FileTest { @Test(expected = NoSuchFileException.class) public void givenInexistentFile_whenDeleteFails_thenCorrect() throws IOException { Path p = Paths.get(HOME + "/inexistentFile.txt"); - assertFalse(Files.exists(p)); Files.delete(p); }