Skip to content

Instantly share code, notes, and snippets.

@tbelmega
Created April 27, 2019 08:05
Show Gist options
  • Save tbelmega/80961329c1055def09da9cffbaa16e1f to your computer and use it in GitHub Desktop.
Save tbelmega/80961329c1055def09da9cffbaa16e1f to your computer and use it in GitHub Desktop.
@ActiveProfiles("test")
@RunWith(SpringJUnit4ClassRunner::class)
@DataJpaTest
class ProductRepositoryTest {
@Autowired
private lateinit var productRepository: ProductRepository
@Test
fun `saves product in database and loads by id`() {
// given
val productToSave = Product("1", "Ryzen 7 2700X", "AMD")
// when
productRepository.save(productToSave)
// then
val loadedProduct = productRepository.getOne("1")
assertThat(loadedProduct).isEqualTo(productToSave)
}
@Test
fun `loads all products from database`() {
// given
val product1 = productRepository.save(Product("1", "Ryzen 7 2700X", "AMD"))
val product2 = productRepository.save(Product("2", "Core i9 9900K", "Intel"))
// when
val products = productRepository.findAll()
// then
assertThat(products).containsExactlyInAnyOrder(product1, product2)
}
@Test
fun `findMostOrderedProducts - first test TODO name it correctly`() {
// given
// when
// then
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment