Skip to content

Instantly share code, notes, and snippets.

@FranckSilvestre
Created May 22, 2024 16:02
Show Gist options
  • Save FranckSilvestre/dbad939898249b7b600d50ba4ff44e22 to your computer and use it in GitHub Desktop.
Save FranckSilvestre/dbad939898249b7b600d50ba4ff44e22 to your computer and use it in GitHub Desktop.
OurbusinessProjevt BUT3 2024 - 2
package ourbusinessproject;
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 static org.junit.jupiter.api.Assertions.*;
import static org.mockito.BDDMockito.willThrow;
import static org.mockito.Mockito.verify;
@ExtendWith(MockitoExtension.class)
class BootstrapTest {
private Bootstrap bootstrap;
@Mock
private InitializationService initializationService;
@BeforeEach
public void setUp() {
bootstrap = new Bootstrap(initializationService);
}
@Test
public void testInitMethodInvokeInitializationService() {
// given a bootstrap and its initialization service
assertNotNull(bootstrap);
// when the init method is triggered
bootstrap.init();
// then the initialization of projects and partnerships is triggered on the initialization service
verify(initializationService).initProjects();
verify(initializationService).initPartnerships();
}
@Test
public void testIniBootstrapMethodCatchRuntimeExceptionComingFromInitProjects() {
// given a bootstrap and its initialization service throwing an exception
willThrow(RuntimeException.class).given(initializationService).initProjects();
// when the init method is triggered
bootstrap.init();
// then no exception is thrown
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment