Merge pull request #7816 from msievers/bael-3077/mapstruct-multiple-source-objects

[BAEL-3077] Update comments in unit tests to align with article snippets
This commit is contained in:
maibin 2019-10-01 13:52:14 -07:00 committed by GitHub
commit e7b8a60fc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 15 deletions

View File

@ -17,48 +17,51 @@ public class DeliveryAddressMapperUnitTest {
@Test
public void testGivenCustomerAndAddress_mapsToDeliveryAddress() {
// given
// given a customer
Customer customer = new Customer().setFirstName("Max")
.setLastName("Powers");
// and some address
Address homeAddress = new Address().setStreet("123 Some Street")
.setCounty("Nevada")
.setPostalcode("89123");
// when
// when calling DeliveryAddressMapper::from
DeliveryAddress deliveryAddress = deliveryAddressMapper.from(customer, homeAddress);
// then
// then a new DeliveryAddress is created, based on the given customer and his home address
assertEquals(deliveryAddress.getForename(), customer.getFirstName());
assertEquals(deliveryAddress.getSurname(), customer.getLastName());
assertEquals(deliveryAddress.getStreet(), homeAddress.getStreet());
assertEquals(deliveryAddress.getCounty(), homeAddress.getCounty());
assertEquals(deliveryAddress.getPostalcode(), homeAddress.getPostalcode());
}
@Test
public void testGivenDeliveryAddressAndSomeOtherAddress_updatesDeliveryAddress() {
// given
Customer customer = new Customer().setFirstName("Max")
.setLastName("Powers");
DeliveryAddress deliveryAddress = new DeliveryAddress().setStreet("123 Some Street")
// given a delivery address
DeliveryAddress deliveryAddress = new DeliveryAddress().setForename("Max")
.setSurname("Powers")
.setStreet("123 Some Street")
.setCounty("Nevada")
.setPostalcode("89123");
Address otherAddress = new Address().setStreet("456 Some other street")
// and some new address
Address newAddress = new Address().setStreet("456 Some other street")
.setCounty("Arizona")
.setPostalcode("12345");
// when
DeliveryAddress updatedDeliveryAddress = deliveryAddressMapper.updateAddress(deliveryAddress, otherAddress);
// when calling DeliveryAddressMapper::updateAddress
DeliveryAddress updatedDeliveryAddress = deliveryAddressMapper.updateAddress(deliveryAddress, newAddress);
// then
// then the *existing* delivery address is updated
assertSame(deliveryAddress, updatedDeliveryAddress);
assertEquals(deliveryAddress.getStreet(), otherAddress.getStreet());
assertEquals(deliveryAddress.getCounty(), otherAddress.getCounty());
assertEquals(deliveryAddress.getPostalcode(), otherAddress.getPostalcode());
assertEquals(deliveryAddress.getStreet(), newAddress.getStreet());
assertEquals(deliveryAddress.getCounty(), newAddress.getCounty());
assertEquals(deliveryAddress.getPostalcode(), newAddress.getPostalcode());
}
}