Files
Vaessl/backend/src/test/java/com/vaessl/app/connection/ConnectionServiceTest.java
T
kasunandClaude Sonnet 4.6 a7b984ca84 refactor: consolidate test mock constants into shared Mockdata class
Moved Mockdata from the connection package to the root test package and
extended it with MOCK_USER, MOCK_PASS, MOCK_TITLE, and MOCK_DESCRIPTION
so all test modules share a single source of truth. Removed duplicate
inline constants from ConnectionControllerTest, HomeboxIntegrationTest,
and SearchControllerTest.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
2026-05-20 17:36:22 +02:00

50 lines
1.5 KiB
Java

package com.vaessl.app.connection;
import static com.vaessl.app.Mockdata.*;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import com.vaessl.app.exception.EmptyCredentialsException;
@ExtendWith(MockitoExtension.class)
class ConnectionServiceTest {
@Mock
private ConnectionProvider mockProvider;
@Mock
private ConnectionRepository mockRepo;
private ConnectionService connectionService;
@BeforeEach
void setup() {
when(mockProvider.getServiceType()).thenReturn(MOCK_SERVICE_TYPE);
connectionService = new ConnectionService(List.of(mockProvider), mockRepo);
}
@Test
void login_ShouldAbort_WhenCheckCredentialsThrowsException() {
ConnectionRequest request =
new ConnectionRequest(MOCK_URL, MOCK_SERVICE_TYPE, null, null, false);
doThrow(new EmptyCredentialsException(List.of("username"))).when(mockProvider)
.checkCredentials(request);
assertThrows(EmptyCredentialsException.class, () -> connectionService.login(request));
verify(mockProvider, never()).authenticate(any());
}
}