Skip to content

Commit

Permalink
merged upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
mosabua committed Oct 30, 2011
2 parents 801559f + 799a4ec commit 04689bc
Show file tree
Hide file tree
Showing 20 changed files with 210 additions and 26 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ temp.json
temp.xml
temp.txt
tmp/
target/
target/
.idea
2 changes: 1 addition & 1 deletion AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@

<uses-permission android:name="android.permission.INTERNET"/>
<uses-sdk android:minSdkVersion="3"/>
<uses-sdk android:targetSdkVersion="9"/>
<uses-sdk android:targetSdkVersion="10"/>
</manifest>
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ To build and run tests:
mvn clean test

To install the sample app on the emulator:
mvn android:deploy
mvn package android:deploy


BUILDING WITH ANT
Expand Down
2 changes: 1 addition & 1 deletion default.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
# project structure.

# Project target.
target=Google Inc.:Google APIs:9
target=Google Inc.:Google APIs:10
Binary file removed lib/main/roboguice-1.0.jar
Binary file not shown.
Binary file added lib/main/roboguice-1.1.jar
Binary file not shown.
Binary file removed lib/test/roboguice-1.0-sources.jar
Binary file not shown.
Binary file added lib/test/roboguice-1.1-sources.jar
Binary file not shown.
Binary file not shown.
101 changes: 89 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>5</version>
</parent>

<groupId>com.pivotallabs</groupId>
<artifactId>RobolectricSample</artifactId>
<artifactId>robolectricsample</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>apk</packaging>
<name>RobolectricSample app</name>
<description>Sample project demonstrating use of the Robolectric Android testing project.</description>
<url>https://github.com/pivotal/RobolectricSample</url>

<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>2.2.1</version>
<version>2.3.3</version>
<scope>provided</scope>
</dependency>

Expand All @@ -30,14 +39,8 @@
<dependency>
<groupId>com.pivotallabs</groupId>
<artifactId>robolectric</artifactId>
<version>0.9.8</version>
<version>1.0</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
Expand Down Expand Up @@ -70,13 +73,16 @@
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>maven-android-plugin</artifactId>
<version>2.8.4</version>
<version>2.8.3</version>
<configuration>
<sdk>
<platform>8</platform>
<!-- platform or api level (api level 4 = platform 1.6)-->
<platform>10</platform>
<!--<path></path>-->
</sdk>
<emulator>
<avd>22</avd>
<!-- the name of the avd device to use for starting the emulator -->
<avd>16</avd>
</emulator>
<deleteConflictingFiles>true</deleteConflictingFiles>
<undeployBeforeDeploy>true</undeployBeforeDeploy>
Expand All @@ -95,4 +101,75 @@
</plugin>
</plugins>
</build>

<scm>
<url>git@github.com:pivotal/RobolectricSample.git</url>
<connection>scm:git:git://github.com/pivotal/RobolectricSample.git</connection>
<developerConnection>scm:git:git@github.com:pivotal/RobolectricSample.git</developerConnection>
</scm>

<developers>
<developer>
<id>tyler</id>
<name>Tyler Schultz</name>
<email>tyler@pivotallabs.com</email>
<organization>Pivotal Labs</organization>
<organizationUrl>http://pivotallabs.com/</organizationUrl>
<roles>
<role>Project Owner</role>
<role>Developer</role>
</roles>
<timezone>PST/PDT</timezone>
</developer>
<developer>
<id>phil</id>
<name>Phil Goodwin</name>
<email>phil@pivotallabs.com</email>
<organization>Pivotal Labs</organization>
<organizationUrl>http://pivotallabs.com/</organizationUrl>
<roles>
<role>Developer</role>
</roles>
<timezone>PST/PDT</timezone>
</developer>
<developer>
<id>joemoore</id>
<name>Joe Moore</name>
<email>joe@pivotallabs.com</email>
<organization>Pivotal Labs</organization>
<organizationUrl>http://pivotallabs.com/</organizationUrl>
<roles>
<role>Developer</role>
</roles>
<timezone>EST/EDT</timezone>
</developer>
</developers>
<licenses>
<license>
<name>MIT license</name>
<comments>
The MIT License

Copyright (c) 2011 Pivotal Labs

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
</comments>
</license>
</licenses>
</project>
10 changes: 8 additions & 2 deletions proguard.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,26 @@
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService

-keepclasseswithmembernames class * {
native <methods>;
}

