generated from pagopa/template-payments-java-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bcbe791
commit 1dc5296
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
...est/java/it/gov/pagopa/pu/debtpositions/config/RepositoryRestCustomConfigurationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package it.gov.pagopa.pu.debtpositions.config; | ||
|
||
import it.gov.pagopa.pu.debtpositions.model.DebtPosition; | ||
import jakarta.persistence.EntityManager; | ||
import jakarta.persistence.metamodel.EntityType; | ||
import jakarta.persistence.metamodel.Metamodel; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.springframework.data.rest.core.config.RepositoryRestConfiguration; | ||
import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurer; | ||
|
||
import java.util.Collections; | ||
|
||
import static org.mockito.Mockito.times; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class RepositoryRestCustomConfigurationTest { | ||
|
||
@Mock | ||
private EntityManager entityManager; | ||
|
||
@Mock | ||
private Metamodel metamodel; | ||
|
||
@Mock | ||
private EntityType<?> entityType; | ||
|
||
@InjectMocks | ||
private RepositoryRestCustomConfiguration config; | ||
|
||
@BeforeEach | ||
void setUp(){ | ||
Mockito.when(entityManager.getMetamodel()).thenReturn(metamodel); | ||
Mockito.when(metamodel.getEntities()).thenReturn(Collections.singleton(entityType)); | ||
Mockito.when(entityType.getJavaType()).thenReturn((Class) DebtPosition.class); | ||
} | ||
|
||
@Test | ||
void givenRepositoryRestConfigurerThenOk() { | ||
RepositoryRestConfiguration repositoryRestConfiguration = Mockito.mock(RepositoryRestConfiguration.class); | ||
// Act | ||
RepositoryRestConfigurer configurer = config.repositoryRestConfigurer(); | ||
configurer.configureRepositoryRestConfiguration(repositoryRestConfiguration,null); | ||
|
||
// Assert | ||
Assertions.assertNotNull(configurer); | ||
Mockito.verify(entityManager, times(1)).getMetamodel(); | ||
Mockito.verify(metamodel, times(1)).getEntities(); | ||
Mockito.verify(entityType, times(1)).getJavaType(); | ||
} | ||
} |