Skip to content

Commit

Permalink
Add PlatformTestStorage get*Uri methods.
Browse files Browse the repository at this point in the history
And remove the existing static TestStorage methods.

PiperOrigin-RevId: 617882692
  • Loading branch information
brettchabot authored and copybara-androidxtest committed Mar 21, 2024
1 parent f202cdf commit 9ffb8f7
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void clickActionTestingOfTestFlowOutput() throws IOException {
assertThat(testFlowVisualizer.getLastActionIndexAndIncrement()).isEqualTo(2);
InputStream outputGalleryFile =
TestStorageUtil.getInputStream(
PlatformTestStorageRegistry.getInstance().getOutputFileUri2("output_gallery.html"),
PlatformTestStorageRegistry.getInstance().getOutputFileUri("output_gallery.html"),
InstrumentationRegistry.getInstrumentation().getTargetContext().getContentResolver());
int size = outputGalleryFile.available();
byte[] directFileContents = new byte[size];
Expand Down Expand Up @@ -129,8 +129,7 @@ public void testFlowVisualizerIfFeatureIsOffShowBreakage() {
FileNotFoundException.class,
() ->
TestStorageUtil.getInputStream(
PlatformTestStorageRegistry.getInstance()
.getOutputFileUri2("output_gallery.html"),
PlatformTestStorageRegistry.getInstance().getOutputFileUri("output_gallery.html"),
InstrumentationRegistry.getInstrumentation()
.getTargetContext()
.getContentResolver()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void screenshotSaved() throws IOException {
}

private Bitmap readBitmapFromTestStorage(String pathName) throws IOException {
Uri outputFileUri = PlatformTestStorageRegistry.getInstance().getOutputFileUri2(pathName);
Uri outputFileUri = PlatformTestStorageRegistry.getInstance().getOutputFileUri(pathName);
try (InputStream input =
TestStorageUtil.getInputStream(
outputFileUri, getApplicationContext().getContentResolver())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void testFlowVisualizerEnsureCorrectOutputForSingleDummyAction() throws I
testFlowVisualizer.visualize();
InputStream outputGalleryFile =
TestStorageUtil.getInputStream(
PlatformTestStorageRegistry.getInstance().getOutputFileUri2("output_gallery.html"),
PlatformTestStorageRegistry.getInstance().getOutputFileUri("output_gallery.html"),
InstrumentationRegistry.getInstrumentation().getTargetContext().getContentResolver());
int size = outputGalleryFile.available();
byte[] directFileContents = new byte[size];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -759,12 +759,12 @@ public OutputStream openInternalOutputFile(String pathname) {
}

@Override
public Uri getInputFileUri2(String pathname) {
public Uri getInputFileUri(String pathname) {
throw new UnsupportedOperationException();
}

@Override
public Uri getOutputFileUri2(String pathname) {
public Uri getOutputFileUri(String pathname) {
throw new UnsupportedOperationException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ public OutputStream openInternalOutputFile(String pathname) throws FileNotFoundE
}

@Override
public Uri getInputFileUri2(@NonNull String pathname) {
public Uri getInputFileUri(@NonNull String pathname) {
throw new UnsupportedOperationException();
}

@Override
public Uri getOutputFileUri2(@NonNull String pathname) {
public Uri getOutputFileUri(@NonNull String pathname) {
File outputFile = new File(pathname);
if (!outputFile.isAbsolute()) {
outputFile = new File(outputDirCalculator.getOutputDir(), pathname);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,15 @@ public interface PlatformTestStorage {
* @return a content Uri to the test file dependency.
* <p>Note: temporary API - will be renamed to getInputFileUri in future
*/
Uri getInputFileUri2(@NonNull String pathname);
Uri getInputFileUri(@NonNull String pathname);

/**
* @deprecated use getInputFileUri instead
*/
@Deprecated
default Uri getInputFileUri2(@NonNull String pathname) {
return getInputFileUri(pathname);
}

/**
* Provides a Uri to a test output file.
Expand All @@ -146,7 +154,15 @@ public interface PlatformTestStorage {
* "/path/to/my_output.txt", the file will end up at
* "/sdcard/test_output_files/path/to/my_output.txt" on device.
*/
Uri getOutputFileUri2(@NonNull String pathname);
Uri getOutputFileUri(@NonNull String pathname);

/**
* @deprecated use getOutputFileUri instead
*/
@Deprecated
default Uri getOutputFileUri2(@NonNull String pathname) {
return getOutputFileUri(pathname);
}

/**
* Returns true if {@code pathname} corresponds to a file or directory that is in a directory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ public OutputStream openInternalOutputFile(String pathname) {
}

@Override
public Uri getInputFileUri2(@NonNull String pathname) {
public Uri getInputFileUri(@NonNull String pathname) {
return null;
}

@Override
public Uri getOutputFileUri2(@NonNull String pathname) {
public Uri getOutputFileUri(@NonNull String pathname) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,6 @@ public TestStorage(@NonNull ContentResolver contentResolver) {
this.contentResolver = contentResolver;
}

/**
* @deprecated call getInputFileUri2 instead
*/
@Deprecated
public static Uri getInputFileUri(@NonNull String pathname) {
checkNotNull(pathname);
return HostedFile.buildUri(HostedFile.FileHost.TEST_FILE, pathname);
}

/**
* Provides a Uri to a test file dependency.
*
Expand All @@ -100,7 +91,7 @@ public static Uri getInputFileUri(@NonNull String pathname) {
* @return a content Uri to the test file dependency.
*/
@Override
public Uri getInputFileUri2(@NonNull String pathname) {
public Uri getInputFileUri(@NonNull String pathname) {
checkNotNull(pathname);
return HostedFile.buildUri(HostedFile.FileHost.TEST_FILE, pathname);
}
Expand All @@ -119,16 +110,7 @@ public Uri getInputFileUri2(@NonNull String pathname) {
* "/sdcard/test_output_files/path/to/my_output.txt" on device.
*/
@Override
public Uri getOutputFileUri2(@NonNull String pathname) {
checkNotNull(pathname);
return HostedFile.buildUri(HostedFile.FileHost.OUTPUT, pathname);
}

/**
* @deprecated call getOutputFileUri2 instead
*/
@Deprecated
public static Uri getOutputFileUri(@NonNull String pathname) {
public Uri getOutputFileUri(@NonNull String pathname) {
checkNotNull(pathname);
return HostedFile.buildUri(HostedFile.FileHost.OUTPUT, pathname);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ axt_android_library_test(
],
deps = [
"//core/java/androidx/test/core",
"//runner/monitor/java/androidx/test:monitor",
"//services/storage/java/androidx/test/services/storage",
"//services/storage/java/androidx/test/services/storage/file",
"@maven//:com_google_truth_truth",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void readWriteOverwriteReadFile() throws IOException {
}

StringBuilder contents = new StringBuilder();
Uri outputFileUri = testStorage.getOutputFileUri2("path/to/file");
Uri outputFileUri = testStorage.getOutputFileUri("path/to/file");
try (InputStream input =
TestStorageUtil.getInputStream(
outputFileUri, getApplicationContext().getContentResolver())) {
Expand All @@ -145,7 +145,7 @@ public void writeFileInAppendMode() throws IOException {
}

byte[] data = new byte[11];
Uri outputFileUri = testStorage.getOutputFileUri2("path/to/file");
Uri outputFileUri = testStorage.getOutputFileUri("path/to/file");
try (InputStream input =
TestStorageUtil.getInputStream(
outputFileUri, getApplicationContext().getContentResolver())) {
Expand Down

0 comments on commit 9ffb8f7

Please sign in to comment.