public void testmapentrymodification() { smallsortedmap<integer, integer> map = smallsortedmap.newinstancefortest(3); for (int i = 0; i < 6; i++) { assertnull(map.put(i, i + 1)); } iterator<map.entry<integer, integer>> it = map.entryset().iterator(); for (int i = 0; i < 6; i++) { map.entry<integer, integer> entry = it.next(); entry.setvalue(i + 23); } for (int i = 0; i < 6; i++) { assertequals(new integer(i + 23), map.get(i)); } }
public void testmakeimmutable() { smallsortedmap<integer, integer> map = smallsortedmap.newinstancefortest(3); for (int i = 0; i < 6; i++) { assertnull(map.put(i, i + 1)); } map.makeimmutable(); assertequals(new integer(1), map.get(0)); assertequals(6, map.size()); try { map.put(23, 23); fail("expected unsupportedoperationexception"); } catch (unsupportedoperationexception expected) { } map<integer, integer> other = new hashmap<integer, integer>(); other.put(23, 23); try { map.putall(other); fail("expected unsupportedoperationexception"); } catch (unsupportedoperationexception expected) { } try { map.remove(0); fail("expected unsupportedoperationexception"); } catch (unsupportedoperationexception expected) { } try { map.clear(); fail("expected unsupportedoperationexception"); } catch (unsupportedoperationexception expected) { } set<map.entry<integer, integer>> entryset = map.entryset(); try { entryset.clear(); fail("expected unsupportedoperationexception"); } catch (unsupportedoperationexception expected) { } iterator<map.entry<integer, integer>> it = entryset.iterator(); while (it.hasnext()) { map.entry<integer, integer> entry = it.next(); try { entry.setvalue(0); fail("expected unsupportedoperationexception"); } catch (unsupportedoperationexception expected) { } try { it.remove(); fail("expected unsupportedoperationexception"); } catch (unsupportedoperationexception expected) { } } set<integer> keyset = map.keyset(); try { keyset.clear(); fail("expected unsupportedoperationexception"); } catch (unsupportedoperationexception expected) { } iterator<integer> keys = keyset.iterator(); while (keys.hasnext()) { integer key = keys.next(); try { keyset.remove(key); fail("expected unsupportedoperationexception"); } catch (unsupportedoperationexception expected) { } try { keys.remove(); fail("expected unsupportedoperationexception"); } catch (unsupportedoperationexception expected) { } } }