@Test public void addCustomer_shouldAddNewCustomer() { Short customerId = customerService.addCustomer(newCustomer(), newAddress()); assertThat(customerId, notNullValue()); }
@Nonnull public Short addCustomer(@Nonnull Customer customer, @Nonnull Address address) { checkNotNull(customer, "Argument[customer] must not be null"); checkNotNull(address, "Argument[address] must not be null"); sqlSessionManager.startManagedSession(TransactionIsolationLevel.READ_COMMITTED); try { AddressMapper addressMapper = sqlSessionManager.getMapper(AddressMapper.class); addressMapper.insert(address); assert (address.getAddressId() >= 0); customer.setAddressId(address.getAddressId()); customerMapper.insert(customer); assert (customer.getCustomerId() >= 0); sqlSessionManager.commit(); logger.info("Added customer[{}]", customer); } catch (Throwable t) { sqlSessionManager.rollback(); logger.error("Error while adding customer[{}]:", customer, t); } return customer.getCustomerId(); }
CustomerService { @Nonnull public Short addCustomer(@Nonnull Customer customer, @Nonnull Address address) { checkNotNull(customer, "Argument[customer] must not be null"); checkNotNull(address, "Argument[address] must not be null"); sqlSessionManager.startManagedSession(TransactionIsolationLevel.READ_COMMITTED); try { AddressMapper addressMapper = sqlSessionManager.getMapper(AddressMapper.class); addressMapper.insert(address); assert (address.getAddressId() >= 0); customer.setAddressId(address.getAddressId()); customerMapper.insert(customer); assert (customer.getCustomerId() >= 0); sqlSessionManager.commit(); logger.info("Added customer[{}]", customer); } catch (Throwable t) { sqlSessionManager.rollback(); logger.error("Error while adding customer[{}]:", customer, t); } return customer.getCustomerId(); } }
CustomerService { @Nonnull public Short addCustomer(@Nonnull Customer customer, @Nonnull Address address) { checkNotNull(customer, "Argument[customer] must not be null"); checkNotNull(address, "Argument[address] must not be null"); sqlSessionManager.startManagedSession(TransactionIsolationLevel.READ_COMMITTED); try { AddressMapper addressMapper = sqlSessionManager.getMapper(AddressMapper.class); addressMapper.insert(address); assert (address.getAddressId() >= 0); customer.setAddressId(address.getAddressId()); customerMapper.insert(customer); assert (customer.getCustomerId() >= 0); sqlSessionManager.commit(); logger.info("Added customer[{}]", customer); } catch (Throwable t) { sqlSessionManager.rollback(); logger.error("Error while adding customer[{}]:", customer, t); } return customer.getCustomerId(); } CustomerService(@Nonnull SqlSessionManager sqlSessionManager); }
CustomerService { @Nonnull public Short addCustomer(@Nonnull Customer customer, @Nonnull Address address) { checkNotNull(customer, "Argument[customer] must not be null"); checkNotNull(address, "Argument[address] must not be null"); sqlSessionManager.startManagedSession(TransactionIsolationLevel.READ_COMMITTED); try { AddressMapper addressMapper = sqlSessionManager.getMapper(AddressMapper.class); addressMapper.insert(address); assert (address.getAddressId() >= 0); customer.setAddressId(address.getAddressId()); customerMapper.insert(customer); assert (customer.getCustomerId() >= 0); sqlSessionManager.commit(); logger.info("Added customer[{}]", customer); } catch (Throwable t) { sqlSessionManager.rollback(); logger.error("Error while adding customer[{}]:", customer, t); } return customer.getCustomerId(); } CustomerService(@Nonnull SqlSessionManager sqlSessionManager); List<Customer> getAll(); @Nullable Customer getCustomer(@Nonnull Short customerId); @Nonnull Short addCustomer(@Nonnull Customer customer, @Nonnull Address address); @Nonnull List<Customer> getCustomerRewardsReport(
      @Nonnull Byte minMonthlyPurchases, @Nonnull Double minDollarAmountPurchased); }
CustomerService { @Nonnull public Short addCustomer(@Nonnull Customer customer, @Nonnull Address address) { checkNotNull(customer, "Argument[customer] must not be null"); checkNotNull(address, "Argument[address] must not be null"); sqlSessionManager.startManagedSession(TransactionIsolationLevel.READ_COMMITTED); try { AddressMapper addressMapper = sqlSessionManager.getMapper(AddressMapper.class); addressMapper.insert(address); assert (address.getAddressId() >= 0); customer.setAddressId(address.getAddressId()); customerMapper.insert(customer); assert (customer.getCustomerId() >= 0); sqlSessionManager.commit(); logger.info("Added customer[{}]", customer); } catch (Throwable t) { sqlSessionManager.rollback(); logger.error("Error while adding customer[{}]:", customer, t); } return customer.getCustomerId(); } CustomerService(@Nonnull SqlSessionManager sqlSessionManager); List<Customer> getAll(); @Nullable Customer getCustomer(@Nonnull Short customerId); @Nonnull Short addCustomer(@Nonnull Customer customer, @Nonnull Address address); @Nonnull List<Customer> getCustomerRewardsReport(
      @Nonnull Byte minMonthlyPurchases, @Nonnull Double minDollarAmountPurchased);  }