200803-java-devops / http-server

0 stars 1 forks source link

JUnit Exceptions (5 points) #14

Open MehrabRahman opened 4 years ago

MehrabRahman commented 4 years ago

https://github.com/200803-java-devops/http-server/blob/4dbbddbe2df1fd298902532af196afabd4580dfd/src/test/java/com/github/MehrabRahman/http/RequestTest.java#L56

Propose a proper unit test for a Request method or methods which will throw an expected IOException.class.

ConnorMRyan commented 4 years ago

@Test(expected = java.lang.IOException.class) void exceptionTest(){ Request request = new Request(Null); }

Since we are using the InputReader, if there is no input reader supplied, there will be an IOException error.

AaronDownward commented 4 years ago

I think it could look something like this:

@Test(expected = java.io.IOException.class)
public void requestIOExceptionTest() {
        Request request = new Request(inputStreamWithIOProblem);
}

Not sure how to create an InputStream with an io problem however to pass into Request constuctor. Also the IOException might occur while creating the InputStream even before the Request constructor runs. Any feedback/help is welcome on this.