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.jayway.maven.plugins.android.standalonemojos;
18  
19  import java.io.IOException;
20  import java.lang.reflect.InvocationHandler;
21  import java.lang.reflect.Method;
22  import java.util.List;
23  import java.util.Map;
24  
25  import org.junit.Test;
26  import org.junit.runner.RunWith;
27  import org.powermock.api.easymock.PowerMock;
28  import org.powermock.api.support.membermodification.MemberMatcher;
29  import org.powermock.core.classloader.annotations.PrepareForTest;
30  import org.powermock.modules.junit4.PowerMockRunner;
31  import org.powermock.reflect.Whitebox;
32  
33  import com.android.ddmlib.AdbCommandRejectedException;
34  import com.android.ddmlib.Client;
35  import com.android.ddmlib.FileListingService;
36  import com.android.ddmlib.IDevice;
37  import com.android.ddmlib.IShellOutputReceiver;
38  import com.android.ddmlib.InstallException;
39  import com.android.ddmlib.RawImage;
40  import com.android.ddmlib.ShellCommandUnresponsiveException;
41  import com.android.ddmlib.SyncException;
42  import com.android.ddmlib.SyncService;
43  import com.android.ddmlib.TimeoutException;
44  import com.android.ddmlib.log.LogReceiver;
45  import com.android.ddmlib.testrunner.RemoteAndroidTestRunner;
46  import com.jayway.maven.plugins.android.AbstractAndroidMojo;
47  import com.jayway.maven.plugins.android.AbstractAndroidMojoTestCase;
48  import com.jayway.maven.plugins.android.DeviceCallback;
49  import com.jayway.maven.plugins.android.phase12integrationtest.InternalIntegrationTestMojo;
50  
51  /**
52   * Tests the {@link InternalIntegrationTestMojo} mojo, as far as possible without actually
53   * connecting and communicating with a device.
54   * 
55   * @author Erik Ogenvik
56   * 
57   */
58  @RunWith(PowerMockRunner.class)
59  @PrepareForTest({ RemoteAndroidTestRunner.class, AbstractAndroidMojo.class })
60  public class InternalIntegrationTestMojoTest extends AbstractAndroidMojoTestCase<InternalIntegrationTestMojo> {
61  
62      @Override
63      public String getPluginGoalName() {
64          return "internal-integration-test";
65      }
66  
67      @Test
68      public void testTestProject() throws Exception {
69  
70          // We need to do some fiddling to make sure we run as far into the Mojo as possible without
71          // actually sending stuff to a device.
72          PowerMock.suppress(MemberMatcher.methodsDeclaredIn(RemoteAndroidTestRunner.class));
73          PowerMock.replace(AbstractAndroidMojo.class.getDeclaredMethod("doWithDevices", DeviceCallback.class)).with(new InvocationHandler() {
74  
75              @Override
76              public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
77                  // Just fake that we've found a device.
78                  DeviceCallback callback = (DeviceCallback) args[0];
79                  callback.doWithDevice(new IDevice() {
80  
81                      @Override
82                      public String getSerialNumber() {
83  
84                          return null;
85                      }
86  
87                      @Override
88                      public String getAvdName() {
89  
90                          return null;
91                      }
92  
93                      @Override
94                      public DeviceState getState() {
95  
96                          return null;
97                      }
98  
99                      @Override
100                     public Map<String, String> getProperties() {
101 
102                         return null;
103                     }
104 
105                     @Override
106                     public int getPropertyCount() {
107 
108                         return 0;
109                     }
110 
111                     @Override
112                     public String getProperty(String name) {
113 
114                         return null;
115                     }
116 
117                     @Override
118                     public String getMountPoint(String name) {
119 
120                         return null;
121                     }
122 
123                     @Override
124                     public boolean isOnline() {
125 
126                         return false;
127                     }
128 
129                     @Override
130                     public boolean isEmulator() {
131 
132                         return false;
133                     }
134 
135                     @Override
136                     public boolean isOffline() {
137 
138                         return false;
139                     }
140 
141                     @Override
142                     public boolean isBootLoader() {
143 
144                         return false;
145                     }
146 
147                     @Override
148                     public boolean hasClients() {
149 
150                         return false;
151                     }
152 
153                     @Override
154                     public Client[] getClients() {
155 
156                         return null;
157                     }
158 
159                     @Override
160                     public Client getClient(String applicationName) {
161 
162                         return null;
163                     }
164 
165                     @Override
166                     public SyncService getSyncService() throws TimeoutException, AdbCommandRejectedException, IOException {
167 
168                         return null;
169                     }
170 
171                     @Override
172                     public FileListingService getFileListingService() {
173 
174                         return null;
175                     }
176 
177                     @Override
178                     public RawImage getScreenshot() throws TimeoutException, AdbCommandRejectedException, IOException {
179 
180                         return null;
181                     }
182 
183                     @Override
184                     public void executeShellCommand(String command, IShellOutputReceiver receiver) throws
185                             TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException,
186                             IOException {
187                     }
188 
189                     @Override
190                     public void executeShellCommand(String command, IShellOutputReceiver receiver,
191                                                     int maxTimeToOutputResponse) throws TimeoutException,
192                             AdbCommandRejectedException, ShellCommandUnresponsiveException, IOException {
193 
194                     }
195 
196                     @Override
197                     public void runEventLogService(LogReceiver receiver) throws TimeoutException,
198                             AdbCommandRejectedException, IOException {
199 
200                     }
201 
202                     @Override
203                     public void runLogService(String logname, LogReceiver receiver) throws TimeoutException,
204                             AdbCommandRejectedException, IOException {
205 
206                     }
207 
208                     @Override
209                     public void createForward(int localPort, int remotePort) throws TimeoutException,
210                             AdbCommandRejectedException, IOException {
211 
212                     }
213 
214                     @Override
215                     public void removeForward(int localPort, int remotePort) throws TimeoutException,
216                             AdbCommandRejectedException, IOException {
217 
218                     }
219 
220                     @Override
221                     public String getClientName(int pid) {
222 
223                         return null;
224                     }
225 
226                     @Override
227                     public String syncPackageToDevice(String localFilePath) throws TimeoutException, AdbCommandRejectedException, IOException, SyncException {
228 
229                         return null;
230                     }
231 
232 
233                     @Override
234                     public void removeRemotePackage(String remoteFilePath) throws InstallException {
235 
236                     }
237 
238                     @Override
239                     public String uninstallPackage(String packageName) throws InstallException {
240                         return null;
241                     }
242 
243                     @Override
244                     public void reboot(String into) throws TimeoutException, AdbCommandRejectedException, IOException {
245 
246                     }
247 
248                     @Override
249                     public boolean arePropertiesSet() {
250                         return false;
251                     }
252 
253                     @Override
254                     public String getPropertySync(String s) throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException, IOException {
255                         return null;
256                     }
257 
258                     @Override
259                     public String getPropertyCacheOrSync(String s) throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException, IOException {
260                         return null;
261                     }
262 
263                     @Override
264                     public void pushFile(String s, String s1) throws IOException, AdbCommandRejectedException, TimeoutException, SyncException {
265 
266                     }
267 
268                     @Override
269                     public void pullFile(String s, String s1) throws IOException, AdbCommandRejectedException, TimeoutException, SyncException {
270 
271                     }
272 
273                     @Override
274                     public String installPackage(String s, boolean b, String... strings) throws InstallException {
275                         return null;
276                     }
277 
278                     @Override
279                     public String installRemotePackage(String s, boolean b, String... strings) throws InstallException {
280                         return null;
281                     }
282 
283                     @Override
284                     public Integer getBatteryLevel() throws TimeoutException, AdbCommandRejectedException, IOException, ShellCommandUnresponsiveException {
285                         return null;
286                     }
287 
288                     @Override
289                     public Integer getBatteryLevel(long l) throws TimeoutException, AdbCommandRejectedException, IOException, ShellCommandUnresponsiveException {
290                         return null;
291                     }
292 
293                     @Override
294                     public void createForward(int arg0, String arg1, DeviceUnixSocketNamespace arg2)
295                             throws TimeoutException, AdbCommandRejectedException, IOException
296                     {
297                     }
298 
299                     @Override
300                     public String getName()
301                     {
302                         return null;
303                     }
304 
305                     @Override
306                     public void removeForward(int arg0, String arg1, DeviceUnixSocketNamespace arg2)
307                             throws TimeoutException, AdbCommandRejectedException, IOException
308                     {
309                     }
310                 });
311                 return null;
312             }
313         });
314 
315         InternalIntegrationTestMojo mojo = createMojo("manifest-tests/test-project");
316 
317         mojo.execute();
318         List<String> classes = Whitebox.getInternalState(mojo, "parsedClasses");
319         assertNotNull(classes);
320         assertEquals(1, classes.size());
321     }
322 }