@Test public void testReadBytes_whenReturnsLessThanZeroWithInvalidLength_doesNotThrow() throws IOException { InputStream is = ContentLengthInputStream.obtain(wrapped, "invalid_length"); when(wrapped.read(any(byte[].class), anyInt(), anyInt())).thenReturn(-1); //noinspection ResultOfMethodCallIgnored is.read(new byte[10], 0, 0); }
public static List<List<KafkaTopicPartition>> createMockGetAllPartitionsFromTopicsSequenceFromFixedReturn(final List<KafkaTopicPartition> fixed) { @SuppressWarnings("unchecked") List<List<KafkaTopicPartition>> mockSequence = mock(List.class); when(mockSequence.get(anyInt())).thenAnswer(new Answer<List<KafkaTopicPartition>>() { @Override public List<KafkaTopicPartition> answer(InvocationOnMock invocationOnMock) throws Throwable { return new ArrayList<>(fixed); } }); return mockSequence; } }
@Test public void testByteArray() throws Exception { RowMetaInterface mockedRowMetaInterface = mock( RowMetaInterface.class ); stepLoadFileInput.data.outputRowMeta = mockedRowMetaInterface; stepLoadFileInput.data.convertRowMeta = mockedRowMetaInterface; Mockito.doReturn( new ValueMetaString() ).when( mockedRowMetaInterface ).getValueMeta( anyInt() ); // byte array Mockito.doReturn( new ValueMetaBinary() ).when( mockedRowMetaInterface ).getValueMeta( anyInt() ); ( (LoadFileInputMeta) runtimeSMI ).setEncoding( "UTF-8" ); stepInputFiles.addFile( getFile( "pentaho_splash.png" ) ); inputField = new LoadFileInputField(); inputField.setType( ValueMetaInterface.TYPE_BINARY ); ( (LoadFileInputMeta) runtimeSMI ).setInputFields( new LoadFileInputField[]{ inputField } ); assertNotNull( stepLoadFileInput.getOneRow() ); assertArrayEquals( IOUtils.toByteArray( getFile( "pentaho_splash.png" ).getContent().getInputStream() ), stepLoadFileInput.data.filecontent ); }
static Resources mockResources(final String resValueString) { Resources resources = mock(Resources.class); doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); ((TypedValue) args[1]).string = resValueString; return null; } }).when(resources).getValue(anyInt(), any(TypedValue.class), anyBoolean()); return resources; }
@Before public void setUp() { MockitoAnnotations.initMocks(this); when(arrayPool.get(anyInt(), eq(byte[].class))) .thenAnswer(new Answer<byte[]>() { @Override public byte[] answer(InvocationOnMock invocation) throws Throwable { int size = (Integer) invocation.getArguments()[0]; return new byte[size]; } }); }
@Test public void flush_withZeroBytesWritten_doesNotWriteToStream() throws IOException { os = new BufferedOutputStream(mockOutputStream, arrayPool, bufferSize); os.flush(); verify(mockOutputStream, never()).write(anyInt()); verify(mockOutputStream, never()).write(any(byte[].class)); verify(mockOutputStream, never()).write(any(byte[].class), anyInt(), anyInt()); }
@Test @Config(sdk = 19) public void testAsksBitmapPoolForArgb8888IfInConfigIsNull() { bitmap.setConfig(null); centerCrop.transform(context, resource, 10, 10); verify(pool).get(anyInt(), anyInt(), eq(Bitmap.Config.ARGB_8888)); verify(pool, never()).get(anyInt(), anyInt(), (Bitmap.Config) isNull()); }
public static List<List<String>> createMockGetAllTopicsSequenceFromFixedReturn(final List<String> fixed) { @SuppressWarnings("unchecked") List<List<String>> mockSequence = mock(List.class); when(mockSequence.get(anyInt())).thenAnswer(new Answer<List<String>>() { @Override public List<String> answer(InvocationOnMock invocationOnMock) throws Throwable { return new ArrayList<>(fixed); } }); return mockSequence; }
@Before public void setUp() { MockitoAnnotations.initMocks(this); doAnswer(new AddBitmapPoolAnswer(addedBitmaps)).when(pool).put(any(Bitmap.class)); when(pool.getDirty(anyInt(), anyInt(), any(Bitmap.Config.class))) .thenAnswer(new CreateBitmap()); when(cache.put(any(Key.class), anyResource())) .thenAnswer(new AddBitmapCacheAnswer(addedBitmaps)); }
@Before public void setup() { MockitoAnnotations.initMocks(this); when(bitmapPool.get(anyInt(), anyInt(), any(Bitmap.Config.class))) .thenAnswer(new Util.CreateBitmap()); Context context = RuntimeEnvironment.application; Glide.init(context, new GlideBuilder().setBitmapPool(bitmapPool)); circleCrop = new CircleCrop(); }
EngineTestHarness() { when(keyFactory.buildKey(eq(model), eq(signature), anyInt(), anyInt(), eq(transformations), eq(Object.class), eq(Object.class), eq(options))).thenReturn(cacheKey); when(resource.getResource()).thenReturn(mock(Resource.class)); job = mock(EngineJob.class); }
@Test public void testAvailable_withReadBytes_returnsContentLengthOffsetByNumberOfBytes() throws IOException { int contentLength = 678; InputStream is = ContentLengthInputStream.obtain(wrapped, String.valueOf(contentLength)); int read = 100; when(wrapped.read(any(byte[].class), anyInt(), anyInt())).thenReturn(read); assertThat(is.read(new byte[500], 0, 0)).isEqualTo(read); assertThat(is.available()).isEqualTo(contentLength - read); }
@Test public void testCallbackIsNotCalledTwiceIfPreDrawFiresTwice() { activity.visible(); target.getSize(cb); LayoutParams layoutParams = new FrameLayout.LayoutParams(1234, 4123); view.setLayoutParams(layoutParams); view.requestLayout(); view.getViewTreeObserver().dispatchOnPreDraw(); view.getViewTreeObserver().dispatchOnPreDraw(); verify(cb, times(1)).onSizeReady(anyInt(), anyInt()); }
@Test public void testReadBytes_whenReturnsLessThanZeroWithoutReadingAllContent_throwsIOException() throws IOException { int contentLength = 2; InputStream is = ContentLengthInputStream.obtain(wrapped, String.valueOf(contentLength)); when(wrapped.read(any(byte[].class), anyInt(), anyInt())).thenReturn(-1); try { //noinspection ResultOfMethodCallIgnored is.read(new byte[10], 0, 0); fail("Failed to throw expected exception"); } catch (IOException e) { // Expected. } }