diff --git a/green-annotations-test/src/main/AndroidManifest.xml b/green-annotations-test/src/main/AndroidManifest.xml index d60e264..20b197b 100644 --- a/green-annotations-test/src/main/AndroidManifest.xml +++ b/green-annotations-test/src/main/AndroidManifest.xml @@ -31,6 +31,7 @@ tools:ignore="all"> + diff --git a/green-annotations-test/src/main/java/com/tmtron/greenannotations/test/ActivityBefore.java b/green-annotations-test/src/main/java/com/tmtron/greenannotations/test/ActivityBefore.java new file mode 100644 index 0000000..b35a7a6 --- /dev/null +++ b/green-annotations-test/src/main/java/com/tmtron/greenannotations/test/ActivityBefore.java @@ -0,0 +1,60 @@ +/* + * Copyright © 2016 Martin Trummer (martin.trummer@tmtron.com) + * + * 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.tmtron.greenannotations.test; + +import android.app.Activity; +import android.os.Bundle; +import android.widget.Toast; +import org.greenrobot.eventbus.EventBus; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; + +/** + * test class to show how to use EventBus without GreenAnnotations + */ +public class ActivityBefore extends Activity { + + EventBus eventBus; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + eventBus = EventBus.getDefault(); + } + + @Override + public void onStart() { + super.onStart(); + eventBus.register(this); + } + + @Override + public void onStop() { + eventBus.unregister(this); + super.onStop(); + } + + void fireEvent(String message) { + eventBus.post(new MessageEvent(message)); + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onMessageEvent(MessageEvent event) { + Toast.makeText(getApplicationContext(), event.message, Toast.LENGTH_SHORT).show(); + } + +} diff --git a/green-annotations-test/src/main/java/com/tmtron/greenannotations/test/MessageEvent.java b/green-annotations-test/src/main/java/com/tmtron/greenannotations/test/MessageEvent.java new file mode 100644 index 0000000..e8bdcf5 --- /dev/null +++ b/green-annotations-test/src/main/java/com/tmtron/greenannotations/test/MessageEvent.java @@ -0,0 +1,27 @@ +/* + * Copyright © 2016 Martin Trummer (martin.trummer@tmtron.com) + * + * 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.tmtron.greenannotations.test; + + +class MessageEvent { + + final String message; + + MessageEvent(String message) { + this.message = message; + } +} \ No newline at end of file diff --git a/green-annotations-test/src/test/java/com/tmtron/greenannotations/test/GreenEventBusDocTest.java b/green-annotations-test/src/test/java/com/tmtron/greenannotations/test/GreenEventBusDocTest.java new file mode 100644 index 0000000..129ee82 --- /dev/null +++ b/green-annotations-test/src/test/java/com/tmtron/greenannotations/test/GreenEventBusDocTest.java @@ -0,0 +1,55 @@ +/* + * Copyright © 2016 Martin Trummer (martin.trummer@tmtron.com) + * + * 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.tmtron.greenannotations.test; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.Robolectric; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.shadows.ShadowHandler; +import org.robolectric.shadows.ShadowToast; + +import static org.fest.assertions.api.Assertions.assertThat; + +@RunWith(RobolectricTestRunner.class) +public class GreenEventBusDocTest { + + private static final String EXPECTED_MESSAGE = "Activity toast"; + + @Test + public void testActivityBefore() { + ActivityBefore activity = Robolectric.setupActivity(ActivityBefore.class); + + assertThat(activity.eventBus).isNotNull(); + activity.fireEvent(EXPECTED_MESSAGE); + + ShadowHandler.idleMainLooper(); + assertThat(ShadowToast.getTextOfLatestToast()).isEqualTo(EXPECTED_MESSAGE); + } + + @Test + public void testActivityAfter() { + ActivityAfter activity = Robolectric.setupActivity(ActivityAfter_.class); + + assertThat(activity.eventBus).isNotNull(); + activity.fireEvent(EXPECTED_MESSAGE); + + ShadowHandler.idleMainLooper(); + assertThat(ShadowToast.getTextOfLatestToast()).isEqualTo(EXPECTED_MESSAGE); + } + +} diff --git a/pom.xml b/pom.xml index 9b3eecf..fd3f6cd 100644 --- a/pom.xml +++ b/pom.xml @@ -351,16 +351,6 @@ - - org.apache.maven.plugins - maven-release-plugin - 2.5.3 - - forked-path - v@{project.version} - - - org.apache.maven.plugins maven-deploy-plugin @@ -399,8 +389,6 @@ SLASHSTAR_STYLE idea_xml_style @@ -429,10 +417,6 @@ org.apache.maven.plugins maven-gpg-plugin - - org.apache.maven.plugins - maven-release-plugin - org.apache.maven.plugins maven-deploy-plugin