ArrayTranslator { public <T> T[] defensiveCopy(T[] value) { if (configuration.isPerformingDefensiveCopies()) { return value.clone(); } else { return value; } } ArrayTranslator(Configuration configuration); T[] translate(Object[] sourceArray, Class<T> destinationClass,
			TranslationSource translationSource); T[] defensiveCopy(T[] value); T[] copyTo(Object[] sourceArray, Class<T> destinationClass);  }
@Test public void testCreatesDefensiveCopiesWithDefaultConfiguration() { String[] source = new String[] { "The", "Quick", "Brown", "Fox" }; String[] destination = new ArrayTranslator(new Configuration()).defensiveCopy(source); Assert.assertNotNull(destination); Assert.assertNotSame(source, destination); Assert.assertTrue(Arrays.equals(source, destination)); }
@Test public void testReturnsOriginalArraysIfNotConfiguredForDefensiveCopies() { String[] source = new String[] { "The", "Quick", "Brown", "Fox" }; Configuration configuration = new Configuration(); configuration.setPerformingDefensiveCopies(false); String[] destination = new ArrayTranslator(configuration).defensiveCopy(source); Assert.assertNotNull(destination); Assert.assertSame(source, destination); }