@Test public void shouldAppendLinks() { RESTServiceDiscovery initialLinks = new RESTServiceDiscovery(); initialLinks.addLink(URI.create("https: EntityWithLinks entity = new EntityWithLinks(initialLinks); RESTServiceDiscovery newLinks = new RESTServiceDiscovery(); newLinks.addLink(URI.create("http: injector.inject(entity, newLinks); Assert.assertEquals(2, entity.getRestServiceDiscovery().size()); Assert.assertEquals("https: entity.getRestServiceDiscovery().getLinkForRel("resteasy").getHref()); Assert.assertEquals("http: }
public void inject(Object entity, RESTServiceDiscovery restServiceDiscovery) { Field injectionField = findInjectionField(entity); if (injectionField == null) { return; } RESTServiceDiscovery fieldValue = null; try { injectionField.setAccessible(true); fieldValue = (RESTServiceDiscovery) injectionField.get(entity); } catch (Exception e) { LogMessages.LOGGER.error(Messages.MESSAGES.failedToReuseServiceDiscovery(entity), e); } if (fieldValue == null) { fieldValue = restServiceDiscovery; } else { fieldValue.addAllLinks(restServiceDiscovery); } try { injectionField.set(entity, fieldValue); injectionField.setAccessible(false); } catch (Exception e) { LogMessages.LOGGER.error(Messages.MESSAGES.failedToInjectLinks(entity), e); } }
LinksInjector { public void inject(Object entity, RESTServiceDiscovery restServiceDiscovery) { Field injectionField = findInjectionField(entity); if (injectionField == null) { return; } RESTServiceDiscovery fieldValue = null; try { injectionField.setAccessible(true); fieldValue = (RESTServiceDiscovery) injectionField.get(entity); } catch (Exception e) { LogMessages.LOGGER.error(Messages.MESSAGES.failedToReuseServiceDiscovery(entity), e); } if (fieldValue == null) { fieldValue = restServiceDiscovery; } else { fieldValue.addAllLinks(restServiceDiscovery); } try { injectionField.set(entity, fieldValue); injectionField.setAccessible(false); } catch (Exception e) { LogMessages.LOGGER.error(Messages.MESSAGES.failedToInjectLinks(entity), e); } } }
LinksInjector { public void inject(Object entity, RESTServiceDiscovery restServiceDiscovery) { Field injectionField = findInjectionField(entity); if (injectionField == null) { return; } RESTServiceDiscovery fieldValue = null; try { injectionField.setAccessible(true); fieldValue = (RESTServiceDiscovery) injectionField.get(entity); } catch (Exception e) { LogMessages.LOGGER.error(Messages.MESSAGES.failedToReuseServiceDiscovery(entity), e); } if (fieldValue == null) { fieldValue = restServiceDiscovery; } else { fieldValue.addAllLinks(restServiceDiscovery); } try { injectionField.set(entity, fieldValue); injectionField.setAccessible(false); } catch (Exception e) { LogMessages.LOGGER.error(Messages.MESSAGES.failedToInjectLinks(entity), e); } }  }
LinksInjector { public void inject(Object entity, RESTServiceDiscovery restServiceDiscovery) { Field injectionField = findInjectionField(entity); if (injectionField == null) { return; } RESTServiceDiscovery fieldValue = null; try { injectionField.setAccessible(true); fieldValue = (RESTServiceDiscovery) injectionField.get(entity); } catch (Exception e) { LogMessages.LOGGER.error(Messages.MESSAGES.failedToReuseServiceDiscovery(entity), e); } if (fieldValue == null) { fieldValue = restServiceDiscovery; } else { fieldValue.addAllLinks(restServiceDiscovery); } try { injectionField.set(entity, fieldValue); injectionField.setAccessible(false); } catch (Exception e) { LogMessages.LOGGER.error(Messages.MESSAGES.failedToInjectLinks(entity), e); } }  void inject(Object entity, RESTServiceDiscovery restServiceDiscovery); }
LinksInjector { public void inject(Object entity, RESTServiceDiscovery restServiceDiscovery) { Field injectionField = findInjectionField(entity); if (injectionField == null) { return; } RESTServiceDiscovery fieldValue = null; try { injectionField.setAccessible(true); fieldValue = (RESTServiceDiscovery) injectionField.get(entity); } catch (Exception e) { LogMessages.LOGGER.error(Messages.MESSAGES.failedToReuseServiceDiscovery(entity), e); } if (fieldValue == null) { fieldValue = restServiceDiscovery; } else { fieldValue.addAllLinks(restServiceDiscovery); } try { injectionField.set(entity, fieldValue); injectionField.setAccessible(false); } catch (Exception e) { LogMessages.LOGGER.error(Messages.MESSAGES.failedToInjectLinks(entity), e); } }  void inject(Object entity, RESTServiceDiscovery restServiceDiscovery);  }