blob: e9f70d4966a256f4bbd06cf7f85536ea00617a73 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.tools.lint.checks;
import com.android.tools.lint.detector.api.Detector;
@SuppressWarnings("javadoc")
public class OnClickDetectorTest extends AbstractCheckTest {
@Override
protected Detector getDetector() {
return new OnClickDetector();
}
public void test() throws Exception {
assertEquals(
"src/test/pkg/OnClickActivity.java:27: Error: On click handler wrong5(View) must be public [OnClick]\n" +
" void wrong5(View view) {\n" +
" ~~~~~~\n" +
"src/test/pkg/OnClickActivity.java:31: Error: On click handler wrong6(View) should not be static [OnClick]\n" +
" public static void wrong6(View view) {\n" +
" ~~~~~~\n" +
"src/test/pkg/OnClickActivity.java:45: Error: On click handler wrong7(View) must be public [OnClick]\n" +
" void wrong7(View view) {\n" +
" ~~~~~~\n" +
"res/layout/onclick.xml:10: Error: Corresponding method handler 'public void nonexistent(android.view.View)' not found [OnClick]\n" +
" android:onClick=\"nonexistent\"\n" +
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" +
"res/layout/onclick.xml:16: Error: Corresponding method handler 'public void wrong1(android.view.View)' not found [OnClick]\n" +
" android:onClick=\"wrong1\"\n" +
" ~~~~~~~~~~~~~~~~~~~~~~~~\n" +
"res/layout/onclick.xml:22: Error: Corresponding method handler 'public void wrong2(android.view.View)' not found [OnClick]\n" +
" android:onClick=\"wrong2\"\n" +
" ~~~~~~~~~~~~~~~~~~~~~~~~\n" +
"res/layout/onclick.xml:28: Error: Corresponding method handler 'public void wrong3(android.view.View)' not found [OnClick]\n" +
" android:onClick=\"wrong3\"\n" +
" ~~~~~~~~~~~~~~~~~~~~~~~~\n" +
"res/layout/onclick.xml:34: Error: Corresponding method handler 'public void wrong4(android.view.View)' not found [OnClick]\n" +
" android:onClick=\"wrong4\"\n" +
" ~~~~~~~~~~~~~~~~~~~~~~~~\n" +
"res/layout/onclick.xml:58: Error: Corresponding method handler 'public void simple_typo(android.view.View)' not found (did you mean void test.pkg.OnClickActivity#simple_tyop(android.view.View) ?) [OnClick]\n" +
" android:onClick=\"simple_typo\"\n" +
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" +
"9 errors, 0 warnings\n" +
"",
lintProject(
"bytecode/.classpath=>.classpath",
"bytecode/AndroidManifest.xml=>AndroidManifest.xml",
"res/layout/onclick.xml=>res/layout/onclick.xml",
"bytecode/OnClickActivity.java.txt=>src/test/pkg/OnClickActivity.java",
"bytecode/OnClickActivity.class.data=>bin/classes/test/pkg/OnClickActivity.class"
));
}
public void testOk() throws Exception {
// No onClick attributes
assertEquals(
"No warnings.",
lintProject("res/layout/accessibility.xml"));
}
}
|