package no.ntnu.capgeminitest.binding.android.propertyprovider;

import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;

import no.ntnu.capgeminitest.data.Property;

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

import com.xtremelabs.robolectric.RobolectricTestRunner;

@RunWith(RobolectricTestRunner.class)
public class PropertyProviderStackTest {
    
    public class FakePropertyProvider implements PropertyProvider {
        public String bindingName;
        public Property<?> property;
        
        public FakePropertyProvider(String bindingName, Property<?> property) {
            this.bindingName = bindingName;
            this.property = property;
        }
        
        @Override
        public Property<?> getProperty(String bindingName) {
            if (bindingName.equals(this.bindingName)) {
                return property;
            } else {
                return null;
            }
        }
    }
    
    private PropertyProviderStack stack = new PropertyProviderStack();
    private FakePropertyProvider pp1 = new FakePropertyProvider(
            "bindingName1", new Property<String>("property1"));
    private FakePropertyProvider pp2 = new FakePropertyProvider(
            "bindingName1", new Property<String>("property2"));
    private FakePropertyProvider pp3 = new FakePropertyProvider(
            "bindingName2", new Property<String>("property3"));
    
    @Test
    public void testSingleProvider() {
        stack.addProvider(pp1);
        assertThat((String)stack.getProperty("bindingName1").get(), equalTo("property1"));
    }
    
    @Test
    public void testProviderOverride1() {
        stack.addProvider(pp1);
        stack.addProvider(pp2);
        assertThat((String)stack.getProperty("bindingName1").get(), equalTo("property1"));
    }
    
    @Test
    public void testProviderOverride2() {
        stack.addProvider(pp2);
        stack.addProvider(pp1);
        assertThat((String)stack.getProperty("bindingName1").get(), equalTo("property2"));
    }
    
    @Test
    public void testMultipleBindingNames() {
        stack.addProvider(pp1);
        stack.addProvider(pp2);
        stack.addProvider(pp3);
        assertThat((String)stack.getProperty("bindingName1").get(), equalTo("property1"));
        assertThat((String)stack.getProperty("bindingName2").get(), equalTo("property3"));
    }
}

@@ -238,16 +238,43 @@
 nWith;%0A%0A
+import android.view.View;%0A%0A
 import c
@@ -322,16 +322,16 @@
 Runner;%0A
-
 %0A@RunWit
@@ -785,16 +785,21 @@
 y%3C?%3E get
+Bound
 Property
@@ -799,16 +799,29 @@
 roperty(
+View unused, 
 String b
@@ -1580,32 +1580,37 @@
 String)stack.get
+Bound
 Property(%22bindin
@@ -1594,32 +1594,38 @@
 etBoundProperty(
+null, 
 %22bindingName1%22).
@@ -1809,32 +1809,37 @@
 String)stack.get
+Bound
 Property(%22bindin
@@ -1823,32 +1823,38 @@
 etBoundProperty(
+null, 
 %22bindingName1%22).
@@ -2038,32 +2038,37 @@
 String)stack.get
+Bound
 Property(%22bindin
@@ -2052,32 +2052,38 @@
 etBoundProperty(
+null, 
 %22bindingName1%22).
@@ -2302,32 +2302,37 @@
 String)stack.get
+Bound
 Property(%22bindin
@@ -2316,32 +2316,38 @@
 etBoundProperty(
+null, 
 %22bindingName1%22).
@@ -2412,16 +2412,21 @@
 tack.get
+Bound
 Property
@@ -2426,16 +2426,22 @@
 roperty(
+null, 
 %22binding

Fix PropertyProviderStackTest.