Skip to content

Commit c6d2b30

Browse files
committed
Merge pull request androidannotations#1228 from WonderCsabo/1216_moveToCompileTimeTests
Add missing tests
2 parents c8b8725 + b2c88d3 commit c6d2b30

28 files changed

Lines changed: 1125 additions & 94 deletions
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**
2+
* Copyright (C) 2010-2014 eBusiness Information, Excilys Group
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+
package org.androidannotations.copyannotations;
17+
18+
import org.androidannotations.AndroidAnnotationProcessor;
19+
import org.androidannotations.utils.AAProcessorTestHelper;
20+
import org.junit.Before;
21+
import org.junit.Test;
22+
23+
public class CopyOtherAnnotationsTest extends AAProcessorTestHelper {
24+
25+
@Before
26+
public void setup() {
27+
addManifestProcessorParameter(CopyOtherAnnotationsTest.class);
28+
addProcessor(AndroidAnnotationProcessor.class);
29+
}
30+
31+
@Test
32+
public void testGeneretedClassWithCopiedAnnotationsCompiles() {
33+
assertCompilationSuccessful(compileFiles(HasOtherAnnotations.class));
34+
}
35+
36+
@Test
37+
public void testGeneratedClassHasCopiedNonAAAnnotations() {
38+
String[] classHeader = { //
39+
"@XmlType", //
40+
"@TestTargetClass(String.class)", //
41+
"@WebServiceRefs({", //
42+
" @WebServiceRef(type = String.class)", //
43+
"})", //
44+
"public final class HasOtherAnnotations_" };
45+
46+
compileFiles(HasOtherAnnotations.class);
47+
assertGeneratedClassContains(toGeneratedFile(HasOtherAnnotations.class), classHeader);
48+
}
49+
50+
@Test
51+
public void testOverridenMethodHasCopiedNonAAAnnotations() {
52+
String[] methodSignature = { //
53+
" @Addressing(responses = (javax.xml.ws.soap.AddressingFeature.Responses.ALL))", //
54+
" @Action(input = \"someString\")", //
55+
" @SuppressWarnings({", //
56+
" \"\",", //
57+
" \"hi\"", //
58+
" })", //
59+
" @Override", //
60+
" public void onEvent(final Event event) {" };
61+
62+
compileFiles(HasOtherAnnotations.class);
63+
assertGeneratedClassContains(toGeneratedFile(HasOtherAnnotations.class), methodSignature);
64+
}
65+
66+
@Test
67+
public void testOverrideDoesNotAddedTwice() {
68+
addProcessorParameter("trace", "true");
69+
compileFiles(HasOtherAnnotations.class);
70+
71+
String[] methodSignature = { //
72+
" @java.lang.Override", //
73+
" @java.lang.Override", //
74+
" public String toString() {" };
75+
76+
assertGeneratedClassDoesNotContain(toGeneratedFile(HasOtherAnnotations.class), methodSignature);
77+
}
78+
}

AndroidAnnotations/functional-test-1-5/src/main/java/org/androidannotations/test15/OthersAnnotations.java renamed to AndroidAnnotations/androidannotations/src/test/java/org/androidannotations/copyannotations/HasOtherAnnotations.java

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,56 +13,41 @@
1313
* License for the specific language governing permissions and limitations under
1414
* the License.
1515
*/
16-
package org.androidannotations.test15;
16+
package org.androidannotations.copyannotations;
17+
18+
import javax.xml.bind.annotation.XmlType;
19+
import javax.xml.ws.Action;
20+
import javax.xml.ws.WebServiceRef;
21+
import javax.xml.ws.WebServiceRefs;
22+
import javax.xml.ws.soap.Addressing;
23+
import javax.xml.ws.soap.AddressingFeature.Responses;
1724

18-
import android.os.Parcel;
19-
import android.os.Parcelable;
20-
import com.squareup.otto.Produce;
21-
import com.squareup.otto.Subscribe;
22-
import com.test.ComplexAnnotation;
23-
import com.test.SimpleAnnotation;
24-
import dalvik.annotation.TestTargetClass;
2525
import org.androidannotations.annotations.Background;
2626
import org.androidannotations.annotations.EBean;
2727
import org.androidannotations.annotations.Trace;
28-
import org.simpleframework.xml.Attribute;
2928

30-
import javax.annotation.Nonnull;
31-
import javax.annotation.Nullable;
32-
import javax.annotation.meta.When;
29+
import dalvik.annotation.TestTargetClass;
3330

