updated the port tests to the fixed findFreePort code
This commit is contained in:
parent
83910eca72
commit
4d17f10323
1 changed files with 27 additions and 21 deletions
|
|
@ -31,31 +31,37 @@ class PortCheckerTest {
|
|||
}
|
||||
}
|
||||
@Test
|
||||
void invalidPort(){
|
||||
PortChecker checker = new PortChecker();
|
||||
|
||||
assertThrows(IllegalArgumentException.class, ()-> {
|
||||
checker.isPortAvailable(-1);
|
||||
}
|
||||
);
|
||||
assertThrows(IllegalArgumentException.class, ()-> {
|
||||
checker.isPortAvailable(65536);
|
||||
}
|
||||
);
|
||||
}
|
||||
@Test
|
||||
void findFreePort() throws IOException {
|
||||
void findNotDefaultFreePort() throws IOException {
|
||||
PortChecker checker = new PortChecker();
|
||||
|
||||
int port = checker.findFreePort();
|
||||
int defaultPort = 8080;
|
||||
int lastPort = 8090;
|
||||
int lowestPossiblePort = 0;
|
||||
int highestPossiblePort = 65535;
|
||||
|
||||
boolean greaterOrEqual = port >= defaultPort;
|
||||
boolean lessOrEqual = port <= lastPort;
|
||||
boolean inRange = greaterOrEqual && lessOrEqual;
|
||||
boolean isItFree = checker.isPortAvailable(port);
|
||||
assertTrue(port > lowestPossiblePort);
|
||||
assertTrue(port <= highestPossiblePort);
|
||||
assertTrue(checker.isPortAvailable(port));
|
||||
}
|
||||
@Test
|
||||
void findDefaultFreePort() throws IOException {
|
||||
PortChecker checker = new PortChecker();
|
||||
|
||||
assertTrue(inRange);
|
||||
boolean free = checker.isPortAvailable(8080);
|
||||
|
||||
assertTrue(free);
|
||||
assertEquals(checker.findFreePort(),8080);
|
||||
}
|
||||
|
||||
@Test
|
||||
void invalidFreePort(){
|
||||
PortChecker checker = new PortChecker();
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () ->
|
||||
checker.isPortAvailable(-1)
|
||||
);
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () ->
|
||||
checker.isPortAvailable(65536)
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue