Created
April 27, 2019 09:27
-
-
Save tbelmega/ee73d2539f8f69eb7e47f012c527a6a1 to your computer and use it in GitHub Desktop.
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
@Test | |
fun `findMostOrderedProducts - 6 orders for 3 products in db - returns Top 2`() { | |
// given | |
val numberOfProducts = 2 | |
val product1 = Product("1", "Ryzen 7 2700X", "AMD") | |
val product2 = Product("2", "Core i9 9900K", "Intel") | |
val product3 = Product("3", "Ryzen Threadripper 2990WX", "AMD") | |
productRepository.saveAll(setOf(product1, product2, product3)) | |
val order1 = Order("1", 1, product1.id, LocalDate.now(), 1) | |
val order2 = Order("2", 1, product1.id, LocalDate.now(), 1) | |
val order3 = Order("3", 1, product1.id, LocalDate.now(), 1) | |
val order4 = Order("4", 1, product2.id, LocalDate.now(), 1) | |
val order5 = Order("5", 1, product2.id, LocalDate.now(), 1) | |
val order6 = Order("6", 1, product3.id, LocalDate.now(), 1) | |
entityManager.persist(order1) | |
entityManager.persist(order2) | |
entityManager.persist(order3) | |
entityManager.persist(order4) | |
entityManager.persist(order5) | |
entityManager.persist(order6) | |
// when | |
val foundProducts = productRepository.findMostOrderedProducts(numberOfProducts) | |
// then | |
assertThat(foundProducts).hasSize(numberOfProducts) | |
assertThat(foundProducts).containsExactlyInAnyOrder(product1, product2) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment