Skip to content

Instantly share code, notes, and snippets.

@oleg
Created February 26, 2012 11:20
Show Gist options
  • Save oleg/1916161 to your computer and use it in GitHub Desktop.
Save oleg/1916161 to your computer and use it in GitHub Desktop.
Isolation
package logic;
import org.junit.Assert;
import org.junit.Test;
import play.Play;
import java.util.Properties;
public class IsolatedTestV1 extends Assert {
static {
Play.configuration = new Properties();
}
@Test
public void should_return_null_if_nothing_added() throws Exception {
assertEquals(null, Play.configuration.getProperty("score"));
}
@Test
public void should_return_what_was_added() throws Exception {
Play.configuration.setProperty("score", "10");
assertEquals("10", Play.configuration.getProperty("score"));
}
}
package logic;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import play.Play;
import java.util.Properties;
public class IsolatedTestV2 extends Assert {
private Properties originalProps;
@Before
public void setUp() throws Exception {
originalProps = Play.configuration;
Play.configuration = new Properties();
}
@After
public void tearDown() throws Exception {
Play.configuration = originalProps;
}
@Test
public void should_return_what_was_added() throws Exception {
Play.configuration.setProperty("score", "10");
assertEquals("10", Play.configuration.getProperty("score"));
}
@Test
public void should_return_null_if_nothing_added() throws Exception {
assertEquals(null, Play.configuration.getProperty("score"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment