{
ArrayList targets = new ArrayList();
targets.add("ONE");
targets.add("TWO");
ClusteringTargetsRepository.initTarget("testImmutability", targets, 0);
FamilyClusterInfo fci = ClusteringTargetsRepository.getFamilyClusterInfo("testImmutability");
List fciTargets = fci.getTargets();
// Confirm the targets are what we expect
assertEquals("Expected number of targets", 2, fciTargets.size());
assertEquals("First target as expected", "ONE", fciTargets.get(0));
assertEquals("Second target as expected", "TWO", fciTargets.get(1));
try
{
fciTargets.add("FAIL");
fail("add call did not fail");
}
catch (UnsupportedOperationException good) {}
try
{
fciTargets.addAll(targets);
fail("addAll call did not fail");
}
catch (UnsupportedOperationException good) {}
try
{
fciTargets.clear();
fail("clear call did not fail");
}
catch (UnsupportedOperationException good) {}
if (fciTargets instanceof ArrayList)
{
ArrayList fciArrayList = (ArrayList) fciTargets;
try
{
fciArrayList.ensureCapacity(5);
fail("ensureCapacity call did not fail");
}
catch (UnsupportedOperationException good) {}
try
{
fciArrayList.trimToSize();
fail("trimToSize call did not fail");
}
catch (UnsupportedOperationException good) {}
}
try
{
fciTargets.remove(0);
fail("remove call did not fail");
}
catch (UnsupportedOperationException good) {}
try
{
fciTargets.set(0, "FAIL");
fail("set call did not fail");
}
catch (UnsupportedOperationException good) {}
try
{
fciTargets.removeAll(targets);
fail("removeAll call did not fail");
}
catch (UnsupportedOperationException good) {}
try
{
fciTargets.retainAll(targets);
fail("retainAll call did not fail");
}
catch (UnsupportedOperationException good) {}
Iterator iter = fciTargets.iterator();
int count = 0;
while (iter.hasNext())
{
iter.next();
count++;
}
assertEquals("Correct count", 2, count);
try
{
iter.remove();
fail("Iterator.remove call did not fail");
}
catch (UnsupportedOperationException good) {}
ListIterator listIter = fciTargets.listIterator();
count = 0;
while (listIter.hasNext())
{
listIter.next();
count++;
}
assertEquals("Correct count", 2, count);
try
{
listIter.remove();
fail("Iterator.remove call did not fail");
}
catch (UnsupportedOperationException good) {}
while (listIter.hasPrevious())
{
listIter.previous();
count--;
}
assertEquals("Correct count", 0, count);
listIter = fciTargets.listIterator(1);
while (listIter.hasNext())
{
listIter.next();
count++;
}
assertEquals("Correct count", 1, count);
try
{
listIter.remove();
fail("Iterator.remove call did not fail");
}
catch (UnsupportedOperationException good) {}
while (listIter.hasPrevious())
{
listIter.previous();
count--;
}
assertEquals("Correct count", -1, count);
// Check the lists returned by other methods
fciTargets = fci.updateClusterInfo(targets, 0);
try
{
fciTargets.add("FAIL");
fail("add call did not fail");
}
catch (UnsupportedOperationException good) {}
fciTargets = fci.removeDeadTarget(targets.get(0));
try
{
fciTargets.add("FAIL");
fail("add call did not fail");