Skip to content

Commit

Permalink
Adjustment for test for initSocket method in main
Browse files Browse the repository at this point in the history
  • Loading branch information
robinalfengard committed Feb 5, 2024
1 parent 00dd4b8 commit f254836
Showing 2 changed files with 11 additions and 16 deletions.
6 changes: 4 additions & 2 deletions src/main/java/org/fungover/haze/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.fungover.haze;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
@@ -10,6 +12,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {
static boolean serverOpen = true;
static Logger logger = LogManager.getLogger(Main.class);
@@ -67,7 +70,6 @@ private static void handleThread(HazeList hazeList, HazeDatabase hazeDatabase, S

private static void controlCommand(HazeList hazeList, HazeDatabase hazeDatabase, Socket client, List<String> inputList) throws IOException {
client.getOutputStream().write(executeCommand(hazeDatabase, inputList, hazeList).getBytes());

inputList.forEach(System.out::println); // For checking incoming message
}

@@ -140,7 +142,7 @@ private static String commandSwitch(HazeDatabase hazeDatabase, List<String> inpu
};
}

private static void readInputStream(BufferedReader input, List<String> inputList, String firstReading) throws
public static void readInputStream(BufferedReader input, List<String> inputList, String firstReading) throws
IOException {
logger.debug("readInputStream: {} {} {}", () -> input, () -> inputList, () -> firstReading);
int size;
21 changes: 7 additions & 14 deletions src/test/java/org/fungover/haze/MainTest.java
Original file line number Diff line number Diff line change
@@ -16,6 +16,8 @@
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.in;
@@ -208,29 +210,20 @@ void callToShutDownClientIfNotAuthenticatedShouldNotShutDownOutputForAuthenticat
assertThat(clientSocket.isOutputShutdown()).isEqualTo(false);
}

@Test
@DisplayName("Call to initSocket should set reuseAddress to true")
void callToInitSocketShouldSetReuseAddressToTrue() throws IOException {
Initialize initialize = new Initialize();
ServerSocket ss = new ServerSocket();
Main.initSocket(initialize, ss);
assertThat(ss.getReuseAddress()).isTrue();
}

@Test
@DisplayName("Call to initSocket should bind serversocket port to same as initialize")
void callToInitSocketShouldBindServerSocketPortToSameAsInitialize() throws IOException {
Initialize initialize = new Initialize();
ServerSocket ss = new ServerSocket();
Main.initSocket(initialize, ss);
int initializePort = initialize.getPort();
int serverSocketPort = ss.getLocalPort();
assertThat(initializePort).isNotEqualTo(serverSocketPort);

Main.initSocket(initialize, ss);
initializePort = initialize.getPort();
serverSocketPort = ss.getLocalPort();
assertThat(initializePort).isEqualTo(serverSocketPort);
}






}

0 comments on commit f254836

Please sign in to comment.