DefaultWorldpayAuthenticatedShopperIdStrategy implements WorldpayAuthenticatedShopperIdStrategy { @Override public String getAuthenticatedShopperId(final UserModel userModel) { Preconditions.checkNotNull(userModel, "The user is null"); if (userModel instanceof CustomerModel) { final String customerID = ((CustomerModel) userModel).getCustomerID(); return StringUtils.defaultIfBlank(customerID, ((CustomerModel) userModel).getOriginalUid()); } throw new IllegalArgumentException(format("The user {0} is not of type Customer.", userModel)); }  @Override String getAuthenticatedShopperId(final UserModel userModel);  }
@Test public void shouldReturnCustomerIdAsAuthenticatedShopperId() throws Exception { when(customerModelMock.getCustomerID()).thenReturn(CUSTOMER_ID); final String result = testObj.getAuthenticatedShopperId(customerModelMock); assertEquals(CUSTOMER_ID, result); }
@Test public void shouldReturnOriginalUIDIfCustomerIdIsNotSet() throws Exception { when(customerModelMock.getCustomerID()).thenReturn(""); when(customerModelMock.getOriginalUid()).thenReturn(ORIGINAL_UID); final String result = testObj.getAuthenticatedShopperId(customerModelMock); assertEquals(ORIGINAL_UID, result); }
@Test public void shouldThrowExceptionIfNotCustomer() throws Exception { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage(format("The user {0} is not of type Customer.", userModelMock)); testObj.getAuthenticatedShopperId(userModelMock); }
@Test public void shouldRaiseErrorIfUserIsNull() throws Exception { expectedException.expect(NullPointerException.class); expectedException.expectMessage("The user is null"); testObj.getAuthenticatedShopperId(null); }