- try {
- map.values().add("v1");
- fail();
- } catch (UnsupportedOperationException e) {
- // OK
- }
-
- try {
- map.values().remove("v1");
- fail();
- } catch (UnsupportedOperationException e) {
- // OK
- }
-
- try {
- map.values().clear();
- fail();
- } catch (UnsupportedOperationException e) {
- // OK
- }
-
- try {
- final Iterator<String> it = map.values().iterator();
- it.next();
- it.remove();
- fail();
- } catch (UnsupportedOperationException e) {
- // OK
- }
-
- try {
- map.keySet().add("k1");
- fail();
- } catch (UnsupportedOperationException e) {
- // OK
- }
-
- try {
- map.keySet().clear();
- fail();
- } catch (UnsupportedOperationException e) {
- // OK
- }
-
- try {
- map.keySet().remove("k1");
- fail();
- } catch (UnsupportedOperationException e) {
- // OK
- }
-
- try {
- final Iterator<String> it = map.keySet().iterator();
- it.next();
- it.remove();
- fail();
- } catch (UnsupportedOperationException e) {
- // OK
- }
-
- try {
- map.entrySet().clear();
- fail();
- } catch (UnsupportedOperationException e) {
- // OK
- }
-
- try {
- map.entrySet().add(new SimpleEntry<>("k1", "v1"));
- fail();
- } catch (UnsupportedOperationException e) {
- // OK
- }
+ final Collection<String> values = map.values();
+ assertThrows(UnsupportedOperationException.class, () -> values.add("v1"));
+ assertThrows(UnsupportedOperationException.class, () -> values.remove("v1"));
+ assertThrows(UnsupportedOperationException.class, () -> values.clear());