Created
July 15, 2011 11:45
-
-
Save jbrains/1084541 to your computer and use it in GitHub Desktop.
An alternative contract test style in Java
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
| package ca.jbrains.junit; | |
| import static org.junit.Assert.assertTrue; | |
| import java.util.ArrayList; | |
| import java.util.LinkedList; | |
| import java.util.List; | |
| import org.junit.Test; | |
| public abstract class ListContract { | |
| @Test | |
| public void emptyList() throws Exception { | |
| assertTrue(createEmptyList().isEmpty()); | |
| } | |
| public abstract List<Object> createEmptyList(); | |
| public static class ArrayListRespectsListContract extends ListContract { | |
| @Override | |
| public List<Object> createEmptyList() { | |
| return new ArrayList<Object>(); | |
| } | |
| } | |
| public static class LinkedListRespectsListContract extends ListContract { | |
| @Override | |
| public List<Object> createEmptyList() { | |
| return new LinkedList<Object>(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment