Code example for AtomicInteger

Methods: getAndSet

0
 
    private static class TestListener implements Runnable {
        private final AtomicInteger callCount;
 
        public TestListener() { 
            this.callCount = new AtomicInteger(0);
        } 
 
        public int getAndResetCallCount() { 
            return callCount.getAndSet(0);
        } 
 
        public void verifyCalledAndReset() { 
            assertTrue("Listener must have been notified.", getAndResetCallCount() > 0); 
        } 
 
        @Override 
        public void run() { 
            callCount.incrementAndGet();
        } 
    }