diff --git a/android/guava-tests/test/com/google/common/collect/SetsTest.java b/android/guava-tests/test/com/google/common/collect/SetsTest.java index 9c8b6e9adb29..2499aeffd15c 100644 --- a/android/guava-tests/test/com/google/common/collect/SetsTest.java +++ b/android/guava-tests/test/com/google/common/collect/SetsTest.java @@ -1087,71 +1087,29 @@ public void testUnmodifiableNavigableSet() { } void ensureNotDirectlyModifiable(SortedSet unmod) { - try { - unmod.add(4); - fail("UnsupportedOperationException expected"); - } catch (UnsupportedOperationException expected) { - } - try { - unmod.remove(4); - fail("UnsupportedOperationException expected"); - } catch (UnsupportedOperationException expected) { - } - try { - unmod.addAll(singleton(4)); - fail("UnsupportedOperationException expected"); - } catch (UnsupportedOperationException expected) { - } - try { - Iterator iterator = unmod.iterator(); - iterator.next(); - iterator.remove(); - fail("UnsupportedOperationException expected"); - } catch (UnsupportedOperationException expected) { - } + assertThrows(UnsupportedOperationException.class, () -> unmod.add(4)); + assertThrows(UnsupportedOperationException.class, () -> unmod.remove(4)); + assertThrows(UnsupportedOperationException.class, () -> unmod.addAll(singleton(4))); + Iterator iterator = unmod.iterator(); + iterator.next(); + assertThrows(UnsupportedOperationException.class, () -> iterator.remove()); } @GwtIncompatible // NavigableSet void ensureNotDirectlyModifiable(NavigableSet unmod) { - try { - unmod.add(4); - fail("UnsupportedOperationException expected"); - } catch (UnsupportedOperationException expected) { - } - try { - unmod.remove(4); - fail("UnsupportedOperationException expected"); - } catch (UnsupportedOperationException expected) { - } - try { - unmod.addAll(singleton(4)); - fail("UnsupportedOperationException expected"); - } catch (UnsupportedOperationException expected) { - } - try { - unmod.pollFirst(); - fail("UnsupportedOperationException expected"); - } catch (UnsupportedOperationException expected) { - } - try { - unmod.pollLast(); - fail("UnsupportedOperationException expected"); - } catch (UnsupportedOperationException expected) { - } - try { - Iterator iterator = unmod.iterator(); - iterator.next(); - iterator.remove(); - fail("UnsupportedOperationException expected"); - } catch (UnsupportedOperationException expected) { - } - try { - Iterator iterator = unmod.descendingIterator(); - iterator.next(); - iterator.remove(); - fail("UnsupportedOperationException expected"); - } catch (UnsupportedOperationException expected) { - } + assertThrows(UnsupportedOperationException.class, () -> unmod.add(4)); + assertThrows(UnsupportedOperationException.class, () -> unmod.remove(4)); + assertThrows(UnsupportedOperationException.class, () -> unmod.addAll(singleton(4))); + assertThrows(UnsupportedOperationException.class, () -> unmod.pollFirst()); + assertThrows(UnsupportedOperationException.class, () -> unmod.pollLast()); + + Iterator iterator = unmod.iterator(); + iterator.next(); + assertThrows(UnsupportedOperationException.class, () -> iterator.remove()); + + Iterator descendingIterator = unmod.descendingIterator(); + descendingIterator.next(); + assertThrows(UnsupportedOperationException.class, () -> descendingIterator.remove()); } @GwtIncompatible // NavigableSet diff --git a/guava-tests/test/com/google/common/collect/SetsTest.java b/guava-tests/test/com/google/common/collect/SetsTest.java index 87e46e95640b..e5cc68fc1e3b 100644 --- a/guava-tests/test/com/google/common/collect/SetsTest.java +++ b/guava-tests/test/com/google/common/collect/SetsTest.java @@ -1121,71 +1121,29 @@ public void testUnmodifiableNavigableSet() { } void ensureNotDirectlyModifiable(SortedSet unmod) { - try { - unmod.add(4); - fail("UnsupportedOperationException expected"); - } catch (UnsupportedOperationException expected) { - } - try { - unmod.remove(4); - fail("UnsupportedOperationException expected"); - } catch (UnsupportedOperationException expected) { - } - try { - unmod.addAll(singleton(4)); - fail("UnsupportedOperationException expected"); - } catch (UnsupportedOperationException expected) { - } - try { - Iterator iterator = unmod.iterator(); - iterator.next(); - iterator.remove(); - fail("UnsupportedOperationException expected"); - } catch (UnsupportedOperationException expected) { - } + assertThrows(UnsupportedOperationException.class, () -> unmod.add(4)); + assertThrows(UnsupportedOperationException.class, () -> unmod.remove(4)); + assertThrows(UnsupportedOperationException.class, () -> unmod.addAll(singleton(4))); + Iterator iterator = unmod.iterator(); + iterator.next(); + assertThrows(UnsupportedOperationException.class, () -> iterator.remove()); } @GwtIncompatible // NavigableSet void ensureNotDirectlyModifiable(NavigableSet unmod) { - try { - unmod.add(4); - fail("UnsupportedOperationException expected"); - } catch (UnsupportedOperationException expected) { - } - try { - unmod.remove(4); - fail("UnsupportedOperationException expected"); - } catch (UnsupportedOperationException expected) { - } - try { - unmod.addAll(singleton(4)); - fail("UnsupportedOperationException expected"); - } catch (UnsupportedOperationException expected) { - } - try { - unmod.pollFirst(); - fail("UnsupportedOperationException expected"); - } catch (UnsupportedOperationException expected) { - } - try { - unmod.pollLast(); - fail("UnsupportedOperationException expected"); - } catch (UnsupportedOperationException expected) { - } - try { - Iterator iterator = unmod.iterator(); - iterator.next(); - iterator.remove(); - fail("UnsupportedOperationException expected"); - } catch (UnsupportedOperationException expected) { - } - try { - Iterator iterator = unmod.descendingIterator(); - iterator.next(); - iterator.remove(); - fail("UnsupportedOperationException expected"); - } catch (UnsupportedOperationException expected) { - } + assertThrows(UnsupportedOperationException.class, () -> unmod.add(4)); + assertThrows(UnsupportedOperationException.class, () -> unmod.remove(4)); + assertThrows(UnsupportedOperationException.class, () -> unmod.addAll(singleton(4))); + assertThrows(UnsupportedOperationException.class, () -> unmod.pollFirst()); + assertThrows(UnsupportedOperationException.class, () -> unmod.pollLast()); + + Iterator iterator = unmod.iterator(); + iterator.next(); + assertThrows(UnsupportedOperationException.class, () -> iterator.remove()); + + Iterator descendingIterator = unmod.descendingIterator(); + descendingIterator.next(); + assertThrows(UnsupportedOperationException.class, () -> descendingIterator.remove()); } @GwtIncompatible // NavigableSet