Add junit tests for utils classes
This commit is contained in:
26
src/test/java/stirling/software/SPDF/utils/UrlUtilsTest.java
Normal file
26
src/test/java/stirling/software/SPDF/utils/UrlUtilsTest.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package stirling.software.SPDF.utils;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class UrlUtilsTest {
|
||||
|
||||
@Test
|
||||
void testGetOrigin() {
|
||||
// Mock HttpServletRequest
|
||||
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
|
||||
Mockito.when(request.getScheme()).thenReturn("http");
|
||||
Mockito.when(request.getServerName()).thenReturn("localhost");
|
||||
Mockito.when(request.getServerPort()).thenReturn(8080);
|
||||
Mockito.when(request.getContextPath()).thenReturn("/myapp");
|
||||
|
||||
// Call the method under test
|
||||
String origin = UrlUtils.getOrigin(request);
|
||||
|
||||
// Assert the result
|
||||
assertEquals("http://localhost:8080/myapp", origin);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user