2
import "primitiveHashCode.stg"
3
import "primitiveLiteral.stg"
7
skipBoolean() ::="true"
9
targetPath() ::= "com/gs/collections/impl/stack/mutable/primitive"
11
fileName(primitive) ::= "AbstractMutable<primitive.name>StackTestCase"
13
class(primitive) ::= <<
14
<body(primitive.type, primitive.wrapperName, primitive.name)>
17
body(type, wrapperName, name) ::= <<
20
package com.gs.collections.impl.stack.mutable.primitive;
22
import java.util.EmptyStackException;
24
import com.gs.collections.api.<name>Iterable;
25
import com.gs.collections.api.stack.primitive.Mutable<name>Stack;
26
import com.gs.collections.impl.list.mutable.primitive.<name>ArrayList;
27
import com.gs.collections.impl.stack.primitive.Abstract<name>StackTestCase;
28
import com.gs.collections.impl.test.Verify;
29
import org.junit.Assert;
30
import org.junit.Test;
33
* Abstract JUnit test for {@link Mutable<name>Stack}.
34
* This file was automatically generated from template file abstractMutablePrimitiveStackTestCase.stg.
36
public abstract class AbstractMutable<name>StackTestCase extends Abstract<name>StackTestCase
39
protected abstract Mutable<name>Stack classUnderTest();
42
protected abstract Mutable<name>Stack newWith(<type>... elements);
45
protected abstract Mutable<name>Stack newMutableCollectionWith(<type>... elements);
48
protected abstract Mutable<name>Stack newWithTopToBottom(<type>... elements);
50
protected abstract Mutable<name>Stack newWithIterableTopToBottom(<name>Iterable iterable);
52
protected abstract Mutable<name>Stack newWithIterable(<name>Iterable iterable);
56
public void peekAtIndex()
59
Mutable<name>Stack stack = this.classUnderTest();
60
int size = stack.size();
62
Assert.assertEquals(size - 2, stack.peekAt(0)<wideDelta.(type)>);
70
Mutable<name>Stack stack = this.classUnderTest();
71
int size = this.classUnderTest().size();
72
for (int i = 0; i \< size; i++)
74
Assert.assertEquals(size - i, stack.peek()<wideDelta.(type)>);
80
public void peekWithCount()
82
Mutable<name>Stack stack = this.classUnderTest();
83
int size = stack.size();
84
Assert.assertEquals(<name>ArrayList.newListWith(<(castIntToNarrowType.(type))("size")>, <(castIntToNarrowTypeWithParens.(type))("size - 1")>), stack.peek(2));
86
Assert.assertEquals(<name>ArrayList.newListWith(<(castIntToNarrowTypeWithParens.(type))("size - 2")>), stack.peek(1));
89
@Test(expected = EmptyStackException.class)
90
public void peek_empty_stack_throws_exception()
92
this.newWith().peek();
96
public void testNewStackWithOrder()
98
Mutable<name>Stack stack = this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">);
99
Assert.assertEquals(<(literal.(type))("3")>, stack.pop()<wideDelta.(type)>);
100
Assert.assertEquals(<(literal.(type))("2")>, stack.pop()<wideDelta.(type)>);
101
Assert.assertEquals(<(literal.(type))("1")>, stack.pop()<wideDelta.(type)>);
105
public void testNewStackIterableOrder()
107
Mutable<name>Stack stack = this.newWithIterable(<name>ArrayList.newListWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">));
108
Assert.assertEquals(<(literal.(type))("3")>, stack.pop()<wideDelta.(type)>);
109
Assert.assertEquals(<(literal.(type))("2")>, stack.pop()<wideDelta.(type)>);
110
Assert.assertEquals(<(literal.(type))("1")>, stack.pop()<wideDelta.(type)>);
115
public void testNewStackFromTopToBottomOrder()
117
Mutable<name>Stack stack = this.newWithTopToBottom(<["3", "2", "1"]:(literal.(type))(); separator=", ">);
118
Assert.assertEquals(<(literal.(type))("3")>, stack.pop()<wideDelta.(type)>);
119
Assert.assertEquals(<(literal.(type))("2")>, stack.pop()<wideDelta.(type)>);
120
Assert.assertEquals(<(literal.(type))("1")>, stack.pop()<wideDelta.(type)>);
124
public void testNewStackFromTopToBottomIterableOrder()
126
Mutable<name>Stack stack = this.newWithIterableTopToBottom(<name>ArrayList.newListWith(<["3", "2", "1"]:(literal.(type))(); separator=", ">));
127
Assert.assertEquals(<(literal.(type))("3")>, stack.pop()<wideDelta.(type)>);
128
Assert.assertEquals(<(literal.(type))("2")>, stack.pop()<wideDelta.(type)>);
129
Assert.assertEquals(<(literal.(type))("1")>, stack.pop()<wideDelta.(type)>);
135
Mutable<name>Stack stack = this.classUnderTest();
136
int size = stack.size();
137
stack.push(<(literal.(type))("5")>);
138
Verify.assertSize(size + 1, stack);
140
Verify.assertSize(size, stack);
141
Assert.assertEquals(<name>ArrayList.newListWith(<(castIntToNarrowType.(type))("size")>, <(castIntToNarrowTypeWithParens.(type))("size - 1")>), stack.peek(2));
147
Mutable<name>Stack stack = this.classUnderTest();
148
int size = stack.size();
149
for (int i = 0; i \< size; i++)
151
Assert.assertEquals(<(castIntToNarrowTypeWithParens.(type))("size - i")>, stack.pop()<wideDelta.(type)>);
152
Verify.assertSize(size - i - 1, stack);
157
public void popWithCount()
159
int size = this.classUnderTest().size();
160
Assert.assertEquals(<name>ArrayList.newListWith(<(castIntToNarrowType.(type))("size")>, <(castIntToNarrowTypeWithParens.(type))("size - 1")>), this.classUnderTest().pop(2));
166
Mutable<name>Stack stack = this.classUnderTest();
168
Verify.assertSize(0, stack);
169
Mutable<name>Stack stack1 = this.newWith();
170
Verify.assertSize(0, stack1);
172
Verify.assertSize(0, stack1);
175
@Test(expected = EmptyStackException.class)
176
public void pop_empty_stack_throws_exception()
178
this.newWith().pop();
181
@Test(expected = IllegalArgumentException.class)
182
public void pop_with_negative_count_throws_exception()
184
this.newWith(<(literal.(type))("1")>).pop(-1);
187
@Test(expected = IllegalArgumentException.class)
188
public void pop_with_count_greater_than_stack_size_throws_exception()
190
this.newWith(<(literal.(type))("1")>).pop(2);
194
public void asSynchronized()
196
Verify.assertInstanceOf(Synchronized<name>Stack.class, this.classUnderTest().asSynchronized());
197
Assert.assertEquals(this.classUnderTest(), this.classUnderTest().asSynchronized());
201
public void asUnmodifiable()
203
Verify.assertInstanceOf(Unmodifiable<name>Stack.class, this.classUnderTest().asUnmodifiable());
204
Assert.assertEquals(this.classUnderTest(), this.classUnderTest().asUnmodifiable());