package com.seadowg.loafers.test;

import android.app.Activity;
import android.app.AlertDialog;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import com.seadowg.loafers.app.App;
import com.seadowg.loafers.collection.List;
import com.seadowg.loafers.widget.Button;
import com.seadowg.loafers.widget.Input;
import com.seadowg.loafers.widget.Popup;
import junit.framework.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowDialog;

import static junit.framework.Assert.assertNotNull;
import static org.junit.Assert.assertEquals;
import static org.robolectric.Robolectric.shadowOf;

@RunWith(RobolectricTestRunner.class) @Config(manifest=Config.NONE)
public class ConceptTest {
  @Test
  public void buildingAMagic8Ball_works() throws Exception {
    Activity app = Robolectric.buildActivity(MyApp.class).create().start().resume().get();

    assertEquals(app.getTitle(), "Magic 8-Ball");

    FrameLayout rootView = (FrameLayout) app.getWindow().getDecorView().getRootView();
    LinearLayout rootLayout = (LinearLayout) rootView.getChildAt(0);
    LinearLayout layout = ((LinearLayout) ((FrameLayout) rootLayout.getChildAt(2)).getChildAt(0));

    android.widget.EditText editText = (EditText) layout.getChildAt(0);
    android.widget.Button button = (android.widget.Button) layout.getChildAt(1);

    assertEquals("", editText.getText().toString());
    assertEquals("Shake", button.getText());

    button.performClick();
    AlertDialog popup = (AlertDialog) ShadowDialog.getLatestDialog();
    assertEquals("Yes!", shadowOf(popup).getTitle());
  }

  private static class MyApp extends App {
    public void open() {
      title = "Magic 8-Ball";

      new Input();
      new Button("Shake") {
        public void click() {
          String answer = new List("Yes!").chooseOne();
          new Popup(answer).show();
        }
      };
    }
  }
}
@@ -400,39 +400,8 @@
 up;%0A
-import junit.framework.Assert;%0A
 impo
@@ -613,23 +613,99 @@
 s.Shadow
+Alert
 Dialog;
+%0Aimport org.robolectric.shadows.ShadowDialog;%0A%0Aimport java.util.Arrays;
 %0A%0Aimport
@@ -745,15 +745,12 @@
 sert
-NotNull
+True
 ;%0Aim
@@ -1692,16 +1692,22 @@
 ();%0A    
+Shadow
 AlertDia
@@ -1718,16 +1718,26 @@
 popup = 
+(shadowOf(
 (AlertDi
@@ -1772,16 +1772,18 @@
 Dialog()
+))
 ;%0A    as
@@ -1790,38 +1790,66 @@
 sert
-Equals(%22Yes!%22, shadowOf
+True(Arrays.asList(%22Yes!%22, %22No!%22, %22Maybe?%22).contains
 (popup
-)
 .get
@@ -1856,16 +1856,17 @@
 Title())
+)
 ;%0A  %7D%0A%0A 
@@ -2081,16 +2081,33 @@
 t(%22Yes!%22
+, %22No!%22, %22Maybe?%22
 ).choose

Test chooseOne() properly