Skip to content

Commit

Permalink
Removed spring-web test dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
SMadani committed Aug 10, 2023
1 parent d5469fb commit 9ba282a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
2 changes: 0 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ dependencies {

testImplementation 'junit:junit:4.13.2'
testImplementation 'org.mockito:mockito-inline:4.11.0'
testImplementation 'org.springframework:spring-test:5.3.29'
testImplementation 'org.springframework:spring-web:5.3.29'
testImplementation 'jakarta.servlet:jakarta.servlet-api:4.0.4'
}

Expand Down
42 changes: 37 additions & 5 deletions src/test/java/com/vonage/client/auth/RequestSigningTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@
import org.apache.http.message.BasicNameValuePair;
import static org.junit.Assert.*;
import org.junit.Test;
import org.mockito.Mockito;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.springframework.mock.web.MockHttpServletRequest;
import javax.servlet.ReadListener;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -231,11 +234,40 @@ private HttpServletRequest constructDummyRequest() {
}


private HttpServletRequest constructDummyRequestJson() {
MockHttpServletRequest request = new MockHttpServletRequest();
private HttpServletRequest constructDummyRequestJson() throws Exception {
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
String dummyJson = "{\"a\":\"alphabet\",\"b\":\"bananas\",\"timestamp\":\"2100\",\"sig\":\"b7f749de27b4adcf736cc95c9a7e059a16c85127\"}";
request.setContent(dummyJson.getBytes());
request.setContentType("application/json");
Mockito.when(request.getContentType()).thenReturn("application/json");
final byte[] contentBytes = dummyJson.getBytes(StandardCharsets.UTF_8);
ServletInputStream servletInputStream = new ServletInputStream() {
private int index = 0;

@Override
public int read() {
if (index < contentBytes.length) {
return contentBytes[index++] & 0xFF;
}
return -1;
}

@Override
public boolean isFinished() {
return index >= contentBytes.length;
}

@Override
public boolean isReady() {
return true;
}

@Override
public void setReadListener(ReadListener readListener) {
// No need to implement for this example
}
};

when(request.getInputStream()).thenReturn(servletInputStream);

return request;
}

Expand Down

0 comments on commit 9ba282a

Please sign in to comment.