Skip to content
This repository has been archived by the owner on Jul 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #6 from ralf-ueberfuhr-ars/feature/simplify-mocking
Browse files Browse the repository at this point in the history
Simplify mocking by using @MockBean instead of configuration classes.
  • Loading branch information
ralf-ueberfuhr-ars authored Jun 26, 2024
2 parents 26cde6f + 2a7e052 commit 2c964c8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@

import de.sample.schulung.accounts.domain.CustomersService;
import org.junit.jupiter.api.Tag;
import org.mockito.Mockito;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.test.mock.mockito.MockReset;
import org.springframework.context.annotation.Bean;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.ActiveProfiles;

import java.lang.annotation.*;
Expand All @@ -21,25 +17,12 @@
// minimal
@WebMvcTest
@ComponentScan(basePackageClasses = BoundaryLayerTest.class)
@Import(BoundaryLayerTest.BoundaryLayerTestConfiguration.class)
@AutoConfigureMockMvc
@MockBean(CustomersService.class)
// optional
@ActiveProfiles({"test", "boundary-test"})
@Tag("integration-test")
@Tag("boundary-test")
public @interface BoundaryLayerTest {

@TestConfiguration
class BoundaryLayerTestConfiguration {

@Bean
CustomersService customersServiceMock() {
return Mockito.mock(
CustomersService.class,
MockReset.withSettings(MockReset.AFTER)
);
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
import de.sample.schulung.accounts.domain.sink.CustomersSinkInMemoryImpl;
import de.sample.schulung.accounts.shared.interceptors.AutoConfigureInterceptors;
import org.junit.jupiter.api.Tag;
import org.mockito.Mockito;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockReset;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
Expand All @@ -38,6 +37,7 @@
@InitializationProperty
@RecordApplicationEvents
@AutoConfigureInterceptors
@MockBean(CustomerEventLogger.class)
// optional
@ActiveProfiles({"test", "domain-test"})
@Tag("integration-test")
Expand All @@ -57,17 +57,6 @@ CustomersSink testCustomerSink() {
return new CustomersSinkInMemoryImpl();
}

@Primary
@Bean
CustomerEventLogger testCustomerEventLogger() {
// Mock or DefaultImpl?
return Mockito.mock(
CustomerEventLogger.class,
MockReset.withSettings(MockReset.AFTER)
);
}

}


}
}

0 comments on commit 2c964c8

Please sign in to comment.