/** For test usage only */ @VisibleForTesting static synchronized void set(ExternalAnnotationRepository singleton) { sSingleton = singleton; } }
/** * Sets the global instance to the provided tracker so tests can provide their own UsageTracker * implementation. NOTE: Should only be used from tests. */ @VisibleForTesting public static UsageTracker setInstanceForTest(UsageTracker tracker) { return sInstance = tracker; }
@VisibleForTesting static final class HttpResult { /* HTTP response code or others errors related to HTTP connection, JSON file parsing. */ private final int mStatus; private final JsonElement mJsonFile; @VisibleForTesting HttpResult(int status, JsonElement jsonFile) { mStatus = status; mJsonFile = jsonFile; } } }
/** Used to calculate diffs between different reports of Garbage Collection stats. */ @VisibleForTesting static class GarbageCollectionStatsDiffs { volatile long collections; volatile long time; }
/** * For testing only: returns the number of exceptions thrown during Java AST analysis * * @return the number of internal errors found */ @VisibleForTesting public static int getCrashCount() { return exceptionCount; }
/** Clears out any existing lookup instances */ @VisibleForTesting static void dispose() { sInstance.clear(); } }
/** Empty current property list. Made accessible for testing purposes. */ @VisibleForTesting(visibility=Visibility.PRIVATE) protected void clear() { synchronized (sSourcesProperties) { sSourcesProperties.clear(); sModified = false; } } }
@VisibleForTesting static String convertToOppositeDirection(String attribute) { if (attribute.contains(LEFT)) { return attribute.replace(LEFT, RIGHT); } else if (attribute.contains(RIGHT)) { return attribute.replace(RIGHT, LEFT); } else if (attribute.contains(START)) { return attribute.replace(START, END); } else { return attribute.replace(END, START); } }
/** Returns true if the given sentence contains a given word */ @VisibleForTesting static boolean containsWord(String sentence, String word) { return containsWord(sentence, word, false, false); }
/** Drop generic type variables from a method or constructor name */ @VisibleForTesting static String getRawMethod(@NonNull String name) { int index = name.indexOf('<'); if (index != -1) { return name.substring(0, index); } return name; }
@VisibleForTesting @Override @NonNull public Set<RepositorySourceProvider> getSourceProviders() { return mSourceProviders; }
/** * Sets the {@link DownloadCache} for us to use, so that a custom one can be used during tests. * * @param cache The {@link DownloadCache} to use. If {@code null} a new {@link DownloadCache} * will be created lazily. */ @VisibleForTesting public void setDownloadCache(@Nullable DownloadCache cache) { mDownloadCache = cache; }
@VisibleForTesting protected File checkPath(@NonNull String path) throws FileNotFoundException { @NonNull File file = new File(path); if (!file.exists()) { System.err.println(path + " does not exist"); throw new FileNotFoundException(path); } return file; }
@VisibleForTesting protected void copyFile(File inputFile, File outputFile) { try { Files.createParentDirs(outputFile); Files.copy(inputFile, outputFile); } catch(IOException e) { LOGGER.error(e, "Cannot copy %1$s to back up folder, build will continue but " + "next time this file is modified will result in a cold swap.", inputFile.getAbsolutePath()); } }
@VisibleForTesting public ExternalNativeBuildOptions() { ndkBuildOptions = new ExternalNativeNdkBuildOptions(); cmakeOptions = new ExternalNativeCmakeOptions(); }
@VisibleForTesting public static void extractBundledProguardFile( @NonNull String name, @NonNull File proguardFile) throws IOException { Files.createParentDirs(proguardFile); URL proguardURL = ProguardFiles.class.getResource(name); URLConnection urlConnection = proguardURL.openConnection(); urlConnection.setUseCaches(false); try (InputStream is = urlConnection.getInputStream()) { Files.asByteSink(proguardFile).writeFrom(is); } } }
/** * resets the global instance to the null usage tracker, to clean state in tests. NOTE: Should * only be used from tests. */ @VisibleForTesting public static void cleanAfterTesting() { sInstance = new NullUsageTracker(new AnalyticsSettings(), null); }
@Nullable private static AnnotationsDatabase getDatabase( @NonNull LintClient client, @NonNull AndroidLibrary library) { // TODO: As of 1.2 this is available in the model: // https://android-review.googlesource.com/#/c/137750/ // Switch over to this when it's in more common usage // (until it is, we'll pay for failed proxying errors) File zip = new File(library.getResFolder().getParent(), FN_ANNOTATIONS_ZIP); return getDatabase(client, zip); }
@VisibleForTesting ClassEntry( @NonNull File file, @Nullable File jarFile, @NonNull File binDir, @NonNull byte[] bytes) { super(); this.file = file; this.jarFile = jarFile; this.binDir = binDir; this.bytes = bytes; }
@VisibleForTesting public static void initializeForTests(@NonNull Path profileOutputFile) { sINSTANCE = new ProcessProfileWriterFactory(); sINSTANCE.setProfileOutputFile(profileOutputFile); ProcessProfileWriter recorder = sINSTANCE.get(); // Initialize the ProcessProfileWriter instance recorder.resetForTests(); setGlobalProperties(recorder, new File("fake/path/to/test_project/"), "2.10", new StdLogger(StdLogger.Level.VERBOSE)); }