|
| 1 | +package com.bnc.sbjb.rest; |
| 2 | + |
| 3 | +import static org.mockito.Mockito.mock; |
| 4 | +import static org.mockito.Mockito.verify; |
| 5 | +import static org.mockito.Mockito.verifyNoMoreInteractions; |
| 6 | +import static org.mockito.Mockito.when; |
| 7 | + |
| 8 | +import javax.servlet.http.HttpServletRequest; |
| 9 | +import org.junit.jupiter.api.Test; |
| 10 | + |
| 11 | +class DefaultExceptionHandlerTest { |
| 12 | + |
| 13 | + @Test |
| 14 | + void testHandleExceptionWithBigQueryString() { |
| 15 | + final HttpServletRequest mockRequest = mock(HttpServletRequest.class); |
| 16 | + when(mockRequest.getQueryString()).thenReturn( |
| 17 | + "This is a string with a lot of text and several extra whitespaces\n" |
| 18 | + + "This is a string with a lot of text and several extra whitespaces\n" |
| 19 | + + "This is a string with a lot of text and several extra whitespaces\n" |
| 20 | + + "This is a string with a lot of text and several extra whitespaces\n" |
| 21 | + + "This is a string with a lot of text and several extra whitespaces\n"); |
| 22 | + new DefaultExceptionHandler().handleException(mockRequest, new Exception("Just testing")); |
| 23 | + // Just to include a test. |
| 24 | + verify(mockRequest).getQueryString(); |
| 25 | + verifyNoMoreInteractions(mockRequest); |
| 26 | + } |
| 27 | + |
| 28 | + @Test |
| 29 | + void testHandleExceptionWithLittleQueryString() { |
| 30 | + final HttpServletRequest mockRequest = mock(HttpServletRequest.class); |
| 31 | + when(mockRequest.getQueryString()).thenReturn("\n"); |
| 32 | + new DefaultExceptionHandler().handleException(mockRequest, new Exception("Just testing")); |
| 33 | + // Just to include a test. |
| 34 | + verify(mockRequest).getQueryString(); |
| 35 | + verifyNoMoreInteractions(mockRequest); |
| 36 | + } |
| 37 | + |
| 38 | + @Test |
| 39 | + void testHandleExceptionWithNoQueryString() { |
| 40 | + final HttpServletRequest mockRequest = mock(HttpServletRequest.class); |
| 41 | + when(mockRequest.getQueryString()).thenReturn(null); |
| 42 | + new DefaultExceptionHandler().handleException(mockRequest, new Exception("Just testing")); |
| 43 | + // Just to include a test. |
| 44 | + verify(mockRequest).getQueryString(); |
| 45 | + } |
| 46 | +} |
0 commit comments