@SuppressWarnings("deprecation") private static Requirement replicate(final Requirement orig) { final String h = orig.hint(); return new RequirementImpl( orig.role(), orig.optional(), h.length() > 0 ? new String[] {h} : orig.hints()); }
private static void checkBehaviour(final String name) throws NoSuchFieldException { final Requirement orig = getRequirement(name); final Requirement clone = replicate(orig); assertTrue(orig.equals(clone)); assertTrue(clone.equals(orig)); assertTrue(clone.equals(clone)); assertFalse(clone.equals("")); assertEquals(orig.hashCode(), clone.hashCode()); assertEquals( new HashSet<String>(Arrays.asList(orig.toString().split("[(, )]"))), new HashSet<String>(Arrays.asList(clone.toString().split("[(, )]")))); assertEquals(orig.annotationType(), clone.annotationType()); try { final Field role = RequirementImpl.class.getDeclaredField("role"); final Method getName = role.getType().getMethod("getName"); role.setAccessible(true); assertEquals(orig.role().getName(), getName.invoke(role.get(clone))); } catch (final Exception e) { fail(e.toString()); } }