Methods Summary |
---|
protected void | setUp()
super.setUp();
/**
* Workaround for mockito and JB-MR2 incompatibility
*
* Avoid java.lang.IllegalArgumentException: dexcache == null
* https://code.google.com/p/dexmaker/issues/detail?id=2
*/
System.setProperty("dexmaker.dexcache", getContext().getCacheDir().toString());
// TODO: refactor above into one of the test runners
mReader = spy(ImageReader.newInstance(DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_FORMAT,
DEFAULT_MAX_IMAGES));
mImage1 = mock(Image.class);
mImage2 = mock(Image.class);
mImage3 = mock(Image.class);
/**
* Ensure rest of classes are mockable
*/
{
mock(Plane.class);
mock(OnImageAvailableListener.class);
}
|
protected void | tearDown()
mReader.close();
super.tearDown();
|
public void | testGetLatestImage1()Return the last image from the image queue, close up the rest.
when(mReader.acquireNextImage()).thenReturn(mImage1);
when(mReader.acquireNextImageNoThrowISE()).thenReturn(null);
assertEquals(mImage1, mReader.acquireLatestImage());
verify(mImage1, never()).close();
|
public void | testGetLatestImage2()Return the last image from the image queue, close up the rest.
when(mReader.acquireNextImage()).thenReturn(mImage1);
when(mReader.acquireNextImageNoThrowISE()).thenReturn(mImage2).thenReturn(null);
assertEquals(mImage2, mReader.acquireLatestImage());
verify(mImage1, atLeastOnce()).close();
verify(mImage2, never()).close();
|
public void | testGetLatestImage3()Return the last image from the image queue, close up the rest.
when(mReader.acquireNextImage()).thenReturn(mImage1);
when(mReader.acquireNextImageNoThrowISE()).thenReturn(mImage2).
thenReturn(mImage3).
thenReturn(null);
assertEquals(mImage3, mReader.acquireLatestImage());
verify(mImage1, atLeastOnce()).close();
verify(mImage2, atLeastOnce()).close();
verify(mImage3, never()).close();
|
public void | testGetLatestImageEmpty()Return null when there is nothing in the image queue.
when(mReader.acquireNextImage()).thenReturn(null);
when(mReader.acquireNextImageNoThrowISE()).thenReturn(null);
assertEquals(null, mReader.acquireLatestImage());
|
public void | testGetLatestImageExceptionalError()All images are cleaned up when we get an unexpected Error.
when(mReader.acquireNextImage()).thenReturn(mImage1);
when(mReader.acquireNextImageNoThrowISE()).thenReturn(mImage2).
thenReturn(mImage3).
thenThrow(new OutOfMemoryError());
try {
mReader.acquireLatestImage();
fail("Impossible");
} catch(OutOfMemoryError e) {
}
verify(mImage1, atLeastOnce()).close();
verify(mImage2, atLeastOnce()).close();
verify(mImage3, atLeastOnce()).close();
|
public void | testGetLatestImageExceptionalRuntime()All images are cleaned up when we get an unexpected RuntimeException.
when(mReader.acquireNextImage()).thenReturn(mImage1);
when(mReader.acquireNextImageNoThrowISE()).thenReturn(mImage2).
thenReturn(mImage3).
thenThrow(new RuntimeException());
try {
mReader.acquireLatestImage();
fail("Impossible");
} catch(RuntimeException e) {
}
verify(mImage1, atLeastOnce()).close();
verify(mImage2, atLeastOnce()).close();
verify(mImage3, atLeastOnce()).close();
|
public void | testGetLatestImageTooManyBuffersAcquiredEmpty()Return null if get a IllegalStateException with no images in the queue.
when(mReader.acquireNextImage()).thenThrow(new IllegalStateException());
try {
mReader.acquireLatestImage();
fail("Expected IllegalStateException to be thrown");
} catch(IllegalStateException e) {
}
|