Created
July 5, 2014 16:01
-
-
Save chbaranowski/fc962c01c84323ca2bf6 to your computer and use it in GitHub Desktop.
Spock sample test
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
import spock.lang.Specification; | |
class FixedSizeListSpec extends Specification { | |
def "T1 - clear a empty list"() { | |
given: "a empty list" | |
List list = list(maxsize: 2) | |
when: "clear the list" | |
list.clear() | |
then: "the list should be empty" | |
list.isEmpty() | |
} | |
def "T2 - remove element from empty list"() { | |
given: "a empty list" | |
List list = list(maxsize: 2) | |
when: "remove a element from the list" | |
list.remove("abc") | |
then: "list should be empty" | |
list.isEmpty() | |
} | |
def "T3 - clear a filled list"() { | |
given: "a list with one element" | |
List list = list(maxsize: 2) | |
list.add("abc") | |
when: "clear the list" | |
list.clear() | |
then: "list should be empty" | |
list.isEmpty() | |
} | |
def "T4 - remove element from list"() { | |
given: "a list with one element" | |
List list = list(maxsize: 2) | |
list.add("abc") | |
when: "remove the element from the list" | |
list.remove("abc") | |
then: "the list should be empty" | |
list.isEmpty() | |
} | |
def "T5 - remove a element which is not in the list"() { | |
given: "a list with one element" | |
List list = list(maxsize: 2) | |
list.add("abc") | |
when: "remove a element which is not in the list" | |
list.remove("xyz") | |
then: "the list size should be one" | |
list.size() == 1 | |
list.get(0) == "abc" | |
} | |
def "T6 - add to much elements in a list"() { | |
given: "a list with two elements" | |
List list = list(maxsize: 2) | |
list.add("abc") | |
list.add("xyz") | |
when: "add another element to the list" | |
list.add("123") | |
then: "the list should throw a exception" | |
thrown IllegalStateException | |
} | |
def "T7 - clear list with two elements"() { | |
given: "a list with two elements" | |
List list = list(maxsize: 2) | |
list.add("abc") | |
list.add("xyz") | |
when: "clear the list" | |
list.clear() | |
then: "the list should be empty" | |
list.isEmpty() | |
} | |
def "T8 - remove a element form a list with two elements"() { | |
given: "a list with two elements" | |
List list = list(maxsize: 2) | |
list.add("abc") | |
list.add("xyz") | |
when: "remove one element from the list" | |
list.remove("abc") | |
then: "the list size should be 1" | |
list.size() == 1 | |
list.get(0) == "xyz" | |
} | |
def "T9 - remove a element which is not in the list(size = 2)"() { | |
given: "a list with two elements" | |
List list = list(maxsize: 2) | |
list.add("abc") | |
list.add("xyz") | |
when: "remove element which is not in the list" | |
list.remove("123") | |
then: "the list size should be 2" | |
list.size() == 2 | |
list.get(0) == "abc" | |
list.get(1) == "xyz" | |
} | |
def list(attr) { | |
new FixedSizeArrayList(attr.maxsize) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment