/** * Thrown if the test tries to invoke a static factory method to test instance methods but the * factory returned null. */ @VisibleForTesting static class FactoryMethodReturnsNullException extends Exception { public FactoryMethodReturnsNullException(Invokable<?, ?> factory) { super(factory + " returns null and cannot be used to test instance methods."); } }
/** Returns the file holding the data (possibly null). */ @VisibleForTesting synchronized File getFile() { return file; }
/** Suppression strategy interface. */ @VisibleForTesting interface Suppressor { /** * Suppresses the given exception ({@code suppressed}) which was thrown when attempting to close * the given closeable. {@code thrown} is the exception that is actually being thrown from the * method. Implementations of this method should not throw under any circumstances. */ void suppress(Closeable closeable, Throwable thrown, Throwable suppressed); }
/** Suppresses exceptions by logging them. */ @VisibleForTesting static final class LoggingSuppressor implements Suppressor { static final LoggingSuppressor INSTANCE = new LoggingSuppressor(); @Override public void suppress(Closeable closeable, Throwable thrown, Throwable suppressed) { // log to the same place as Closeables Closeables.logger.log( Level.WARNING, "Suppressing exception thrown when closing " + closeable, suppressed); } }
/** * Returns 1 if {@code x < y} as unsigned longs, and 0 otherwise. Assumes that x - y fits into a * signed long. The implementation is branch-free, and benchmarks suggest it is measurably faster * than the straightforward ternary expression. */ @VisibleForTesting static int lessThanBranchFree(long x, long y) { // Returns the sign bit of x - y. return (int) (~~(x - y) >>> (Long.SIZE - 1)); }
/** * Returns 1 if {@code x < y} as unsigned integers, and 0 otherwise. Assumes that x - y fits into * a signed int. The implementation is branch-free, and benchmarks suggest it is measurably (if * narrowly) faster than the straightforward ternary expression. */ @VisibleForTesting static int lessThanBranchFree(int x, int y) { // The double negation is optimized away by normal Java, but is necessary for GWT // to make sure bit twiddling works as expected. return ~~(x - y) >>> (Integer.SIZE - 1); }
@VisibleForTesting WithExplicitOrdering(Policy policy, Map<E, LockGraphNode> lockGraphNodes) { super(policy); this.lockGraphNodes = lockGraphNodes; }
@VisibleForTesting static Comparator<byte[]> lexicographicalComparatorJavaImpl() { return LexicographicalComparatorHolder.PureJavaComparator.INSTANCE; }
@VisibleForTesting int capacity() { return queue.length; }
@VisibleForTesting interface GetCheckedTypeValidator { void validateClass(Class<? extends Exception> exceptionClass); }
@VisibleForTesting static boolean isEvenLevel(int index) { int oneBased = ~~(index + 1); // for GWT checkState(oneBased > 0, "negative index"); return (oneBased & EVEN_POWERS_OF_TWO) > (oneBased & ODD_POWERS_OF_TWO); }
@VisibleForTesting static boolean isCheckedException(Class<? extends Exception> type) { return !RuntimeException.class.isAssignableFrom(type); }
@VisibleForTesting ConcurrentHashMultiset(ConcurrentMap<E, AtomicInteger> countMap) { checkArgument(countMap.isEmpty(), "the backing map (%s) must be empty", countMap); this.countMap = countMap; }
@VisibleForTesting void addShutdownHook(Thread hook) { Runtime.getRuntime().addShutdownHook(hook); } }
/** * Returns the absolute uri of the Class-Path entry value as specified in <a * href="http://docs.oracle.com/javase/8/docs/technotes/guides/jar/jar.html#Main_Attributes">JAR * File Specification</a>. Even though the specification only talks about relative urls, * absolute urls are actually supported too (for example, in Maven surefire plugin). */ @VisibleForTesting static URL getClassPathEntry(File jarFile, String path) throws MalformedURLException { return new URL(jarFile.toURI().toURL(), path); } }
@VisibleForTesting static String getClassName(String filename) { int classNameEnd = filename.length() - CLASS_FILE_NAME_EXTENSION.length(); return filename.substring(0, classNameEnd).replace('/', '.'); }
/** * True when a valid surrogate pair starts at the given {@code index} in the given {@code string}. * Out-of-range indexes return false. */ @VisibleForTesting static boolean validSurrogatePairAt(CharSequence string, int index) { return index >= 0 && index <= (string.length() - 2) && Character.isHighSurrogate(string.charAt(index)) && Character.isLowSurrogate(string.charAt(index + 1)); }
@VisibleForTesting static File toFile(URL url) { checkArgument(url.getProtocol().equals("file")); try { return new File(url.toURI()); // Accepts escaped characters like %20. } catch (URISyntaxException e) { // URL.toURI() doesn't escape chars. return new File(url.getPath()); // Accepts non-escaped chars like space. } } }
@J2ObjCIncompatible // ClassValue @VisibleForTesting static GetCheckedTypeValidator classValueValidator() { return GetCheckedTypeValidatorHolder.ClassValueValidator.INSTANCE; }
@VisibleForTesting final void scan(File file, ClassLoader classloader) throws IOException { if (scannedUris.add(file.getCanonicalFile())) { scanFrom(file, classloader); } }