Primes { public final int compute() { long start = System.currentTimeMillis(); int cnt = 0; int prntCnt = 97; int res; for (;;) { res = next(); cnt += 1; if (cnt % prntCnt == 0) { log("Computed " + cnt + " primes in " + (System.currentTimeMillis() - start) + " ms. Last one is " + res); prntCnt *= 2; } if (cnt >= 100000) { break; } } return res; } protected  Primes(); final int compute(); static void main(String... args);  }
@Test public void fifthThousandThPrime() { Primes p = new Primes() { @Override protected void log(String msg) { } }; int last = p.compute(); assertEquals("100000th prime is", 1_299_709, last); }