@CollectionSize.Require(absent = ZERO) @ListFeature.Require(absent = SUPPORTS_SET) public void testSet_unsupported() { try { getList().set(aValidIndex(), e3()); fail("set() should throw UnsupportedOperationException"); } catch (UnsupportedOperationException expected) { } expectUnchanged(); }
private void doTestSet(E newValue) { int index = aValidIndex(); E initialValue = getList().get(index); assertEquals( "set(i, x) should return the old element at position i.", initialValue, getList().set(index, newValue)); assertEquals("After set(i, x), get(i) should return x", newValue, getList().get(index)); assertEquals("set() should not change the size of a list.", getNumElements(), getList().size()); }
@CollectionSize.Require(absent = ZERO) @CollectionFeature.Require(ALLOWS_NULL_VALUES) @ListFeature.Require(SUPPORTS_SET) public void testSet_replacingNull() { E[] elements = createSamplesArray(); int i = aValidIndex(); elements[i] = null; collection = getSubjectGenerator().create(elements); doTestSet(e3()); }
@ListFeature.Require(SUPPORTS_SET) public void testSet_indexTooHigh() { int index = getNumElements(); try { getList().set(index, e3()); fail("set(size) should throw IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException expected) { } expectUnchanged(); }
@ListFeature.Require(SUPPORTS_SET) public void testSet_indexTooLow() { try { getList().set(-1, samples.e3); fail("set(-1) should throw IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException expected) { } expectUnchanged(); }
@CollectionSize.Require(absent = ZERO) @CollectionFeature.Require(ALLOWS_NULL_VALUES) @ListFeature.Require(SUPPORTS_SET) public void testSet_null() { doTestSet(null); }
@Override protected Collection<Method> suppressForCheckedList() { return Arrays.asList( CollectionAddTester.getAddNullSupportedMethod(), getAddSupportedNullPresentMethod(), ListAddAtIndexTester.getAddNullSupportedMethod(), getSetNullSupportedMethod()); } }
private int aValidIndex() { return getList().size() / 2; }
@CollectionSize.Require(ZERO) @ListFeature.Require(absent = SUPPORTS_SET) public void testSet_unsupportedByEmptyList() { try { getList().set(0, samples.e3); fail("set() should throw UnsupportedOperationException " + "or IndexOutOfBoundsException"); } catch (UnsupportedOperationException tolerated) { } catch (IndexOutOfBoundsException tolerated) { } expectUnchanged(); }
@ListFeature.Require(SUPPORTS_SET) @CollectionSize.Require(absent = ZERO) public void testSet() { doTestSet(samples.e3); }
@Override protected Collection<Method> suppressForCheckedList() { return Arrays.asList( CollectionAddTester.getAddNullSupportedMethod(), getAddSupportedNullPresentMethod(), ListAddAtIndexTester.getAddNullSupportedMethod(), getSetNullSupportedMethod()); } }
private int aValidIndex() { return getList().size() / 2; }
@ListFeature.Require(SUPPORTS_SET) public void testSet_indexTooLow() { try { getList().set(-1, e3()); fail("set(-1) should throw IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException expected) { } expectUnchanged(); }
@CollectionSize.Require(absent = ZERO) @CollectionFeature.Require(ALLOWS_NULL_VALUES) @ListFeature.Require(SUPPORTS_SET) public void testSet_replacingNull() { E[] elements = createSamplesArray(); int i = aValidIndex(); elements[i] = null; collection = getSubjectGenerator().create(elements); doTestSet(e3()); }
private void doTestSet(E newValue) { int index = aValidIndex(); E initialValue = getList().get(index); assertEquals( "set(i, x) should return the old element at position i.", initialValue, getList().set(index, newValue)); assertEquals("After set(i, x), get(i) should return x", newValue, getList().get(index)); assertEquals("set() should not change the size of a list.", getNumElements(), getList().size()); }
@CollectionSize.Require(absent = ZERO) @CollectionFeature.Require(ALLOWS_NULL_VALUES) @ListFeature.Require(SUPPORTS_SET) public void testSet_null() { doTestSet(null); }
@Override protected Collection<Method> suppressForCheckedList() { return Arrays.asList( CollectionAddTester.getAddNullSupportedMethod(), getAddSupportedNullPresentMethod(), ListAddAtIndexTester.getAddNullSupportedMethod(), getSetNullSupportedMethod()); } }
private int aValidIndex() { return getList().size() / 2; }