3431
@EBean
35-
@Nullable
32+
@XmlType
3633
@TestTargetClass(String.class)
37-
@ComplexAnnotation(value = @SimpleAnnotation("1"), array = {@SimpleAnnotation("2"), @SimpleAnnotation("3")})
38-
public class OthersAnnotations implements Parcelable {
39-
40-
@Trace
34+
@WebServiceRefs(value = { @WebServiceRef(type = String.class) })
35+
public class HasOtherAnnotations {
36+
4137
@Background
38+
@Addressing(responses = Responses.ALL)
39+
@Action(input = "someString")
4240
@SuppressWarnings(value = { "", "hi" })
43-
@Attribute(name = "2")
44-
@Nonnull(when = When.MAYBE)
45-
@Subscribe
46-
public void onEvent(@Nonnull(when = When.UNKNOWN) Event event) {
41+
public void onEvent(Event event) {
4742

4843
}
49-
50-
@Produce
51-
@Attribute(name = "2")
52-
public Event produceEvent() {
53-
return new Event();
54-
}
5544

45+
@Trace
5646
@Override
57-
public int describeContents() {
58-
return 0;
47+
public String toString() {
48+
return super.toString();
5949
}
6050

61-
@Override
62-
@Background
63-
public void writeToParcel(Parcel parcel, int i) {
64-
51+
protected static class Event {
6552
}
66-
67-
public static class Event {}
6853
}

‎AndroidAnnotations/androidannotations/src/test/java/org/androidannotations/utils/ProcessorTestHelper.java‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import static org.junit.Assert.assertEquals;
1919
import static org.junit.Assert.assertFalse;
20+
import static org.junit.Assert.assertTrue;
2021
import static org.junit.Assert.fail;
2122

2223
import java.io.BufferedReader;
@@ -28,6 +29,7 @@
2829
import java.util.ArrayList;
2930
import java.util.Arrays;
3031
import java.util.Collection;
32+
import java.util.Collections;
3133
import java.util.List;
3234

3335
import javax.annotation.processing.Processor;
@@ -77,6 +79,14 @@ public static void assertGeneratedClassDoesntMatches(File output, String value)
7779
}
7880
}
7981

82+
public static void assertGeneratedClassContains(File output, String[] codeFragment) {
83+
assertTrue("Code fragment \"" + join(codeFragment) + "\" should be in file " + output.getAbsolutePath(), Collections.indexOfSubList(Arrays.asList(getContents(output)), Arrays.asList(codeFragment)) != -1);
84+
}
85+
86+
public static void assertGeneratedClassDoesNotContain(File output, String[] codeFragment) {
87+
assertTrue("Code fragment \"" + join(codeFragment) + "\" should not be in file " + output.getAbsolutePath(), Collections.indexOfSubList(Arrays.asList(getContents(output)), Arrays.asList(codeFragment)) == -1);
88+
}
89+
8090
public static void assertOutput(File expectedResult, File output) {
8191
String[] expectedContent = getContents(expectedResult);
8292
String[] outputContent = getContents(output);
@@ -247,7 +257,7 @@ public String toPath(String packageName) {
247257
* <p>
248258
* The compilation units and all their dependencies are expected to be on
249259
* the classpath.
250-
*
260+
*
251261
* @param compilationUnits
252262
* the classes to compile
253263
* @return the {@link Diagnostic diagnostics} returned by the compilation,
@@ -421,4 +431,8 @@ private boolean isWindows() {
421431
return getOsName().startsWith("Windows");
422432
}
423433

434+
private static String join(String[] array) {
435+
return Arrays.toString(array).replaceAll(",", "\n");
436+
}
437+
424438
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
4+
Copyright (C) 2010-2014 eBusiness Information, Excilys Group
5+
6+
Licensed under the Apache License, Version 2.0 (the "License"); you may not
7+
use this file except in compliance with the License. You may obtain a copy of
8+
the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed To in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14+
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15+
License for the specific language governing permissions and limitations under
16+
the License.
17+
18+
-->
19+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
20+
package="org.androidannotations.testprocessor"
21+
android:versionCode="1"
22+
android:versionName="1.0" >
23+
24+
<application>
25+
</application>
26+
27+
</manifest>

‎AndroidAnnotations/functional-test-1-5/AndroidManifest.xml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,10 @@
8585
<activity android:name="org.androidannotations.test15.SeekBarChangeListenedActivity_" />
8686
<activity android:name="org.androidannotations.test15.AwaitingResultActivity_" />
8787
<activity android:name=".HierarchyViewerActivity_" />
88-
<activity android:name="org.androidannotations.test15.CustomTitleActivity_" />
88+
<activity android:name="org.androidannotations.test15.CustomTitleActivity_" android:theme="@android:style/Theme" />
8989
<activity android:name=".ActivityWithGenerics_" />
9090
<activity android:name=".WakeLockActivity_" />
91+
<activity android:name=".FragmentStartedActivity_" />
9192

9293
<receiver android:name="org.androidannotations.test15.ereceiver.MyReceiver_" />
9394

‎AndroidAnnotations/functional-test-1-5/pom.xml‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,6 @@
5151
<artifactId>ormlite-android</artifactId>
5252
<version>4.41</version>
5353
</dependency>
54-
<dependency>
55-
<groupId>com.google.code.findbugs</groupId>
56-
<artifactId>jsr305</artifactId>
57-
<version>1.3.9</version>
58-
</dependency>
5954
<dependency>
6055
<groupId>com.squareup</groupId>
6156
<artifactId>otto</artifactId>
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
4+
Copyright (C) 2010-2014 eBusiness Information, Excilys Group
5+
6+
Licensed under the Apache License, Version 2.0 (the "License"); you may not
7+
use this file except in compliance with the License. You may obtain a copy of
8+
the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed To in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14+
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15+
License for the specific language governing permissions and limitations under
16+
the License.
17+
18+
-->
19+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
20+
android:layout_width="fill_parent"
21+
android:layout_height="fill_parent"
22+
android:orientation="vertical" >
23+
24+
<CheckBox
25+
android:id="@+id/conventionButton"
26+
android:layout_width="fill_parent"
27+
android:layout_height="wrap_content" />
28+
29+
<CheckBox
30+
android:id="@+id/snake_case_button"
31+
android:layout_width="fill_parent"
32+
android:layout_height="wrap_content" />
33+
34+
<CheckBox
35+
android:id="@+id/extendedConventionButton"
36+
android:layout_width="fill_parent"
37+
android:layout_height="wrap_content" />
38+
39+
<CheckBox
40+
android:id="@+id/overridenConventionButton"
41+
android:layout_width="fill_parent"
42+
android:layout_height="wrap_content" />
43+
44+
<CheckBox
45+
android:id="@+id/configurationOverConventionButton"
46+
android:layout_width="fill_parent"
47+
android:layout_height="wrap_content" />
48+
49+
<CheckBox
50+
android:id="@+id/unboundButton"
51+
android:layout_width="fill_parent"
52+
android:layout_height="wrap_content" />
53+
54+
<CheckBox
55+
android:id="@+id/buttonWithViewArgument"
56+
android:layout_width="fill_parent"
57+
android:layout_height="wrap_content" />
58+
59+
<CheckBox
60+
android:id="@+id/buttonWithOnlyViewArgument"
61+
android:layout_width="fill_parent"
62+
android:layout_height="wrap_content" />
63+
64+
65+
<CheckBox
66+
android:id="@+id/button1"
67+
android:layout_width="fill_parent"
68+
android:layout_height="wrap_content" />
69+
70+
<CheckBox
71+
android:id="@+id/button2"
72+
android:layout_width="fill_parent"
73+
android:layout_height="wrap_content" />
74+
75+
<CheckBox
76+
android:id="@+id/stackOverflowProofButton"
77+
android:layout_width="fill_parent"
78+
android:layout_height="wrap_content" />
79+
80+
<CheckBox
81+
android:id="@+id/libResButton1"
82+
android:layout_width="fill_parent"
83+
android:layout_height="wrap_content" />
84+
85+
<CheckBox
86+
android:id="@+id/libResButton2"
87+
android:layout_width="fill_parent"
88+
android:layout_height="wrap_content" />
89+
90+
</LinearLayout>

‎AndroidAnnotations/functional-test-1-5/src/main/java/com/test/SimpleAnnotation.java‎

Lines changed: 0 additions & 20 deletions
This file was deleted.

‎AndroidAnnotations/functional-test-1-5/src/main/java/org/androidannotations/test15/AwaitingResultFragment.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package org.androidannotations.test15;
1717

18-
import android.app.Fragment;
18+
import android.support.v4.app.Fragment;
1919
import android.content.Intent;
2020
import android.net.Uri;
2121
import org.androidannotations.annotations.EFragment;
@@ -25,7 +25,7 @@
2525
@EFragment(R.layout.views_injected)
2626
public class AwaitingResultFragment extends Fragment {
2727

28-
private static final int FIRST_REQUEST = 11;
28+
static final int FIRST_REQUEST = 11;
2929
private static final int SECOND_REQUEST = 22;
3030
private static final int THIRD_REQUEST = 33;
3131
private static final int FORTH_REQUEST = 44;

0 commit comments

Comments
 (0)