Test unmodifiability of returned collections
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@307282 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
deba27893e
commit
6767a45758
|
@ -18,6 +18,7 @@
|
|||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
@ -256,10 +257,7 @@ private void assertLocaleLookupList(Locale locale, Locale defaultLocale, Locale[
|
|||
|
||||
assertEquals(expected.length, localeList.size());
|
||||
assertEquals(Arrays.asList(expected), localeList);
|
||||
try {
|
||||
localeList.add("Unmodifiable");
|
||||
fail();
|
||||
} catch (UnsupportedOperationException ex) {}
|
||||
assertUnmodifiableCollection(localeList);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
@ -344,6 +342,8 @@ public void testAvailableLocaleList() {
|
|||
List list2 = LocaleUtils.availableLocaleList();
|
||||
assertNotNull(list);
|
||||
assertSame(list, list2);
|
||||
assertUnmodifiableCollection(list);
|
||||
|
||||
Locale[] jdkLocaleArray = Locale.getAvailableLocales();
|
||||
List jdkLocaleList = Arrays.asList(jdkLocaleArray);
|
||||
assertEquals(jdkLocaleList, list);
|
||||
|
@ -358,6 +358,8 @@ public void testAvailableLocaleSet() {
|
|||
Set set2 = LocaleUtils.availableLocaleSet();
|
||||
assertNotNull(set);
|
||||
assertSame(set, set2);
|
||||
assertUnmodifiableCollection(set);
|
||||
|
||||
Locale[] jdkLocaleArray = Locale.getAvailableLocales();
|
||||
List jdkLocaleList = Arrays.asList(jdkLocaleArray);
|
||||
Set jdkLocaleSet = new HashSet(jdkLocaleList);
|
||||
|
@ -413,10 +415,7 @@ private void assertLanguageByCountry(String country, String[] languages) {
|
|||
+ " for country: " + country);
|
||||
}
|
||||
}
|
||||
try {
|
||||
list.add("Unmodifiable");
|
||||
fail();
|
||||
} catch (UnsupportedOperationException ex) {}
|
||||
assertUnmodifiableCollection(list);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -463,10 +462,7 @@ private void assertCountriesByLanguage(String language, String[] countries) {
|
|||
+ " for country: " + language);
|
||||
}
|
||||
}
|
||||
try {
|
||||
list.add("Unmodifiable");
|
||||
fail();
|
||||
} catch (UnsupportedOperationException ex) {}
|
||||
assertUnmodifiableCollection(list);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -479,4 +475,14 @@ public void testCountriesByLanguage() {
|
|||
assertCountriesByLanguage("it", new String[]{"IT", "CH"});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param coll the collection to check
|
||||
*/
|
||||
private static void assertUnmodifiableCollection(Collection coll) {
|
||||
try {
|
||||
coll.add("Unmodifiable");
|
||||
fail();
|
||||
} catch (UnsupportedOperationException ex) {}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue