Skip to content

Commit

Permalink
updated constructor copy and new unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
firaja committed Apr 8, 2018
1 parent 8b54d19 commit 139a14c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/cc/firaja/generators/AbstractGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,18 @@ public AbstractGenerator(final int limit)
* is re-initialized to this state.
*
* @param copy the generator to be copied.
* @throws IllegalArgumentException if parameter copy is null
*/
public AbstractGenerator(final AbstractGenerator<T> copy)
{
if (copy == null)
{
throw new IllegalArgumentException("Argument cannot be null");
}
this.hasLimit = copy.hasLimit;
this.limit = copy.limit;
this.cursor = copy.cursor;

this.result = copy.result;
storeOriginals();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,52 @@ public void testNegativeLimitInResize()
// THEN
}

@Test
public void testConstructorCopy()
{
// GIVEN
Generator<Integer> newGenerator;

sequentialNumericalAbstractGenerator.next();
sequentialNumericalAbstractGenerator.next();
sequentialNumericalAbstractGenerator.next();
int lastResult = sequentialNumericalAbstractGenerator.last();


// WHEN
newGenerator = new AbstractGenerator<Integer>(sequentialNumericalAbstractGenerator)
{
@Override
public Integer generate()
{
return c();
}
};
int nextResult = sequentialNumericalAbstractGenerator.next();

// THEN
assertEquals(lastResult, (int) newGenerator.last());
assertEquals(nextResult, (int) newGenerator.next());
}

@Test(expected = IllegalArgumentException.class)
public void testConstructorNullCopy()
{
// GIVEN


// WHEN
new AbstractGenerator<Object>(null)
{
@Override
public Object generate()
{
return null;
}
};

// THEN

}

}

0 comments on commit 139a14c

Please sign in to comment.