Skip to content

Commit e3b40e4

Browse files
Egima profilepivovarit
authored andcommitted
fixed network interface tetst (eugenp#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
1 parent 0532349 commit e3b40e4

2 files changed

Lines changed: 21 additions & 17 deletions

File tree

‎core-java/src/test/java/com/baeldung/java/networking/interfaces/NetworkInterfaceTest.java‎

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.baeldung.java.networking.interfaces;
22

3-
import static org.junit.Assert.assertEquals;
4-
import static org.junit.Assert.assertFalse;
5-
import static org.junit.Assert.assertTrue;
3+
import static org.junit.Assert.*;
64

75
import java.net.InetAddress;
86
import java.net.InterfaceAddress;
@@ -18,44 +16,44 @@ public class NetworkInterfaceTest {
1816
@Test
1917
public void givenName_whenReturnsNetworkInterface_thenCorrect() throws SocketException {
2018
NetworkInterface nif = NetworkInterface.getByName("lo");
21-
assertFalse(nif == null);
19+
assertNotNull(nif);
2220
}
2321

2422
@Test
2523
public void givenInExistentName_whenReturnsNull_thenCorrect() throws SocketException {
2624
NetworkInterface nif = NetworkInterface.getByName("inexistent_name");
27-
assertTrue(nif == null);
25+
assertNull(nif);
2826
}
2927

3028
@Test
3129
public void givenIP_whenReturnsNetworkInterface_thenCorrect() throws SocketException, UnknownHostException {
3230
byte[] ip = new byte[] { 127, 0, 0, 1 };
3331
NetworkInterface nif = NetworkInterface.getByInetAddress(InetAddress.getByAddress(ip));
34-
assertFalse(nif == null);
32+
assertNotNull(nif);
3533
}
3634

3735
@Test
3836
public void givenHostName_whenReturnsNetworkInterface_thenCorrect() throws SocketException, UnknownHostException {
3937
NetworkInterface nif = NetworkInterface.getByInetAddress(InetAddress.getByName("localhost"));
40-
assertFalse(nif == null);
38+
assertNotNull(nif);
4139
}
4240

4341
@Test
4442
public void givenLocalHost_whenReturnsNetworkInterface_thenCorrect() throws SocketException, UnknownHostException {
4543
NetworkInterface nif = NetworkInterface.getByInetAddress(InetAddress.getLocalHost());
46-
assertFalse(nif == null);
44+
assertNotNull(nif);
4745
}
4846

4947
@Test
5048
public void givenLoopBack_whenReturnsNetworkInterface_thenCorrect() throws SocketException, UnknownHostException {
5149
NetworkInterface nif = NetworkInterface.getByInetAddress(InetAddress.getLoopbackAddress());
52-
assertFalse(nif == null);
50+
assertNotNull(nif);
5351
}
5452

5553
@Test
5654
public void givenIndex_whenReturnsNetworkInterface_thenCorrect() throws SocketException, UnknownHostException {
5755
NetworkInterface nif = NetworkInterface.getByIndex(0);
58-
assertFalse(nif == null);
56+
assertNotNull(nif);
5957
}
6058

6159
@Test
@@ -112,12 +110,13 @@ public void givenInterface_whenChecksMulticastSupport_thenCorrect() throws Socke
112110
public void givenInterface_whenGetsMacAddress_thenCorrect() throws SocketException, UnknownHostException {
113111
NetworkInterface nif = NetworkInterface.getByName("lo");
114112
byte[] bytes = nif.getHardwareAddress();
115-
assertFalse(bytes == null);
113+
assertNotNull(bytes);
116114
}
117115

118116
@Test
119117
public void givenInterface_whenGetsMTU_thenCorrect() throws SocketException, UnknownHostException {
120-
NetworkInterface nif = NetworkInterface.getByName("lo");
118+
NetworkInterface nif = NetworkInterface.getByName("net0");
121119
int mtu = nif.getMTU();
120+
assertEquals(1500, mtu);
122121
}
123122
}

‎core-java/src/test/java/com/baeldung/java/nio2/FileTest.java‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
package com.baeldung.java.nio2;
22

3-
import org.junit.Test;
3+
import static org.junit.Assert.assertFalse;
4+
import static org.junit.Assert.assertTrue;
45

56
import java.io.IOException;
6-
import java.nio.file.*;
7+
import java.nio.file.DirectoryNotEmptyException;
8+
import java.nio.file.FileAlreadyExistsException;
9+
import java.nio.file.Files;
10+
import java.nio.file.NoSuchFileException;
11+
import java.nio.file.Path;
12+
import java.nio.file.Paths;
13+
import java.nio.file.StandardCopyOption;
714
import java.util.UUID;
815

9-
import static org.junit.Assert.assertFalse;
10-
import static org.junit.Assert.assertTrue;
16+
import org.junit.Test;
1117

1218
public class FileTest {
1319
private static final String HOME = System.getProperty("user.home");
@@ -155,7 +161,6 @@ public void givenPath_whenFailsToDeleteNonEmptyDir_thenCorrect() throws IOExcept
155161
@Test(expected = NoSuchFileException.class)
156162
public void givenInexistentFile_whenDeleteFails_thenCorrect() throws IOException {
157163
Path p = Paths.get(HOME + "/inexistentFile.txt");
158-
assertFalse(Files.exists(p));
159164
Files.delete(p);
160165
}
161166

0 commit comments

Comments
 (0)