Skip to content

Instantly share code, notes, and snippets.

@dmitric
Created September 28, 2011 19:52
Show Gist options
  • Save dmitric/1249066 to your computer and use it in GitHub Desktop.
Save dmitric/1249066 to your computer and use it in GitHub Desktop.
MapBackedBeanTest
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