diff options
author | Raphael Moll <ralf@android.com> | 2012-08-28 16:21:06 -0700 |
---|---|---|
committer | Raphael Moll <ralf@android.com> | 2012-08-28 16:50:03 -0700 |
commit | 97ff66c481de45c87e3ce6d462037dee3c73f418 (patch) | |
tree | 747f46a0564a1661026b1e45d0b9b00ada9c53ba /sdkmanager/app | |
parent | 96e729c9d0a7ba82e93eb30a9698e1f3f349b653 (diff) | |
download | sdk-97ff66c481de45c87e3ce6d462037dee3c73f418.zip sdk-97ff66c481de45c87e3ce6d462037dee3c73f418.tar.gz sdk-97ff66c481de45c87e3ce6d462037dee3c73f418.tar.bz2 |
Fix SdkManager.hasChanged
Also add a simple unit test.
Change-Id: I8ed3dfbea07578528036f1dabd75c18f3161819c
Diffstat (limited to 'sdkmanager/app')
-rw-r--r-- | sdkmanager/app/tests/com/android/sdkmanager/MainTest.java | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/sdkmanager/app/tests/com/android/sdkmanager/MainTest.java b/sdkmanager/app/tests/com/android/sdkmanager/MainTest.java index 10d7576..96cb003 100644 --- a/sdkmanager/app/tests/com/android/sdkmanager/MainTest.java +++ b/sdkmanager/app/tests/com/android/sdkmanager/MainTest.java @@ -19,6 +19,7 @@ package com.android.sdkmanager; import com.android.SdkConstants; import com.android.sdklib.IAndroidTarget; +import com.android.sdklib.SdkManager; import com.android.sdklib.SdkManagerTestCase; import com.android.sdklib.internal.avd.AvdInfo; import com.android.sdklib.repository.SdkAddonConstants; @@ -26,6 +27,8 @@ import com.android.sdklib.repository.SdkRepoConstants; import com.android.utils.Pair; import java.io.File; +import java.io.FileWriter; +import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Set; @@ -161,6 +164,50 @@ public class MainTest extends SdkManagerTestCase { getLog().toString()); } + public void testSdkManagerHasChanged() throws IOException { + Main main = new Main(); + main.setLogger(getLog()); + SdkManager sdkman = getSdkManager(); + main.setSdkManager(sdkman); + getLog().clear(); + + assertFalse(sdkman.hasChanged()); + + File addonsDir = new File(sdkman.getLocation(), SdkConstants.FD_ADDONS); + assertTrue(addonsDir.isDirectory()); + + FileWriter readme = new FileWriter(new File(addonsDir, "android.txt")); + readme.write("test\n"); + readme.close(); + + // Adding a file doesn't alter sdk.hasChanged + assertFalse(sdkman.hasChanged()); + sdkman.reloadSdk(getLog()); + assertFalse(sdkman.hasChanged()); + + File fakeAddon = new File(addonsDir, "google-addon"); + fakeAddon.mkdirs(); + File sourceProps = new File(fakeAddon, SdkConstants.FN_SOURCE_PROP); + FileWriter propsWriter = new FileWriter(sourceProps); + propsWriter.write("revision=7\n"); + propsWriter.close(); + + // Adding a directory does alter sdk.hasChanged even if not a real add-on + assertTrue(sdkman.hasChanged()); + // Once reloaded, sdk.hasChanged will be reset + sdkman.reloadSdk(getLog()); + assertFalse(sdkman.hasChanged()); + + // Changing the source.properties file alters sdk.hasChanged + propsWriter = new FileWriter(sourceProps); + propsWriter.write("revision=8\n"); + propsWriter.close(); + assertTrue(sdkman.hasChanged()); + // Once reloaded, sdk.hasChanged will be reset + sdkman.reloadSdk(getLog()); + assertFalse(sdkman.hasChanged()); + } + public void testCheckFilterValues() { // These are the values we expect checkFilterValues() to match. String[] expectedValues = { |