/** * Return the value of the variable. * Uses lazy initialisation to call the {@link #create()} method (implemented safely for Java 5.0+, see * http://www.oracle.com/technetwork/articles/javase/bloch-effective-08-qa-140880.html). * @return value of scoped variable */ public T get() { T result = value; if (result == null) { // First check (no locking) synchronized (this) { result = value; if (result == null) { // Second check (with locking) value = result = create(); } } } return result; }
@Test public void isNotCreatedInitially() { assertFalse("expected holder to not be created yet", holder.isCreated()); }
public boolean beforeSpecRunOnce() { return beforeSpecCounter.get().get() == 1; } }
/** * Return the value of the variable. * Uses lazy initialisation to call the {@link #create()} method (implemented safely for Java 5.0+, see * http://www.oracle.com/technetwork/articles/javase/bloch-effective-08-qa-140880.html). * @return value of scoped variable */ public T get() { T result = value; if (result == null) { // First check (no locking) synchronized (this) { result = value; if (result == null) { // Second check (with locking) value = result = create(); } } } return result; }
public int getExampleScopedCounter() { return exampleScopedCounter.get().get(); }
public int getSpecScopedCounter() { return specScopedCounter.get().get(); }
public int getExampleScopedCounter() { return exampleScopedCounter.get().get(); }
@BeforeSpecification public void beforeSpec() { beforeSpecCounter.get().getAndIncrement(); }
public PrintStream getLogStream() { return helper.get().getLogStream(); }
@BeforeExample public void incrementAllCounters(@ExampleName String name) { exampleName = name; fieldCounter++; exampleScopedCounter.get().addAndGet(1); }
@Test public void returnsCurrentValueAfterGet() { Integer expected = 1; Integer actual = holder.get(); assertEquals(expected, actual); } }