DefaultScriptSafeProvider implements ScriptSafeProvider { @Override public Object get(Object unsafe) { if (unsafe == null) { return null; } Object safe = get(unsafe, Arrays.<Type>asList(unsafe.getClass())); if (safe == null) { safe = unsafe; } return safe; }  @Override Object get(Object unsafe);  }
@Test void getWithNoProvider() { Object safe = ""; assertSame(safe, this.scriptSafeProvider.get(safe)); }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test void getCollection() { Collection unsafe = Arrays.asList("1", "2"); Collection safe = (Collection) this.scriptSafeProvider.get(unsafe); assertNotSame(unsafe, safe); assertTrue(safe instanceof List); assertEquals(unsafe, safe); unsafe = new LinkedHashSet(Arrays.asList("1", "2", "3", "4", "5")); safe = (Collection) this.scriptSafeProvider.get(unsafe); assertNotSame(unsafe, safe); assertTrue(safe instanceof Set); assertEquals(unsafe, safe); assertEquals(unsafe.toString(), safe.toString()); }
@SuppressWarnings({ "rawtypes", "unchecked", "cast" }) @Test void getMap() { Map unsafe = new LinkedHashMap(5); unsafe.put("1", "1"); unsafe.put("2", "2"); unsafe.put("3", "3"); unsafe.put("4", "4"); unsafe.put("5", "5"); Map safe = (Map) this.scriptSafeProvider.get(unsafe); assertNotSame(unsafe, safe); assertTrue(safe instanceof Map); assertEquals(unsafe, safe); assertEquals(unsafe.toString(), safe.toString()); }