Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds tests for ClientHandler #62

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

Adds tests for ClientHandler #62

wants to merge 5 commits into from

Conversation

Vimbayinashe
Copy link
Contributor

Closes #42

Initially I tried to test if the method would throw an I/O Exception or not but I soon realised that the method itself never throws an Exception because it would already have been handled by the try-catch block in ClientHandler. I have therefore tested whether or not an error message has been logged in order to determine if an exception has been thrown.
Any input or improvements would be greatly appreciated 馃檪.

@robinkorkmaz1 robinkorkmaz1 self-requested a review February 4, 2022 02:05
@GreenGard GreenGard self-requested a review February 4, 2022 09:38
Copy link
Contributor

@GreenGard GreenGard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the doThrow() method form the mockito library. Where you can check if any exception has been thrown when a class's method gets called
image
Would this solve your first id茅a?

Should we check if errormessages is greater than 0 instead of equal to 1?

@Vimbayinashe
Copy link
Contributor Author

What about the doThrow() method form the mockito library. Where you can check if any exception has been thrown when a class's method gets called image Would this solve your first id茅a?

Should we check if errormessages is greater than 0 instead of equal to 1?

I tried to throw an I/O Exception for Mockito.doThrow(IOException.class).when(socket.getInputStream()); but the exception is handled within the method's try-catch block and it does not throw an exception itself. The method will only log an error message if an exception has occured.
assertThatIOException().isThrownBy(clientHandler::run); is always false even if the socket is closed.

@Vimbayinashe
Copy link
Contributor Author

What about the doThrow() method form the mockito library. Where you can check if any exception has been thrown when a class's method gets called image Would this solve your first id茅a?
Should we check if errormessages is greater than 0 instead of equal to 1?

I tried to throw an I/O Exception for Mockito.doThrow(IOException.class).when(socket.getInputStream()); but the exception is handled within the method's try-catch block and it does not throw an exception itself. The method will only log an error message if an exception has occured. assertThatIOException().isThrownBy(clientHandler::run); is always false even if the socket is closed.

The run method only logs 1 message and it may similarly be an issue of concern if it deviates from its expected behaviour and logs 2 messages instead. That would then possibly be a bug in our logging system.

@Vimbayinashe Vimbayinashe marked this pull request as draft February 8, 2022 09:12
@Vimbayinashe
Copy link
Contributor Author

Following updates to ClientHandler, issue #75 is required before tests to ClientHandler can be implemented.

Copy link

sonarcloud bot commented Feb 2, 2024

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add tests for ClientHandler
2 participants