LazyMetadataValue extends MetadataValueAdapter implements MetadataValue { public Object value() { eval(); Object value = internalValue.get(); if (value == ACTUALLY_NULL) { return null; } return value; } LazyMetadataValue(Plugin owningPlugin, Callable<Object> lazyValue);  LazyMetadataValue(Plugin owningPlugin, CacheStrategy cacheStrategy, Callable<Object> lazyValue); protected  LazyMetadataValue(Plugin owningPlugin); Object value(); synchronized void invalidate();  }
@Test public void testLazyInt() { int value = 10; subject = makeSimpleCallable(value); assertEquals(value, subject.value()); }
@Test public void testLazyDouble() { double value = 10.5; subject = makeSimpleCallable(value); assertEquals(value, (Double)subject.value(), 0.01); }
@Test public void testLazyString() { String value = "TEN"; subject = makeSimpleCallable(value); assertEquals(value, subject.value()); }
@Test public void testLazyBoolean() { boolean value = false; subject = makeSimpleCallable(value); assertEquals(value, subject.value()); }
@Test(expected=MetadataEvaluationException.class) public void testEvalException() { subject = new LazyMetadataValue(plugin, LazyMetadataValue.CacheStrategy.CACHE_AFTER_FIRST_EVAL, new Callable<Object>() { public Object call() throws Exception { throw new RuntimeException("Gotcha!"); } }); subject.value(); }
@Test public void testCacheStrategyNeverCache() { final Counter counter = new Counter(); final int value = 10; subject = new LazyMetadataValue(plugin, LazyMetadataValue.CacheStrategy.NEVER_CACHE, new Callable<Object>() { public Object call() throws Exception { counter.increment(); return value; } }); subject.value(); subject.value(); assertEquals(value, subject.value()); assertEquals(3, counter.value()); }