Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions tests/unit/ServiceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import static org.mockito.Mockito.*;

@SpringBootTest
@ExtendWith(SpringExtension.class)
class ServiceTest {

@MockBean
private ExternalService externalService;

@Autowired
private MyService myService;

@Test
void shouldHandleBusinessLogic() {
// Arrange
when(externalService.call()).thenReturn("expectedResponse");

// Act
String result = myService.process();

// Assert
assertEquals("expectedResponse", result);
verify(externalService, times(1)).call();
}

@Test
void shouldHandleExceptionScenario() {
// Arrange
when(externalService.call()).thenThrow(new RuntimeException("Service error"));

// Act & Assert
assertThrows(RuntimeException.class, () -> myService.process());
}
}