it's hard to pinpoint what your code looks like. May help you better if I knew the code you want to test. But if your code you want to test looks like this:
private BlockingQueue<String> queue; private List<String> myList = new ArrayList<String> (): private void setBlockingQueue( BlockingQueue<String> queue ) { this.queue = queue; } public List<String> getMyList() { return myList; } public void setMyList( List<String> myList) { this.myList = myList; } public void doWork() { System.out.println("blah"); queue.drainTo( myList ); }
Test will be
public void testDoWork() { List<String> stuffToDrain = new ArrayList<String>(); stuffToDrain.add( "foo" ); stuffToDrain.add( "bar" ); myTestingClass.setMyList( stuffToTrain ); BlockingQueue<String> queue = EasyMock.createMock( BlockingQueue.class ); myTestingClass.setBlockingQueue( queue ); queue.drainTo( stuffToDrain ); EasyMock.replay( queue ); myTestingClass.doWork(); EasyMock.verify( queue ); }
Sorry if this is wrong, but it is very difficult to offer a test for code that I do not see ...
Change - we cannot claim that the parameter being changed is changing because we use the layout. All we can do is claim that the drainage method is called. If drainTo does what we want to do, weβll have to test it elsewhere, i.e. in BlockingQueue.class tests
Edit 2 - we can be more specific about which list we expect the method to be called with.
bwawok
source share