1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.simpligility.maven.plugins.android;
17
18 import java.io.File;
19 import java.io.IOException;
20 import java.net.URISyntaxException;
21
22 import org.codehaus.plexus.util.ReflectionUtils;
23 import org.junit.Assert;
24 import org.junit.Before;
25 import org.junit.Test;
26
27 import com.simpligility.maven.plugins.android.AndroidSdk;
28 import com.simpligility.maven.plugins.android.InvalidSdkException;
29 import org.junit.Ignore;
30
31
32
33
34
35
36
37 public class AndroidSdkTest {
38
39 private SdkTestSupport sdkTestSupport;
40
41 @Before
42 public void setUp(){
43 sdkTestSupport = new SdkTestSupport();
44 }
45
46 @Test
47 public void givenToolAdbThenPathIsPlatformTools() {
48 final String pathForTool =sdkTestSupport.getSdk_with_platform_default().getAdbPath();
49 Assert.assertEquals(new File(sdkTestSupport.getEnv_ANDROID_HOME() + "/platform-tools").getAbsolutePath(), new File(pathForTool).getParentFile().getAbsolutePath());
50 }
51
52 @Test
53 public void givenToolAndroidThenPathIsCommon() {
54 final String pathForTool = sdkTestSupport.getSdk_with_platform_default().getAndroidPath();
55 Assert.assertEquals(new File(sdkTestSupport.getEnv_ANDROID_HOME() + "/tools").getAbsolutePath(), new File(pathForTool).getParentFile().getAbsolutePath());
56 }
57
58
59 @Test(expected = InvalidSdkException.class)
60 public void givenInvalidPlatformStringThenException() throws IOException {
61 final AndroidSdk sdk = new AndroidSdk(new File(sdkTestSupport.getEnv_ANDROID_HOME()), "invalidplatform");
62 }
63
64 @Test
65 public void givenPlatformNullThenPlatformisSomethingValidLooking() throws IllegalAccessException, URISyntaxException {
66 final File sdkPath = (File) ReflectionUtils.getValueIncludingSuperclasses("sdkPath",sdkTestSupport.getSdk_with_platform_default());
67 final File platform = sdkTestSupport.getSdk_with_platform_default().getPlatform();
68 final String platformPath = platform.getAbsoluteFile().toURI().toString();
69 final String regex = "/platforms/android-.*";
70
71 String matcher = platformPath.substring( sdkPath.toURI().toString().length() -1 );
72 Assert.assertTrue(String.format("Platform [%s] does not match regex: [%s]", matcher,regex), matcher.matches(regex));
73 }
74
75
76
77
78
79 @Test
80 public void validPlatformsAndApiLevels19() {
81
82 final AndroidSdk sdk19 = new AndroidSdk(new File(sdkTestSupport.getEnv_ANDROID_HOME()), "19");
83 }
84
85 @Test
86 public void validPlatformsAndApiLevels22() {
87
88 final AndroidSdk sdk22 = new AndroidSdk(new File(sdkTestSupport.getEnv_ANDROID_HOME()), "22", null);
89 Assert.assertTrue( sdk22.getAaptPath() != null && !sdk22.getAaptPath().equals( "" ) );
90 }
91
92 @Test
93 public void validPlatformsAndApiLevels25() {
94
95 final AndroidSdk sdk25 = new AndroidSdk( new File( sdkTestSupport.getEnv_ANDROID_HOME()), "25", "25.0.3" );
96 Assert.assertTrue( sdk25.getAaptPath() != null && !sdk25.getAaptPath().equals( "" ) );
97 }
98
99 @Test
100 public void validPlatformsAndApiLevels23() {
101
102 final AndroidSdk sdk23 = new AndroidSdk( new File( sdkTestSupport.getEnv_ANDROID_HOME() ), "23" );
103 Assert.assertTrue( sdk23.getAaptPath() != null && !sdk23.getAaptPath().equals( "" ) );
104 }
105
106 @Test
107 public void validPlatformsAndApiLevels28() {
108
109 final AndroidSdk sdk23 = new AndroidSdk( new File( sdkTestSupport.getEnv_ANDROID_HOME() ), "28" );
110 Assert.assertTrue( sdk23.getAaptPath() != null && !sdk23.getAaptPath().equals( "" ) );
111 }
112
113 @Test(expected = InvalidSdkException.class)
114 public void invalidPlatformAndApiLevels() {
115 final AndroidSdk invalid = new AndroidSdk (new File( sdkTestSupport.getEnv_ANDROID_HOME() ), "invalid" );
116 }
117
118 @Test(expected = NumberFormatException.class)
119 public void invalidBuildTools() {
120 final AndroidSdk invalid = new AndroidSdk (new File( sdkTestSupport.getEnv_ANDROID_HOME() ), "19", "invalid" );
121 invalid.getAaptPath();
122 }
123
124 @Test
125 public void validPlatformsAndApiLevelsWithDiffBuildTools1() {
126
127 final AndroidSdk sdk = new AndroidSdk( new File( sdkTestSupport.getEnv_ANDROID_HOME() ), "19", "25.0.3" );
128 Assert.assertTrue( sdk.getAaptPath() != null && !sdk.getAaptPath().equals( "" ) );
129 }
130
131 @Test
132 public void validPlatformsAndApiLevelsWithDiffBuildTools2() {
133
134 final AndroidSdk sdk = new AndroidSdk( new File( sdkTestSupport.getEnv_ANDROID_HOME() ), "19", "24.0.3" );
135 Assert.assertTrue( sdk.getAaptPath() != null && !sdk.getAaptPath().equals( "" ) );
136 }
137
138 @Test
139 public void validPlatformsAndApiLevelsWithDiffBuildTools3() {
140
141 final AndroidSdk sdk = new AndroidSdk( new File( sdkTestSupport.getEnv_ANDROID_HOME() ), "28", "28.0.3" );
142 Assert.assertTrue( sdk.getAaptPath() != null && !sdk.getAaptPath().equals( "" ) );
143 }
144
145 }