AbstractAction implements Action<T> { public static String getIdFromSource(Object source) { if (source == null) return null; Field[] fields = source.getClass().getDeclaredFields(); for (Field field : fields) { if (field.isAnnotationPresent(JestId.class)) { try { field.setAccessible(true); Object name = field.get(source); return name == null ? null : name.toString(); } catch (IllegalAccessException e) { log.error("Unhandled exception occurred while getting annotated id from source", e); } } } return null; } AbstractAction(); @SuppressWarnings("unchecked")  AbstractAction(Builder builder); static String getIdFromSource(Object source); Collection<Object> getParameter(String parameter); Object getHeader(String header); @Override Map<String, Object> getHeaders(); @Override String getURI(ElasticsearchVersion elasticsearchVersion); @Override String getData(Gson gson); @Override String getPathToResult(); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); abstract String getRestMethodName(); static String CHARSET; }
@Test public void getIdFromNullSource() { assertNull(AbstractAction.getIdFromSource(null)); }
@Test public void getIdFromSourceWithoutAnnotation() { assertNull(AbstractAction.getIdFromSource("JEST")); }
@Test public void getIdFromSourceWithAnnotation() { String expected = "jest@searchbox.io"; String actual = AbstractAction.getIdFromSource(new Source("data", "jest@searchbox.io")); assertEquals(expected, actual); }
@Test public void getIdFromSourceWithAnnotationWithNullId() { assertNull(AbstractAction.getIdFromSource(new Source("data", null))); }