View Javadoc
1   /*
2    * Copyright (C) 2012 Jayway AB
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package com.simpligility.maven.plugins.android.standalonemojos;
18  
19  import java.io.File;
20  import java.io.IOException;
21  import java.lang.reflect.InvocationHandler;
22  import java.lang.reflect.Method;
23  import java.util.List;
24  import java.util.Map;
25  import java.util.concurrent.Future;
26  import java.util.concurrent.TimeUnit;
27  
28  import com.android.sdklib.AndroidVersion;
29  import org.junit.Ignore;
30  import org.junit.Test;
31  import org.junit.runner.RunWith;
32  import org.powermock.api.easymock.PowerMock;
33  import org.powermock.api.support.membermodification.MemberMatcher;
34  import org.powermock.core.classloader.annotations.PrepareForTest;
35  import org.powermock.modules.junit4.PowerMockRunner;
36  import org.powermock.reflect.Whitebox;
37  
38  import com.android.ddmlib.AdbCommandRejectedException;
39  import com.android.ddmlib.Client;
40  import com.android.ddmlib.FileListingService;
41  import com.android.ddmlib.IDevice;
42  import com.android.ddmlib.IShellOutputReceiver;
43  import com.android.ddmlib.InstallException;
44  import com.android.ddmlib.RawImage;
45  import com.android.ddmlib.ScreenRecorderOptions;
46  import com.android.ddmlib.ShellCommandUnresponsiveException;
47  import com.android.ddmlib.SyncException;
48  import com.android.ddmlib.SyncService;
49  import com.android.ddmlib.TimeoutException;
50  import com.android.ddmlib.log.LogReceiver;
51  import com.android.ddmlib.testrunner.RemoteAndroidTestRunner;
52  import com.simpligility.maven.plugins.android.AbstractAndroidMojo;
53  import com.simpligility.maven.plugins.android.AbstractAndroidMojoTestCase;
54  import com.simpligility.maven.plugins.android.DeviceCallback;
55  import com.simpligility.maven.plugins.android.phase12integrationtest.InternalIntegrationTestMojo;
56  
57  /**
58   * Tests the {@link InternalIntegrationTestMojo} mojo, as far as possible without actually
59   * connecting and communicating with a device.
60   * 
61   * @author Erik Ogenvik
62   * 
63   */
64  @Ignore("This test has to be migrated to be an IntegrationTest using AbstractAndroidMojoIntegrationTest") 
65  @RunWith(PowerMockRunner.class)
66  @PrepareForTest({ RemoteAndroidTestRunner.class, AbstractAndroidMojo.class })
67  public class InternalIntegrationTestMojoTest extends AbstractAndroidMojoTestCase<InternalIntegrationTestMojo> {
68  
69      @Override
70      public String getPluginGoalName() {
71          return "internal-integration-test";
72      }
73  
74      @Test
75      public void testTestProject() throws Exception {
76  
77          // We need to do some fiddling to make sure we run as far into the Mojo as possible without
78          // actually sending stuff to a device.
79          PowerMock.suppress(MemberMatcher.methodsDeclaredIn(RemoteAndroidTestRunner.class));
80          PowerMock.replace(AbstractAndroidMojo.class.getDeclaredMethod("doWithDevices", DeviceCallback.class)).with(new InvocationHandler() {
81  
82              @Override
83              public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
84                  // Just fake that we've found a device.
85                  DeviceCallback callback = (DeviceCallback) args[0];
86                  callback.doWithDevice(new IDevice() {
87  
88                      @Override
89                      public String getSerialNumber() {
90  
91                          return null;
92                      }
93  
94                      @Override
95                      public String getAvdName() {
96  
97                          return null;
98                      }
99  
100                     @Override
101                     public DeviceState getState() {
102 
103                         return null;
104                     }
105 
106                     @Override
107                     public Map<String, String> getProperties() {
108 
109                         return null;
110                     }
111 
112                     @Override
113                     public int getPropertyCount() {
114 
115                         return 0;
116                     }
117 
118                     @Override
119                     public String getProperty(String name) {
120 
121                         return null;
122                     }
123 
124                     @Override
125                     public String getMountPoint(String name) {
126 
127                         return null;
128                     }
129 
130                     @Override
131                     public boolean isOnline() {
132 
133                         return false;
134                     }
135 
136                     @Override
137                     public boolean isEmulator() {
138 
139                         return false;
140                     }
141 
142                     @Override
143                     public boolean isOffline() {
144 
145                         return false;
146                     }
147 
148                     @Override
149                     public boolean isBootLoader() {
150 
151                         return false;
152                     }
153 
154                     @Override
155                     public boolean hasClients() {
156 
157                         return false;
158                     }
159 
160                     @Override
161                     public Client[] getClients() {
162 
163                         return null;
164                     }
165 
166                     @Override
167                     public Client getClient(String applicationName) {
168 
169                         return null;
170                     }
171 
172                     @Override
173                     public SyncService getSyncService() throws TimeoutException, AdbCommandRejectedException, IOException {
174 
175                         return null;
176                     }
177 
178                     @Override
179                     public FileListingService getFileListingService() {
180 
181                         return null;
182                     }
183 
184                     @Override
185                     public RawImage getScreenshot() throws TimeoutException, AdbCommandRejectedException, IOException {
186 
187                         return null;
188                     }
189 
190                     @Override
191                     public RawImage getScreenshot(long l, TimeUnit timeUnit) throws TimeoutException, AdbCommandRejectedException, IOException {
192                         return null;
193                     }
194 
195                     @Override
196                     public void executeShellCommand(String command, IShellOutputReceiver receiver) throws
197                             TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException,
198                             IOException {
199                     }
200 
201                     @Override
202                     public void executeShellCommand(String command, IShellOutputReceiver receiver,
203                                                     int maxTimeToOutputResponse) throws TimeoutException,
204                             AdbCommandRejectedException, ShellCommandUnresponsiveException, IOException {
205 
206                     }
207 
208                     @Override
209                     public void runEventLogService(LogReceiver receiver) throws TimeoutException,
210                             AdbCommandRejectedException, IOException {
211 
212                     }
213 
214                     @Override
215                     public void runLogService(String logname, LogReceiver receiver) throws TimeoutException,
216                             AdbCommandRejectedException, IOException {
217 
218                     }
219 
220                     @Override
221                     public void createForward(int localPort, int remotePort) throws TimeoutException,
222                             AdbCommandRejectedException, IOException {
223 
224                     }
225 
226                     @Override
227                     public void removeForward(int localPort, int remotePort) throws TimeoutException,
228                             AdbCommandRejectedException, IOException {
229 
230                     }
231 
232                     @Override
233                     public String getClientName(int pid) {
234 
235                         return null;
236                     }
237 
238                     @Override
239                     public String syncPackageToDevice(String localFilePath) throws TimeoutException, AdbCommandRejectedException, IOException, SyncException {
240 
241                         return null;
242                     }
243 
244 
245                     @Override
246                     public void removeRemotePackage(String remoteFilePath) throws InstallException {
247 
248                     }
249 
250                     @Override
251                     public String uninstallPackage(String packageName) throws InstallException {
252                         return null;
253                     }
254 
255                     @Override
256                     public void reboot(String into) throws TimeoutException, AdbCommandRejectedException, IOException {
257 
258                     }
259 
260                     @Override
261                     public boolean arePropertiesSet() {
262                         return false;
263                     }
264 
265                     @Override
266                     public String getPropertySync(String s) throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException, IOException {
267                         return null;
268                     }
269 
270                     @Override
271                     public String getPropertyCacheOrSync(String s) throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException, IOException {
272                         return null;
273                     }
274 
275                     @Override
276                     public void pushFile(String s, String s1) throws IOException, AdbCommandRejectedException, TimeoutException, SyncException {
277 
278                     }
279 
280                     @Override
281                     public void pullFile(String s, String s1) throws IOException, AdbCommandRejectedException, TimeoutException, SyncException {
282 
283                     }
284 
285                     @Override
286                     public void installPackage(String s, boolean b, String... strings) throws InstallException {
287                     }
288 
289                     @Override
290                     public void installPackages (List<File> list, boolean b, List<String> list1, long l, TimeUnit timeUnit ) throws InstallException
291                     {
292 
293                     }
294 
295                     @Override
296                     public void installRemotePackage(String s, boolean b, String... strings) throws InstallException {
297                     }
298 
299                     @Override
300                     public Integer getBatteryLevel() throws TimeoutException, AdbCommandRejectedException, IOException, ShellCommandUnresponsiveException {
301                         return null;
302                     }
303 
304                     @Override
305                     public Integer getBatteryLevel(long l) throws TimeoutException, AdbCommandRejectedException, IOException, ShellCommandUnresponsiveException {
306                         return null;
307                     }
308 
309                     @Override
310                     public Future<Integer> getBattery() {
311                         return null;
312                     }
313 
314                     @Override
315                     public Future<Integer> getBattery(long l, TimeUnit timeUnit) {
316                         return null;
317                     }
318 
319                     @Override
320                     public void createForward(int arg0, String arg1, DeviceUnixSocketNamespace arg2)
321                             throws TimeoutException, AdbCommandRejectedException, IOException
322                     {
323                     }
324 
325                     @Override
326                     public String getName()
327                     {
328                         return null;
329                     }
330 
331                     @Override
332                     public void executeShellCommand(String s, IShellOutputReceiver iShellOutputReceiver, long l, TimeUnit timeUnit)
333                         throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException, IOException
334                     {
335                     }
336 
337                     @Override
338                     public Future<String> getSystemProperty(String s) {
339                         return null;
340                     }
341 
342                     @Override
343                     public void removeForward(int arg0, String arg1, DeviceUnixSocketNamespace arg2)
344                             throws TimeoutException, AdbCommandRejectedException, IOException
345                     {
346                     }
347 
348                     @Override
349                     public boolean supportsFeature(Feature feature) {
350                         return false;
351                     }
352 
353                     @Override
354                     public void startScreenRecorder(String remoteFilePath,
355                             ScreenRecorderOptions options,
356                             IShellOutputReceiver receiver)
357                             throws TimeoutException,
358                             AdbCommandRejectedException, IOException,
359                             ShellCommandUnresponsiveException {
360                     }
361 
362                     @Override
363                     public boolean supportsFeature(HardwareFeature arg0) {
364                       return false;
365                     }
366 
367                     @Override
368                     public List<String> getAbis() {
369                       return null;
370                     }
371 
372                     @Override
373                     public int getDensity() {
374                       return 0;
375                     }
376 
377                     @Override
378                     public String getLanguage() {
379                         return null;
380                     }
381 
382                     @Override
383                     public String getRegion() {
384                         return null;
385                     }
386 
387                     @Override
388                     public AndroidVersion getVersion() {
389                         return null;
390                     }
391 
392                     @Override
393                     public boolean root() throws TimeoutException, AdbCommandRejectedException, IOException,
394                         ShellCommandUnresponsiveException {
395                       return false;
396                     }
397 
398                     @Override
399                     public boolean isRoot() throws TimeoutException, AdbCommandRejectedException, IOException,
400                         ShellCommandUnresponsiveException {
401                       return false;
402                     }
403 
404                 });
405                 return null;
406             }
407         });
408 
409         InternalIntegrationTestMojo mojo = createMojo("manifest-tests/test-project");
410 
411         mojo.execute();
412         List<String> classes = Whitebox.getInternalState(mojo, "parsedClasses");
413         assertNotNull(classes);
414         assertEquals(1, classes.size());
415     }
416 }