### Question:
ConfiguredStringUserReferenceSerializer implements UserReferenceSerializer<String> { @Override public String serialize(UserReference userReference) { return resolveUserReferenceSerializer().serialize(userReference); }  @Override String serialize(UserReference userReference);  }### Answer:
@Test void serialize() throws Exception { when(this.userConfiguration.getStoreHint()).thenReturn("storehint"); UserReferenceSerializer customUserReferenceSerializer = mock(UserReferenceSerializer.class); when(this.componentManager.getInstance(new DefaultParameterizedType(null, UserReferenceSerializer.class, String.class), "storehint")).thenReturn(customUserReferenceSerializer); UserReference userReference = mock(UserReference.class); this.serializer.serialize(userReference); verify(customUserReferenceSerializer).serialize(userReference); }
@Test void serializeWhenNoSerializer() throws Exception { when(this.userConfiguration.getStoreHint()).thenReturn("storehint"); when(this.componentManager.getInstance(new DefaultParameterizedType(null, UserReferenceSerializer.class, String.class), "storehint")).thenThrow(new ComponentLookupException("error")); Throwable exception = assertThrows(RuntimeException.class, () -> this.serializer.serialize(mock(UserReference.class))); assertEquals("Failed to find user reference serializer for role " + "[org.xwiki.user.UserReferenceSerializer<java.lang.String>] and hint [storehint]", exception.getMessage()); assertEquals("ComponentLookupException: error", ExceptionUtils.getRootCauseMessage(exception)); }