-keepclasseswithmembernames class * {
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembernames class * {
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}

-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
Expand Down
22 changes: 22 additions & 0 deletions res/layout/loading_text.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>

<com.pivotallabs.views.LoadingTextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>

<include
android:id="@+id/loading_text_spinner"
layout="@layout/loading_view"
android:visibility="visible"
/>

<TextView
android:id="@+id/loading_text_text_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="invisible"
/>

</com.pivotallabs.views.LoadingTextView>
1 change: 1 addition & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
<string name="recent_activity">Recent Activity</string>
<string name="injected_activity">Roboguice Injected Activity</string>
<string name="injected_activity_caption">Roboguice Activity tested with Robolectric</string>
<string name="unit_tests_ftw">Unit Tests FTW!!!</string>
</resources>
2 changes: 1 addition & 1 deletion src/main/java/com/pivotallabs/api/Http.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private DefaultHttpClient getPromiscuousDefaultClient() {
}

public static class Response {
private static final int BUFFER_SIZE = 2 ^ 12;
private static final int BUFFER_SIZE = 4096;
private int statusCode;
private String responseBody;

Expand Down
30 changes: 30 additions & 0 deletions src/main/java/com/pivotallabs/views/LoadingTextView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.pivotallabs.views;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.pivotallabs.R;

public class LoadingTextView extends RelativeLayout {
public LoadingTextView(Context context) {
super(context);
}

public LoadingTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}

public LoadingTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}

public void stopLoadingAndSetText(int text_res_id) {
TextView textView = (TextView) findViewById(R.id.loading_text_text_view);
textView.setText(text_res_id);
textView.setVisibility(View.VISIBLE);

findViewById(R.id.loading_text_spinner).setVisibility(View.GONE);
}
}
2 changes: 1 addition & 1 deletion src/test/java/com/pivotallabs/api/ApiGatewayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.xtremelabs.robolectric.Robolectric;
import com.xtremelabs.robolectric.RobolectricTestRunner;
import com.xtremelabs.robolectric.util.HttpRequestInfo;
import com.xtremelabs.robolectric.tester.org.apache.http.HttpRequestInfo;
import org.apache.http.HttpRequest;
import org.apache.http.auth.AuthScope;
import org.apache.http.client.CredentialsProvider;
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/pivotallabs/api/HttpTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.google.inject.internal.Maps;
import com.xtremelabs.robolectric.Robolectric;
import com.xtremelabs.robolectric.RobolectricTestRunner;
import com.xtremelabs.robolectric.util.HttpRequestInfo;
import com.xtremelabs.robolectric.tester.org.apache.http.HttpRequestInfo;
import com.xtremelabs.robolectric.util.Strings;
import org.apache.http.HttpRequest;
import org.apache.http.auth.AuthScope;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import com.pivotallabs.api.ApiRequest;
import com.pivotallabs.api.TestApiGateway;
import com.xtremelabs.robolectric.RobolectricTestRunner;
import com.xtremelabs.robolectric.view.TestMenu;
import com.xtremelabs.robolectric.view.TestMenuItem;
import com.xtremelabs.robolectric.tester.android.view.TestMenu;
import com.xtremelabs.robolectric.tester.android.view.TestMenuItem;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down
7 changes: 4 additions & 3 deletions src/test/java/com/pivotallabs/tracker/SignInDialogTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.junit.runner.RunWith;

import static com.xtremelabs.robolectric.Robolectric.clickOn;
import static com.xtremelabs.robolectric.Robolectric.shadowOf;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
Expand Down Expand Up @@ -120,10 +121,10 @@ public void shouldShowAlertDialogWhenUnSuccessfullySignedIn() throws Exception {

apiGateway.simulateResponse(401, "Access Denied");

ShadowAlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog();
AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog();
assertThat(alertDialog.isShowing(), equalTo(true));
assertThat(alertDialog.getTitle(), equalTo("Error"));
assertThat(alertDialog.getMessage(), equalTo("Username/Password combination is not recognized."));
assertThat(((String) shadowOf(alertDialog).getTitle()), equalTo("Error"));
assertThat(((String) shadowOf(alertDialog).getMessage()), equalTo("Username/Password combination is not recognized."));
assertNotNull(alertDialog.getButton(AlertDialog.BUTTON_POSITIVE));
}

Expand Down
46 changes: 46 additions & 0 deletions src/test/java/com/pivotallabs/views/LoadingTextViewTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.pivotallabs.views;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import com.pivotallabs.R;
import com.xtremelabs.robolectric.RobolectricTestRunner;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;

@RunWith(RobolectricTestRunner.class)
public class LoadingTextViewTest {
private LoadingTextView loadingTextView;
private View loadingSpinner;
private TextView loadingTextTextView;

@Before
public void setUp() throws Exception {
loadingTextView = (LoadingTextView) LayoutInflater.from(new Activity()).inflate(R.layout.loading_text, null);
loadingSpinner = loadingTextView.findViewById(R.id.loading_text_spinner);
loadingTextTextView = (TextView) loadingTextView.findViewById(R.id.loading_text_text_view);
}

@Test
public void testStopLoadingAndSetTextShouldHideTheSpinnerAndShowTheTextView() throws Exception {
assertThat(loadingSpinner.getVisibility(), equalTo(View.VISIBLE));
assertThat(loadingTextTextView.getVisibility(), equalTo(View.INVISIBLE));

loadingTextView.stopLoadingAndSetText(R.string.unit_tests_ftw);

assertThat(loadingSpinner.getVisibility(), equalTo(View.GONE));
assertThat(loadingTextTextView.getVisibility(), equalTo(View.VISIBLE));
}

@Test
public void testStopLoadingAndSEtTextShouldSetTheTextOnTheTextView() {
loadingTextView.stopLoadingAndSetText(R.string.unit_tests_ftw);

assertThat((String) loadingTextTextView.getText(), equalTo("Unit Tests FTW!!!"));
}
}

0 comments on commit 04689bc

Please sign in to comment.