Created
December 2, 2015 18:59
-
-
Save rsds143/7838f03ccfb7c9586681 to your computer and use it in GitHub Desktop.
sharing junit tests between different repository types
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 static org.hamcrest.MatcherAssert.assertThat; | |
| import static org.hamcrest.core.Is.is; | |
| /** | |
| * Created by rsvihla on 12/2/2015. | |
| */ | |
| public abstract class BaseIntegrationTest { | |
| protected abstract DataRepository getDataRepository(); | |
| private MyService service; | |
| @Before | |
| public void before(){ | |
| service = new MyService(); | |
| service.setRepository(getDataRepository()); | |
| } | |
| @Test | |
| public void testGetInts(){ | |
| assertThat(service.getAllInts().size(), is(0)); | |
| } | |
| @Test | |
| public void testSaveInts(){ | |
| service.saveInt(1); | |
| assertThat(getDataRepository().getAllInts().get(0), is(1)); | |
| } | |
| } |
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.hamcrest.MatcherAssert.assertThat; | |
| import static org.hamcrest.core.Is.is; | |
| /** | |
| * Created by rsvihla on 12/2/2015. | |
| */ | |
| public abstract class BaseTestCase { | |
| protected abstract DataRepository getDataRepository(); | |
| @Test | |
| public void testGetInts(){ | |
| assertThat(getDataRepository().getAllInts().size(), is(0)); | |
| } | |
| @Test | |
| public void testSaveInts(){ | |
| getDataRepository().saveInt(1); | |
| assertThat(getDataRepository().getAllInts().get(0), is(1)); | |
| } | |
| } |
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
| class CassandraIntegrationTest extends BaseIntegrationTest { | |
| @Override | |
| protected DataRepository getDataRepository() { | |
| return new CassandraDataRepository(); | |
| } | |
| } |
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
| public class CassandraTest extends BaseTestCase{ | |
| @Override | |
| protected DataRepository getDataRepository() { | |
| return new CassandraDataRepository(); | |
| } | |
| } |
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
| class OracleIntegrationTest extends BaseIntegrationTest { | |
| @Override | |
| protected DataRepository getDataRepository() { | |
| return new OracleDataRepository(); | |
| } | |
| } |
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
| public class OracleTest extends BaseTestCase{ | |
| @Override | |
| protected DataRepository getDataRepository() { | |
| return new OracleDataRepository(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment