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
This commit is contained in:
Egima profile 2016-11-01 22:45:01 +03:00 committed by Grzegorz Piwowarek
parent 0532349b4e
commit e3b40e4556
2 changed files with 23 additions and 19 deletions

View File

@ -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);
}
}

View File

@ -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);
}