public void testIncrement() throws Exception { AtomicInteger value = new AtomicInteger(3); List<Thread> threads = new ArrayList<>(THREAD_COUNT); for (int threadIndex = 0; threadIndex < THREAD_COUNT; ++threadIndex) { Thread thread = new Thread( () -> { for (int iterationIndex = 0; iterationIndex < ITERATION_COUNT; ++iterationIndex) { AtomicUtil.increment(value, 9); } }); threads.add(thread); thread.start(); } for (int threadIndex = 0; threadIndex < THREAD_COUNT; ++threadIndex) { threads.get(threadIndex).join(); } assertEquals("AtomicUtil.increment(AtomicInteger, int) failed.", 3, value.get()); }