Skip to content

Commit

Permalink
added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tmtron committed Sep 25, 2016
1 parent 08395ca commit 6e586f6
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 16 deletions.
1 change: 1 addition & 0 deletions green-annotations-test/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
tools:ignore="all">

<activity android:name=".GreenEventBusActivity_" />
<activity android:name=".ActivityAfter_" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright © 2016 Martin Trummer ([email protected])
*
* 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();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright © 2016 Martin Trummer ([email protected])
*
* 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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright © 2016 Martin Trummer ([email protected])
*
* 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);
}

}
16 changes: 0 additions & 16 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -351,16 +351,6 @@
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<mavenExecutorId>forked-path</mavenExecutorId>
<tagNameFormat>v@{project.version}</tagNameFormat>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
Expand Down Expand Up @@ -399,8 +389,6 @@
<!--
just use /* not /**
see: http://code.mycila.com/license-maven-plugin/
see: http://code.mycila.com/license-maven-plugin/
see: http://code.mycila.com/license-maven-plugin/
-->
<java>SLASHSTAR_STYLE</java>
<xml>idea_xml_style</xml>
Expand Down Expand Up @@ -429,10 +417,6 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
Expand Down

0 comments on commit 6e586f6

Please sign in to comment.