Writing Contract Tests in Java differently
I just wanted to know whether anyone has tried nesting the concrete tests inside the abstract test like this, and if you have, then how do/did you like it?
This file contains 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>(); | |
} | |
} | |
} |
Comments