package com.xtremelabs.robolectric.shadows;

import static com.xtremelabs.robolectric.Robolectric.shadowOf;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertThat;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.TabHost;

import com.xtremelabs.robolectric.R;
import com.xtremelabs.robolectric.WithTestDefaultsRunner;

@RunWith(WithTestDefaultsRunner.class)
public class TabSpecTest {
	Drawable icon1;
	Drawable icon2;
	@Before
	public void init() {
		 icon1 = new Drawable() {

				@Override
				public void draw(Canvas canvas) {
				}

				@Override
				public void setAlpha(int alpha) {
				}

				@Override
				public void setColorFilter(ColorFilter cf) {
				}

				@Override
				public int getOpacity() {
					return 1;
				}
	        
	        };
		 icon2 = new Drawable() {

			@Override
			public void draw(Canvas canvas) {
			}

			@Override
			public void setAlpha(int alpha) {
			}

			@Override
			public void setColorFilter(ColorFilter cf) {
			}

			@Override
			public int getOpacity() {
				return 2;
			}
		 
		 };
	}
	
    @Test
    public void shouldGetAndSetTheIndicator() throws Exception {
        TabHost.TabSpec spec = new TabHost(null).newTabSpec("foo");
        View view = new View(null);
        TabHost.TabSpec self = spec.setIndicator(view);
        assertThat(self, is(spec));
        assertThat(shadowOf(spec).getIndicatorAsView(), is(view));
    }

    @Test
    public void shouldGetAndSetTheIntentContent() throws Exception {
        TabHost.TabSpec spec = new TabHost(null).newTabSpec("foo");
        Intent intent = new Intent();
        TabHost.TabSpec self = spec.setContent(intent);
        assertThat(self, is(spec));
        assertThat(shadowOf(spec).getContentAsIntent(), is(intent));
    }
    
    @Test
    public void shouldGetAndSetTheIndicatorLabel() throws Exception {
        TabHost.TabSpec spec = new TabHost(null).newTabSpec("foo")
        .setContent(R.layout.main).setIndicator("labelText");

        assertThat(shadowOf(spec).getIndicatorLabel(), is("labelText"));
        assertThat(shadowOf(spec).getText(), is("labelText"));
    }
    @Test
    public void shouldGetAndSetTheIndicatorLabelAndIcon() throws Exception {
        TabHost.TabSpec spec = new TabHost(null).newTabSpec("foo")
        .setContent(R.layout.main).setIndicator("labelText",icon1);

        assertThat(shadowOf(spec).getIndicatorLabel(), is("labelText"));
        assertThat(shadowOf(spec).getText(), is("labelText"));
        assertThat(shadowOf(spec).getIndicatorIcon(), is(icon1));
        assertThat(shadowOf(spec).getIndicatorIcon(), is(not(icon2)));
    }
}

@@ -696,23 +696,9 @@
 1;%0A%09
-Drawable icon2;
+%09
 %0A%09@B
@@ -744,575 +744,22 @@
 new 
-Drawable() %7B%0A%0A%09%09%09%09@Override%0A%09%09%09%09public void draw(Canvas canvas) %7B%0A%09%09%09%09%7D%0A%0A%09%09%09%09@Override%0A%09%09%09%09public void setAlpha(int alpha) %7B%0A%09%09%09%09%7D%0A%0A%09%09%09%09@Override%0A%09%09%09%09public void setColorFilter(ColorFilter cf) %7B%0A%09%09%09%09%7D%0A%0A%09%09%09%09@Override%0A%09%09%09%09public int getOpacity() %7B%0A%09%09%09%09%09return 1;%0A%09%09%09%09%7D%0A%09        %0A%09        %7D;%0A%09%09 icon2 = new Drawable() %7B%0A%0A%09%09%09@Override%0A%09%09%09public void draw(Canvas canvas) %7B%0A%09%09%09%7D%0A%0A%09%09%09@Override%0A%09%09%09public void setAlpha(int alpha) %7B%0A%09%09%09%7D%0A%0A%09%09%09@Override%0A%09%09%09public void setColorFilter(ColorFilter cf) %7B%0A%09%09%09%7D%0A%0A%09%09%09@Override%0A%09%09%09public int getOpacity() %7B%0A%09%09%09%09return 2;%0A%09%09%09%7D%0A%09%09 %0A%09%09 %7D;
+TestIcon();%09%09 
 %0A%09%7D%0A
@@ -2247,79 +2247,294 @@
     
+%7D%0A
     
-assertThat(shadowOf(spec).getIndicatorIcon(), is(not(icon2)));%0A    %7D
+%0A    private class TestIcon extends Drawable %7B%0A%0A%09%09@Override%0A%09%09public void draw(Canvas canvas) %7B%0A%09%09%7D%0A%0A%09%09@Override%0A%09%09public void setAlpha(int alpha) %7B%0A%09%09%7D%0A%0A%09%09@Override%0A%09%09public void setColorFilter(ColorFilter cf) %7B%0A%09%09%7D%0A%0A%09%09@Override%0A%09%09public int getOpacity() %7B%0A%09%09%09return 0;%0A%09%09%7D%0A%09%09%0A%09%7D%0A
 %0A%7D%0A

edit TabSpecTest.shouldGetAndSetTheIndicatorLabelAndIcon On branch ShadowTabActivityFix modified: src/test/java/com/xtremelabs/robolectric/shadows/TabSpecTest.java