Mercurial > hg > release > thermostat-0.13
changeset 177:cbc3b73ac685
Use test fixtures in backend tests
Reviewed-by: rkennke
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-March/000597.html
author | Omair Majid <omajid@redhat.com> |
---|---|
date | Fri, 30 Mar 2012 10:19:08 -0400 |
parents | a5ab66716e6b |
children | 2e2cb086b621 |
files | agent/src/test/java/com/redhat/thermostat/backend/sample/SampleBackendTest.java agent/src/test/java/com/redhat/thermostat/backend/system/SystemBackendTest.java |
diffstat | 2 files changed, 18 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/agent/src/test/java/com/redhat/thermostat/backend/sample/SampleBackendTest.java Fri Mar 30 09:44:58 2012 -0400 +++ b/agent/src/test/java/com/redhat/thermostat/backend/sample/SampleBackendTest.java Fri Mar 30 10:19:08 2012 -0400 @@ -43,16 +43,22 @@ import java.util.Collection; +import org.junit.Before; import org.junit.Test; -import com.redhat.thermostat.backend.Backend; import com.redhat.thermostat.common.storage.Category; public class SampleBackendTest { + private SampleBackend b; + + @Before + public void setUp() { + b = new SampleBackend(); + } + @Test public void testBackendInfo() { - Backend b = new SampleBackend(); assertNotNull(b.getName()); assertNotNull(b.getVersion()); assertNotNull(b.getVendor()); @@ -61,7 +67,6 @@ @Test public void testBasicBackend() { - Backend b = new SampleBackend(); assertFalse(b.isActive()); b.activate(); assertTrue(b.isActive()); @@ -71,7 +76,6 @@ @Test public void testActivateTwice() { - Backend b = new SampleBackend(); b.activate(); b.activate(); assert (b.isActive()); @@ -79,7 +83,6 @@ @Test public void testDeactiateWhenNotActive() { - Backend b = new SampleBackend(); b.deactivate(); b.deactivate(); assertFalse(b.isActive()); @@ -87,14 +90,12 @@ @Test public void testCategoriesAreSane() { - SampleBackend b = new SampleBackend(); Collection<Category> categories = b.getCategories(); assertEquals(0, categories.size()); } @Test public void testDefaultConfiguration() { - SampleBackend b = new SampleBackend(); assertTrue(b.getConfigurationMap().isEmpty()); assertTrue(b.getConfigurationValue("foo") == null); @@ -102,7 +103,6 @@ @Test public void testModifyConfiguration() { - SampleBackend b = new SampleBackend(); b.setConfigurationValue("speed", "fast"); assertEquals("fast", b.getConfigurationValue("speed")); }
--- a/agent/src/test/java/com/redhat/thermostat/backend/system/SystemBackendTest.java Fri Mar 30 09:44:58 2012 -0400 +++ b/agent/src/test/java/com/redhat/thermostat/backend/system/SystemBackendTest.java Fri Mar 30 10:19:08 2012 -0400 @@ -42,9 +42,9 @@ import java.util.Collection; +import org.junit.Before; import org.junit.Test; -import com.redhat.thermostat.backend.Backend; import com.redhat.thermostat.common.dao.CpuStatDAO; import com.redhat.thermostat.common.dao.HostInfoDAO; import com.redhat.thermostat.common.dao.MemoryStatDAO; @@ -59,11 +59,17 @@ public class SystemBackendTest { + private SystemBackend b; + + @Before + public void setUp() { + b = new SystemBackend(); + Storage s = mock(Storage.class); + b.setStorage(s); + } + @Test public void testBasicBackend() { - Backend b = new SystemBackend(); - Storage s = mock(Storage.class); - b.setStorage(s); assertFalse(b.isActive()); b.activate(); assertTrue(b.isActive()); @@ -73,9 +79,6 @@ @Test public void testActivateTwice() { - Backend b = new SystemBackend(); - Storage s = mock(Storage.class); - b.setStorage(s); b.activate(); b.activate(); assert(b.isActive()); @@ -83,9 +86,6 @@ @Test public void testDeactiateWhenNotActive() { - Backend b = new SystemBackend(); - Storage s = mock(Storage.class); - b.setStorage(s); b.deactivate(); b.deactivate(); assertFalse(b.isActive()); @@ -93,7 +93,6 @@ @Test public void testCategoriesAreSane() { - SystemBackend b = new SystemBackend(); Collection<Category> categories = b.getCategories(); assertTrue(categories.contains(CpuStatDAO.cpuStatCategory));