Primes { public static List<Integer> primeFactors(int n) { if (n < 2) { throw new MathIllegalArgumentException(LocalizedFormats.NUMBER_TOO_SMALL, n, 2); } return SmallPrimes.trialDivision(n); } private  Primes(); static boolean isPrime(int n); static int nextPrime(int n); static List<Integer> primeFactors(int n);  }
@Test public void testPrimeFactors() throws Exception { for (int i : BELOW_2) { assertPrimeFactorsException(i, new MathIllegalArgumentException(LocalizedFormats.NUMBER_TOO_SMALL,i,2)); } for (int i : NOT_PRIMES) { List<Integer> factors = Primes.primeFactors(i); checkPrimeFactors(factors); int prod = product(factors); Assert.assertEquals(i, prod); } for (int i : PRIMES) { List<Integer> factors = Primes.primeFactors(i); Assert.assertEquals(i, (int)factors.get(0)); Assert.assertEquals(1, factors.size()); } }