Created
August 22, 2017 23:40
-
-
Save lhauspie/da209eb0f4d99f1e31be7b8af02b2ff3 to your computer and use it in GitHub Desktop.
Cumul Test unitaire et d'intégration
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
@SpringBootTest | |
@RunWith(SpringRunner.class) | |
public class ProductRepositoryTest { | |
@Autowired | |
private ProductRepository productRepo; | |
@SpyBean | |
private MongoTemplate mongoTemplate; | |
@Test | |
public void searchProductTest() { | |
// partie init de données | |
Assertions.assertThat(productRepo.findAll()).hasSize(0); | |
Product product1 = productRepo.save(new Product(null, "CODE", "LABEL", "DESCRIPTION", 1234D)); | |
Product product2 = productRepo.save(new Product(null, "CODE_LONG", "LABEL", "DESCRIPTION", 1234D)); | |
// appel de la couche Repository à tester | |
Collection<Product> products = productRepo.search(new SearchQuery("CODE", null, null, null, null)); | |
// vérification de la bonne exécution de la méthode find du MongoTemplate avec les bons paramètres | |
Query query = new Query(); | |
query.addCriteria(Criteria.where("code").regex("CODE")); | |
Mockito.verify(mongoTemplate, Mockito.times(1)).find(query, Product.class); | |
// vérification du résultat de l'execution | |
Assertions.assertThat(products).hasSize(2); | |
Assertions.assertThat(products).containsExactly(product1, product2); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment