Created
September 28, 2011 19:52
-
-
Save dmitric/1249066 to your computer and use it in GitHub Desktop.
MapBackedBeanTest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.junit.Test | |
import static org.junit.Assert.* | |
import org.junit.Before | |
class MapBackedBeanTest { | |
private MapBackedBean mbb | |
@Before | |
public void init(){ | |
mbb = new MapBackedBean() | |
} | |
@Test | |
public void setNewPropertyAndCheckIt(){ | |
mbb.foo = "Foo" | |
assertTrue(mbb.foo == "Foo") | |
} | |
@Test | |
public void setPropertyViaSetterAndCheckWithGetter(){ | |
mbb.setFoo("Foo") | |
assertTrue(mbb.getFoo() == "Foo") | |
} | |
@Test (expected=groovy.lang.MissingPropertyException.class) | |
public void accessPropertyThatHasNotBeenSetAndThrowException(){ | |
mbb.notDefinedYet | |
} | |
@Test (expected=groovy.lang.MissingMethodException.class) | |
public void getGetterForPropertyThatHasNotBeenSetAndThrowException(){ | |
mbb.getNotDefinedYet() | |
} | |
@Test | |
public void setUsingPropertyThenSetAgainWithSetterAndCheckPropertyAndGetter(){ | |
mbb.helloWorld = "wacky" | |
mbb.setHelloWorld("not wacky") | |
assertTrue(mbb.getHelloWorld() == "not wacky" && mbb.helloWorld == "not wacky") | |
} | |
@Test (expected=RuntimeException.class) | |
public void methodNamesLessThan4CharactersThrowException(){ | |
mbb.get() | |
} | |
@Test | |
public void singleCapitalPropertyShouldWork(){ | |
mbb.A = "capital" | |
assertTrue(mbb.A == "capital") | |
} | |
@Test | |
public void propertyShouldBeCaseInsensitiveForFirstLetter(){ | |
mbb.Amazing = "capital" | |
assertTrue(mbb.amazing == "capital") | |
} | |
@Test | |
public void shouldAllowPutAtAndGetAt(){ | |
mbb["amazing"] = "capital" | |
assertTrue(mbb["amazing"] == "capital") | |
} | |
@Test | |
public void shouldAllowPutAtAndReturnSameWithGetter(){ | |
mbb["amazing"] = "capital" | |
assertTrue(mbb.getAmazing() == "capital") | |
} | |
@Test | |
public void shouldAllowPutAtAndReturnSameWithProperty(){ | |
mbb["amazing"] = "capital" | |
assertTrue(mbb.amazing == "capital") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment