Skip to content

Commit

Permalink
Fix test suite for Robolectric 3.1
Browse files Browse the repository at this point in the history
Add a workaround until Robolectlectric is not fixed.
robolectric/robolectric#2562 (comment)
  • Loading branch information
WonderCsabo committed Dec 10, 2016
1 parent c4fb4b5 commit 0a970eb
Show file tree
Hide file tree
Showing 17 changed files with 46 additions and 27 deletions.
Expand Up @@ -67,6 +67,10 @@
<version>${robolectric.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.robolectric</groupId>
<artifactId>android-all</artifactId>
</dependency>
<dependency>
<groupId>org.easytesting</groupId>
<artifactId>fest-reflect</artifactId>
Expand Down
Empty file.
Expand Up @@ -39,14 +39,14 @@ public void setUp() {
@Test
public void injectionOfHtmlTest() {
assertNotNull(activity.textView);
assertEquals(Html.fromHtml(activity.getString(R.string.hello_html)),
activity.textView.getText());
assertEquals(Html.fromHtml(activity.getString(R.string.hello_html)).toString(),
activity.textView.getText().toString());
}

@Test
public void injectionOfHtmlWithDefaultName() {
assertNotNull(activity.someView);
assertEquals(Html.fromHtml(activity.getString(R.string.someView)),
activity.someView.getText());
assertEquals(Html.fromHtml(activity.getString(R.string.someView)).toString(),
activity.someView.getText().toString());
}
}
Empty file.
Expand Up @@ -16,6 +16,7 @@
package org.androidannotations.test.ebean;

import static org.fest.assertions.api.Assertions.assertThat;
import static org.robolectric.Robolectric.setupActivity;

import org.androidannotations.test.EmptyActivityWithoutLayout_;
import org.junit.Test;
Expand All @@ -27,7 +28,7 @@ public class CyclicSingletonTest {

@Test
public void cyclicSingleton() {
EmptyActivityWithoutLayout_ context = new EmptyActivityWithoutLayout_();
EmptyActivityWithoutLayout_ context = setupActivity(EmptyActivityWithoutLayout_.class);
SomeCyclicSingletonA_ singletonA = SomeCyclicSingletonA_.getInstance_(context);
SomeCyclicSingletonB_ singletonB = SomeCyclicSingletonB_.getInstance_(context);
assertThat(singletonA.singletonB).isSameAs(singletonB);
Expand Down
Expand Up @@ -17,6 +17,7 @@

import static org.fest.assertions.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.robolectric.Robolectric.setupActivity;

import java.lang.reflect.Field;

Expand All @@ -41,7 +42,7 @@ public void setUp() throws Exception {

@Test
public void getInstanceReturnsSameInstance() {
EmptyActivityWithoutLayout_ context = new EmptyActivityWithoutLayout_();
EmptyActivityWithoutLayout_ context = setupActivity(EmptyActivityWithoutLayout_.class);
SomeSingleton_ firstInstance = SomeSingleton_.getInstance_(context);
SomeSingleton_ secondInstance = SomeSingleton_.getInstance_(context);
assertThat(firstInstance).isSameAs(secondInstance);
Expand Down
Expand Up @@ -16,6 +16,7 @@
package org.androidannotations.test.eintentservice;

import static org.fest.assertions.api.Assertions.assertThat;
import static org.robolectric.Robolectric.setupActivity;

import org.androidannotations.test.EmptyActivityWithoutLayout;
import org.androidannotations.test.EmptyActivityWithoutLayout_;
Expand All @@ -33,7 +34,7 @@ public void testAction() {
IntentServiceHandledAction.actionForTestHandled = null;

// Simulate call to intent builder and retrieve the configured Intent
EmptyActivityWithoutLayout context = new EmptyActivityWithoutLayout_();
EmptyActivityWithoutLayout context = setupActivity(EmptyActivityWithoutLayout_.class);
Intent intent = IntentServiceHandledAction_.intent(context) //
.myActionOneParam("test") //
.get();
Expand Down
Expand Up @@ -92,7 +92,7 @@ public void onIntentParametersActionTest() {
Intent extraIntent = new Intent("someAction");
intent.putExtra("extraIntent", extraIntent);

receiver.onReceive(Robolectric.application, intent);
receiver.onReceive(RuntimeEnvironment.application, intent);

assertEquals(intent, receiver.originalIntent);
assertEquals(extraIntent, receiver.extraIntent);
Expand Down
Expand Up @@ -22,6 +22,7 @@
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;

import android.content.Intent;
import android.support.v4.content.LocalBroadcastManager;
Expand Down Expand Up @@ -64,7 +65,7 @@ public void eViewAndEViewGroupReceivedAction2WithExtraTest() {
Intent extraIntent = new Intent("someAction");
intent.putExtra("extra", extraIntent);

LocalBroadcastManager.getInstance(Robolectric.application).sendBroadcast(intent);
LocalBroadcastManager.getInstance(RuntimeEnvironment.application).sendBroadcast(intent);

assertTrue(activity.viewWithReceiver.action2Received);
assertTrue(activity.viewWithReceiver.action2Extra.equals(extraIntent));
Expand Down
Expand Up @@ -111,12 +111,12 @@ public void htmlInjectedNotNull() {

@Test
public void htmlResCorrectlySet() {
assertEquals(Html.fromHtml(activity.getString(R.string.hello_html)), activity.helloHtml);
assertEquals(Html.fromHtml(activity.getString(R.string.hello_html)).toString(), activity.helloHtml.toString());
}

@Test
public void htmlInjectedCorrectlySet() {
assertEquals(Html.fromHtml(activity.getString(R.string.hello_html)), activity.htmlInjected);
assertEquals(Html.fromHtml(activity.getString(R.string.hello_html)).toString(), activity.htmlInjected.toString());
}

@Test
Expand Down
Empty file.
Expand Up @@ -68,6 +68,10 @@
<groupId>org.robolectric</groupId>
<artifactId>robolectric</artifactId>
</dependency>
<dependency>
<groupId>org.robolectric</groupId>
<artifactId>android-all</artifactId>
</dependency>
<dependency>
<groupId>com.squareup</groupId>
<artifactId>fest-android</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions AndroidAnnotations/androidannotations-otto/otto-test/pom.xml
Expand Up @@ -63,6 +63,10 @@
<groupId>org.robolectric</groupId>
<artifactId>robolectric</artifactId>
</dependency>
<dependency>
<groupId>org.robolectric</groupId>
<artifactId>android-all</artifactId>
</dependency>
<dependency>
<groupId>com.squareup</groupId>
<artifactId>fest-android</artifactId>
Expand Down
Expand Up @@ -99,6 +99,10 @@
<version>${robolectric.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.robolectric</groupId>
<artifactId>android-all</artifactId>
</dependency>
<dependency>
<groupId>com.squareup</groupId>
<artifactId>fest-android</artifactId>
Expand Down
Expand Up @@ -19,25 +19,25 @@

import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.springframework.web.client.ResponseErrorHandler;

@RunWith(RobolectricTestRunner.class)
public class RestResponseErrorHandlerTest {

@Test
public void testSameAsSingletonBeanResponseErrorHandler() {
RestWithSingletonBeanResponseErrorHandler restClient = new RestWithSingletonBeanResponseErrorHandler_(Robolectric.application);
RestWithSingletonBeanResponseErrorHandler restClient = new RestWithSingletonBeanResponseErrorHandler_(RuntimeEnvironment.application);
ResponseErrorHandler errorHandler = restClient.getRestTemplate().getErrorHandler();
MyResponseErrorHandlerBean errorHandlerBean = MyResponseErrorHandlerBean_.getInstance_(Robolectric.application);
MyResponseErrorHandlerBean errorHandlerBean = MyResponseErrorHandlerBean_.getInstance_(RuntimeEnvironment.application);

assertThat(errorHandler).isSameAs(errorHandlerBean);
}

@Test
public void testInstanceCreatedFromNonBeanClassAsResponseErrorHandler() {
new RestWithSimpleClassResponseErrorHandler_(Robolectric.application);
new RestWithSimpleClassResponseErrorHandler_(RuntimeEnvironment.application);

assertThat(MyResponseErrorHandler.instanceCreated).isTrue();
}
Expand Down
Expand Up @@ -68,6 +68,10 @@
<groupId>org.robolectric</groupId>
<artifactId>robolectric</artifactId>
</dependency>
<dependency>
<groupId>org.robolectric</groupId>
<artifactId>android-all</artifactId>
</dependency>
<dependency>
<groupId>com.squareup</groupId>
<artifactId>fest-android</artifactId>
Expand Down
19 changes: 7 additions & 12 deletions AndroidAnnotations/pom.xml
Expand Up @@ -131,25 +131,14 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<main.basedir>${project.basedir}</main.basedir>
<robolectric.version>3.1-SNAPSHOT</robolectric.version> <!-- TODO 3.1-->
<robolectric.version>3.1.4</robolectric.version>
</properties>


<prerequisites>
<maven>3.2.1</maven>
</prerequisites>

<repositories> <!-- TODO remove-->
<repository>
<id>oss-sonatype</id>
<name>oss-sonatype</name>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>

<modules>
<module>androidannotations-core</module>
<module>androidannotations-ormlite</module>
Expand Down Expand Up @@ -200,6 +189,12 @@
<version>${robolectric.version}</version>
<scope>test</scope>
</dependency>
<dependency> <!-- TODO https://github.com/robolectric/robolectric/issues/2562#issuecomment-263086503 -->
<groupId>org.robolectric</groupId>
<artifactId>android-all</artifactId>
<version>6.0.0_r1-robolectric-0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup</groupId>
<artifactId>fest-android</artifactId>
Expand Down

0 comments on commit 0a970eb

Please sign in to comment.