@Test @UsingDataSet({"single-user.xml", "address.yml"}) // Convention over configuration - no need to specify 'datasets' folder public void should_have_address_linked_to_user_account_using_multiple_files() throws Exception { // given String expectedCity = "Metropolis"; UserAccount user = em.find(UserAccount.class, 1L); // when Address address = user.getAddresses().iterator().next(); // then assertThat(user.getAddresses()).hasSize(1); assertThat(address.getCity()).isEqualTo(expectedCity); }
@Test @UsingDataSet("user-with-address.yml") public void should_have_address_linked_to_user_account() throws Exception { // given String expectedCity = "Metropolis"; long userAccountId = 1L; // when UserAccount user = em.find(UserAccount.class, userAccountId); Address address = user.getAddresses().iterator().next(); // then assertThat(user.getAddresses()).hasSize(1); assertThat(address.getCity()).isEqualTo(expectedCity); }
@Test @UsingDataSet("single-user.xml") @ShouldMatchDataSet({"single-user.xls", "datasets/expected-address.yml"}) public void should_add_address_to_user_account_and_verify_using_multiple_files() throws Exception { // given UserAccount user = em.find(UserAccount.class, 1L); Address address = new Address("Testing Street", 7, "JavaPolis", 1234); // when user.addAddress(address); user = em.merge(user); // then assertThat(user.getAddresses()).hasSize(1); }