package org.webik.storm.StormUnit.trident.mock;

import java.util.LinkedList;
import java.util.List;

import storm.trident.operation.TridentCollector;

public class MockCollector implements TridentCollector{

	protected LinkedList<List<Object>> tuplesList = new LinkedList<List<Object>>();
	
	protected Throwable lastError = null;
	
	public void emit( List<Object> values ) {
		tuplesList.add( values );
		
	}

	public void reportError(Throwable t) {
		lastError = t;
	}
	
	public List<Object> getEmmitedTuple( int offset ){
		return tuplesList.get( offset );
	}
	
	public List<Object> getEmmitedTuple(){
		return tuplesList.getLast();
	}
	
	public boolean assertTuplesListSize( int expectedSize ){
		return tuplesList.size() == expectedSize;
	}
	
	public boolean assertTuple( List<Object> expectedTuple ){
		return getEmmitedTuple().equals( expectedTuple );
	}
	
	public boolean assertTuple( int offset, List<Object> expectedTuple ){
		return getEmmitedTuple(offset).equals( expectedTuple );
	}

	public boolean assertError(){
		return lastError != null;
	}
	
	public Throwable getLastError(){
		return lastError;
	}
}

@@ -514,24 +514,77 @@
 t offset )%7B%0A
+%09%09if( tuplesList.isEmpty() )%7B%0A%09%09%09return null;%0A%09%09%7D%0A%09%09%0A
 %09%09return tup
@@ -647,24 +647,80 @@
 tedTuple()%7B%0A
+%09%09%0A%09%09if( tuplesList.isEmpty() )%7B%0A%09%09%09return null;%0A%09%09%7D%0A%09%09%0A
 %09%09return tup
@@ -915,32 +915,112 @@
 %7B%0A%09%09
-return getEmmitedTuple()
+List%3CObject%3E tuple = getEmmitedTuple();%0A%09%09%0A%09%09if( tuple == null )%7B%0A%09%09%09return false;%0A%09%09%7D%0A%09%09%0A%09%09return tuple
 .equ
@@ -1119,22 +1119,36 @@
 le )%7B%0A%09%09
-return
+List%3CObject%3E tuple =
  getEmmi
@@ -1160,15 +1160,83 @@
 ple(
+ 
 offset
-)
+ );%0A%09%09%0A%09%09if( tuple == null )%7B%0A%09%09%09return false;%0A%09%09%7D%0A%09%09%0A%09%09return tuple
 .equ

Check if tuple list is empty