ExcelFieldService { public static Long getObjectID(final Object object) { Long objectId = Long.valueOf(-1); if (object == null || !(Persistable.class.isAssignableFrom(object.getClass()))) { return Long.valueOf(-1); } try { final Method idMethod = object.getClass().getMethod("getId"); if (idMethod != null) { objectId = (Long) idMethod.invoke(object); } } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { logger.error("getObjectID error", e); } return objectId; } private  ExcelFieldService(); static FieldType getFieldType(final Field field); static Class getFieldClass(final Field field); static Iterator<Field> getFields(final Class clazz); static Long getObjectID(final Object object); static String getFieldName(final Class clazz, final Field field, final TranslateService translateService); static Class[] getFieldClazz(final Field field); static Boolean isCollection(final Field field);  }
@Test public void getObjectID() throws Exception { final OtherClass otherClass = new OtherClass(); Assert.assertEquals("Check object ID", Long.valueOf(-1), ExcelFieldService.getObjectID(otherClass)); final TestClass testclass = new TestClass((long) 10); Assert.assertEquals("Check object ID", Long.valueOf(10), ExcelFieldService.getObjectID(testclass)); }