• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * 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, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */
16 
17 package com.google.android.mobly.snippet.example1;
18 
19 import com.google.android.mobly.snippet.Snippet;
20 import com.google.android.mobly.snippet.rpc.Rpc;
21 
22 import com.google.android.mobly.snippet.rpc.RunOnUiThread;
23 
24 import org.json.JSONArray;
25 
26 import java.io.IOException;
27 
28 public class ExampleSnippet2 implements Snippet {
29     @Rpc(description = "Returns the given string with the prefix \"bar\"")
getBar(String input)30     public String getBar(String input) {
31         return "bar " + input;
32     }
33 
34     @Rpc(description = "Returns the given JSON array with the prefix \"bar\"")
getJSONArray(JSONArray input)35     public String getJSONArray(JSONArray input) {
36         return "bar " + input;
37     }
38 
39     @Rpc(description = "Throws an exception")
throwSomething()40     public String throwSomething() throws IOException {
41         throw new IOException("Example exception from throwSomething()");
42     }
43 
44     @Rpc(description = "Throws an exception from the main thread")
45     // @RunOnUiThread makes this method execute on the main thread, but only has effect when
46     // invoked as an RPC. It does not affect how this method executes if invoked directly in Java.
47     // This annotation can also be applied to the constructor and the shutdown() method.
48     @RunOnUiThread
throwSomethingFromMainThread()49     public String throwSomethingFromMainThread() throws IOException {
50         throw new IOException("Example exception from throwSomethingFromMainThread()");
51     }
52 
53     @Override
shutdown()54     public void shutdown() {}
55 }
56