Skip to content
Permalink
Browse files
Added new tests case
  • Loading branch information
marcosperanza committed Jul 11, 2012
1 parent 7504291 commit 97d2d877ce5fe177332832d6a2e4f10ab77faf0f
Showing 1 changed file with 61 additions and 1 deletion.
@@ -21,11 +21,13 @@

import static java.util.Collections.sort;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;

import java.util.ArrayList;

import java.util.Collection;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Queue;
import java.util.Random;

@@ -58,6 +60,7 @@ public void tearDown()
public void emptyWhenCreated()
{
assertThat( queue.isEmpty(), is( true ) );
assertThat( queue.poll(), nullValue() );
}

@Test
@@ -138,6 +141,63 @@ public void returnsOrderedItemsFromRandomInsert()
Integer i = queue.poll();
assertThat( i, is( integer ) );
}

assertThat( queue.isEmpty(), is( true ) );
}

@Test
public void addAllAndContinsItem()
{
Collection<Integer> c = new ArrayList<Integer>();

c.add( 50 );
c.add( 100 );
c.add( 20 );
c.add( 21 );

queue.addAll( c );

assertThat( queue.isEmpty(), is( false ) );
assertThat( queue.containsAll( c ), is( true ) );

assertThat( queue.contains( 100 ), is( true ) );
assertThat( queue.contains( 21 ), is( true ) );
assertThat( queue.contains( 50 ), is( true ) );
assertThat( queue.contains( 20 ), is( true ) );
}

@Test
public void clearQueue()
{
final Random r = new Random( System.currentTimeMillis() );
for ( int i = 0; i < 1000; i++ )
{
Integer number = new Integer( r.nextInt( 10000 ) );
queue.add( number );
}

assertThat( queue.isEmpty(), is( false ) );
queue.clear();
assertThat( queue.isEmpty(), is( true ) );
}

@Test
public void offerPeekAndElement()
{
queue.offer( 50 );
queue.offer( 100 );
queue.offer( 20 );
queue.offer( 21 );

assertThat( queue.isEmpty(), is( false ) );
assertThat( queue.peek(), is( 20 ) );
assertThat( queue.element(), is( 20 ) );
assertThat( queue.size(), is( 4 ) );
}

@Test( expected = NoSuchElementException.class )
public void elementThrowsException()
{
assertThat( queue.element(), is( 20 ) );
}
}

0 comments on commit 97d2d87

Please sign in to comment.