From b0361ffa3e25ab3e234a5ccaa5587b7dca88de76 Mon Sep 17 00:00:00 2001 From: Zhomart Mukhamejanov Date: Fri, 18 May 2018 10:22:13 -0700 Subject: updater_config: make utils/PayloadSpecs non-static PayloadSpecs has complicated methods, which makes hard to test other dependent classes. Making it non-static allows mocking it, which makes testing other classes easier. Test: manually Test: using JUnit4 Change-Id: I818dc59c6bb0e7d131439d0d41f88d5cd9a451b4 Signed-off-by: Zhomart Mukhamejanov --- .../android/systemupdatersample/util/PayloadSpecsTest.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'updater_sample/tests/src') diff --git a/updater_sample/tests/src/com/example/android/systemupdatersample/util/PayloadSpecsTest.java b/updater_sample/tests/src/com/example/android/systemupdatersample/util/PayloadSpecsTest.java index d9e54652f..3ba84c116 100644 --- a/updater_sample/tests/src/com/example/android/systemupdatersample/util/PayloadSpecsTest.java +++ b/updater_sample/tests/src/com/example/android/systemupdatersample/util/PayloadSpecsTest.java @@ -55,6 +55,8 @@ public class PayloadSpecsTest { private Context mTargetContext; private Context mTestContext; + private PayloadSpecs mPayloadSpecs; + @Rule public final ExpectedException thrown = ExpectedException.none(); @@ -64,6 +66,7 @@ public class PayloadSpecsTest { mTestContext = InstrumentationRegistry.getContext(); mTestDir = mTargetContext.getFilesDir(); + mPayloadSpecs = new PayloadSpecs(); } @Test @@ -75,7 +78,7 @@ public class PayloadSpecsTest { java.nio.file.Files.deleteIfExists(packageFile.toPath()); java.nio.file.Files.copy(mTestContext.getResources().openRawResource(R.raw.ota_002_package), packageFile.toPath()); - PayloadSpec spec = PayloadSpecs.forNonStreaming(packageFile); + PayloadSpec spec = mPayloadSpecs.forNonStreaming(packageFile); assertEquals("correct url", "file://" + packageFile.getAbsolutePath(), spec.getUrl()); assertEquals("correct payload offset", @@ -90,7 +93,7 @@ public class PayloadSpecsTest { @Test public void forNonStreaming_IOException() throws Exception { thrown.expect(IOException.class); - PayloadSpecs.forNonStreaming(new File("/fake/news.zip")); + mPayloadSpecs.forNonStreaming(new File("/fake/news.zip")); } @Test @@ -100,7 +103,7 @@ public class PayloadSpecsTest { long size = 200; File propertiesFile = createMockPropertiesFile(); - PayloadSpec spec = PayloadSpecs.forStreaming(url, offset, size, propertiesFile); + PayloadSpec spec = mPayloadSpecs.forStreaming(url, offset, size, propertiesFile); assertEquals("same url", url, spec.getUrl()); assertEquals("same offset", offset, spec.getOffset()); assertEquals("same size", size, spec.getSize()); -- cgit v1.2.3