From 9eee1bbdaa7b1ce0b29b75d7c3b05b343fa33f8d Mon Sep 17 00:00:00 2001 From: Julien Desprez Date: Wed, 24 Feb 2021 17:55:25 -0800 Subject: Change a test to be robust to env. * delete a duplicated coverage test * Avoid using a random file, instead create a tmp file location for the test. Test: unit tests Bug; 181171606 Change-Id: I62a74c025a01accc23f06aa62c65bc23fb0ec07f (cherry picked from commit 64d813b195d54c302bc43e51b7369836ba1ffb35) --- .../contentprovider/ContentProviderHandlerTest.java | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/tests/src/com/android/tradefed/device/contentprovider/ContentProviderHandlerTest.java b/tests/src/com/android/tradefed/device/contentprovider/ContentProviderHandlerTest.java index a9f453352..e72b23a21 100644 --- a/tests/src/com/android/tradefed/device/contentprovider/ContentProviderHandlerTest.java +++ b/tests/src/com/android/tradefed/device/contentprovider/ContentProviderHandlerTest.java @@ -190,28 +190,16 @@ public class ContentProviderHandlerTest { /** Test {@link ContentProviderHandler#pullFile(String, File)}. */ @Test public void testPullFile_createLocalFileIfNotExist() throws Exception { - File pullTo = new File("content-provider-test.txt"); + File pullTo = FileUtil.createTempFile("content-provider-test", ".txt"); + // Delete to test unexisting file. + pullTo.delete(); String devicePath = "path/somewhere/file.txt"; mockPullFileSuccess(); try { assertFalse(pullTo.exists()); - mProvider.pullFile(devicePath, pullTo); - assertTrue(pullTo.exists()); - } finally { - FileUtil.deleteFile(pullTo); - } - } - - /** Test {@link ContentProviderHandler#pullFile(String, File)}. */ - @Test - public void testPullFile_success() throws Exception { - File pullTo = new File("content-provider-test.txt"); - String devicePath = "path/somewhere/file.txt"; - - try { - mockPullFileSuccess(); assertTrue(mProvider.pullFile(devicePath, pullTo)); + assertTrue(pullTo.exists()); } finally { FileUtil.deleteFile(pullTo); } -- cgit v1.2.3