UnmodifiableContextStorage implements ContextStorage<Context> { @Override public Context put(final Context context) { throw new UnsupportedOperationException("Cannot put context"); } UnmodifiableContextStorage(final Context context); @Override Context get(); @Override Context put(final Context context);  }
@Test public void testPut() { final Context expected = EmptyContext.getInstance() .withValue(Key.of(randomUUID().toString(), String.class), randomUUID().toString()) .withValue(Key.of(randomUUID().toString(), String.class), randomUUID().toString()) .withValue(Key.of(randomUUID().toString(), String.class), randomUUID().toString()); final ContextStorage<Context> contextStorage = new UnmodifiableContextStorage(expected); final Context actual = contextStorage.get(); assertEquals(expected, actual); }
@Test public void shouldPutThrowException() { final ContextStorage<Context> contextStorage = new UnmodifiableContextStorage( EmptyContext.getInstance()); try { contextStorage.put(EmptyContext.getInstance()); fail("Should throw UnsupportedOperationException"); } catch (UnsupportedOperationException e) { } }