Permalink
Browse files

Add initial robolectric test for Toaster helper

  • Loading branch information...
1 parent 6fb01d1 commit d479330771aa5d6671a5b9e33aa946e07001f55c @kevinsawicki committed Aug 28, 2012
View
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="src" path="src/test/java"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
View
@@ -1,5 +1,8 @@
<?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">
+<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>
@@ -56,6 +59,20 @@
<version>4.0.1.2</version>
<scope>provided</scope>
</dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.10</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>com.pivotallabs</groupId>
+ <artifactId>robolectric</artifactId>
+ <version>1.1</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+ <string name="lib_name">wishlist</string>
+
+</resources>
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2012 Kevin Sawicki <kevinsawicki@gmail.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.github.kevinsawicki.wishlist;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import android.app.Activity;
+
+import com.xtremelabs.robolectric.RobolectricTestRunner;
+import com.xtremelabs.robolectric.shadows.ShadowToast;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * Tests of {@link Toaster} helper
+ */
+@RunWith(RobolectricTestRunner.class)
+public class ToasterTest {
+
+ /**
+ * Setup tests
+ */
+ @Before
+ public void setup() {
+ ShadowToast.reset();
+ assertNull(ShadowToast.getLatestToast());
+ }
+
+ /**
+ * Call Toaster with no activity
+ */
+ @Test
+ public void noActivity() {
+ Toaster.showLong(null, "toast");
+ assertNull(ShadowToast.getLatestToast());
+ Toaster.showShort(null, "toast");
+ assertNull(ShadowToast.getLatestToast());
+ }
+
+ /**
+ * Call Toaster with valid activity and message
+ */
+ @Test
+ public void toastText() {
+ Toaster.showLong(new Activity(), "toast1");
+ assertEquals("toast1", ShadowToast.getTextOfLatestToast());
+ Toaster.showShort(new Activity(), "toast2");
+ assertEquals("toast2", ShadowToast.getTextOfLatestToast());
+ }
+}

0 comments on commit d479330

Please sign in to comment.