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
class PastaAppConfig( | |
val env0BaseURL: String, | |
val env1Name: String, | |
val env1BaseURL: String | |
) { | |
fun getBaseUrl(targetEnvironment: String): String { | |
return if (targetEnvironment === env1Name) env1BaseURL | |
else env0BaseURL | |
} |
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
class PastaAppConfigTest { | |
@Test | |
fun `getBaseUrl returns env1 if targetEnvironment is env1`{ | |
// given | |
val config = PastaAppConfig("https://foo-sandbox.bar", "Production", "https://foo.bar") | |
// when | |
val result = config.getBaseUrl("Production") | |
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
val str1 = "Production" | |
val str2 = "Production" // referentially equal, String pool | |
val str3 = String("Production") // new object in memory, not referentially equal |
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
@ActiveProfiles("test") | |
@RunWith(SpringJUnit4ClassRunner::class) | |
@DataJpaTest | |
class ProductRepositoryTest { | |
@Autowired | |
private lateinit var productRepository: ProductRepository | |
@Test | |
fun `saves product in database and loads by id`() { |
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 - no orders in db - return empty list`() { | |
// given | |
productRepository.save(Product("1", "Ryzen 7 2700X", "AMD")) | |
productRepository.save(Product("2", "Core i9 9900K", "Intel")) | |
// when | |
val foundProducts = productRepository.findMostOrderedProducts(1) | |
// then |
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 | |
// when | |
val foundProducts = productRepository.findMostOrderedProducts(2) | |
// then | |
} |
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 | |
// when | |
val foundProducts = productRepository.findMostOrderedProducts(numberOfProducts) | |
// then | |
assertThat(foundProducts).hasSize(numberOfProducts) | |
assertThat(foundProducts).containsExactlyInAnyOrder(product1, product2) |
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") | |
// when | |
val foundProducts = productRepository.findMostOrderedProducts(numberOfProducts) |
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) |
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)) | |
persistNewOrderForProduct(product1.id) |
OlderNewer