StompEndpoint NullPointerException Error on Unit Testing

27 Views Asked by At

Here is my code block:

@Test
    public void testRegisterStompEndpoints() {
        // Arrange
        StompEndpointRegistry registry = mock(StompEndpointRegistry.class);
        WebSocketConfig webSocketConfig = new WebSocketConfig();

        // Act
        webSocketConfig.registerStompEndpoints(registry);

        // Assert
        verify(registry, times(1)).addEndpoint("/ws").withSockJS();
    }

Whenever I try to test this method. I got an error like:

java.lang.NullPointerException: Cannot invoke "org.springframework.web.socket.config.annotation.StompWebSocketEndpointRegistration.withSockJS()" because the return value of "org.springframework.web.socket.config.annotation.StompEndpointRegistry.addEndpoint(String[])" is null

registerStompEndpoints is yellow underlined.

Can anyone please help me to fix this?

0

There are 0 best solutions below