RBACDecorator implements RBACDecoratorMBean { @SuppressWarnings("unchecked") static Map<String, Object> deepCopy(Map<String, Object> mBeanInfo) { Map<String, Object> copy = new HashMap<>(mBeanInfo); Map<String, Object> ops = (Map<String, Object>) mBeanInfo.get("op"); Map<String, Object> newOps = new HashMap<>(ops.size()); for (String name : ops.keySet()) { Object op = ops.get(name); Object newOp; if (op instanceof List) { List<Map<String, Object>> overloaded = (List<Map<String, Object>>) op; List<Map<String, Object>> newOpList = new ArrayList<>(overloaded.size()); for (Map<String, Object> method : overloaded) { newOpList.add(new HashMap<>(method)); } newOp = newOpList; } else { Map<String, Object> method = (Map<String, Object>) op; newOp = new HashMap<>(method); } newOps.put(name, newOp); } copy.put("op", newOps); return copy; } RBACDecorator(BundleContext bundleContext); @Override @SuppressWarnings("unchecked") void decorate(Map<String, Object> result); @Override boolean getVerify(); @Override void setVerify(boolean verify); static Logger LOG; }
@Test @SuppressWarnings("unchecked") public void deepCopy() throws Exception { Map<String, Object> result = readInput(); Map<String, Map<String, Object>> cache = (Map<String, Map<String, Object>>) result.get("cache"); for (String key : cache.keySet()) { Map<String, Object> original = cache.get(key); Map<String, Object> copy = RBACDecorator.deepCopy(original); assertThat(copy, not(sameInstance(original))); assertThat(copy, equalTo(original)); } }