Refine search
@Before public void setUp() throws IOException { MockitoAnnotations.initMocks(this); String assetPath = "/some/asset/path"; fetcher = new StreamAssetPathFetcher(assetManager, assetPath); when(assetManager.open(eq(assetPath))).thenReturn(expected); }
static void scanDeprecatedWay(AnnotationEngine annotationEngine, Object testClass, Class<?> clazz) { Field[] fields = clazz.getDeclaredFields(); for (Field field : fields) { processAnnotationDeprecatedWay(annotationEngine, testClass, field); } }
@Before public void shutUp() { initMocks(this); when(picasso.transformRequest(any(Request.class))).thenAnswer(TRANSFORM_REQUEST_ANSWER); }
@SuppressWarnings("unchecked") @Before public void setUp() { MockitoAnnotations.initMocks(this); Application context = RuntimeEnvironment.application; ReEncodingGifResourceEncoder.Factory factory = mock(ReEncodingGifResourceEncoder.Factory.class); when(decoder.getNextFrame()).thenReturn(Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888)); when(factory.buildDecoder(any(GifDecoder.BitmapProvider.class))).thenReturn(decoder); when(factory.buildParser()).thenReturn(parser); when(factory.buildEncoder()).thenReturn(gifEncoder); when(factory.buildFrameResource(any(Bitmap.class), any(BitmapPool.class))) .thenReturn(frameResource); // TODO Util.anyResource once Util is moved to testutil module (remove unchecked above!) when(frameTransformation.transform(anyContext(), any(Resource.class), anyInt(), anyInt())) .thenReturn(frameResource); when(gifDrawable.getFrameTransformation()).thenReturn(frameTransformation); when(gifDrawable.getBuffer()).thenReturn(ByteBuffer.allocate(0)); when(resource.get()).thenReturn(gifDrawable); encoder = new ReEncodingGifResourceEncoder(context, mock(BitmapPool.class), factory); options = new Options(); options.set(ReEncodingGifResourceEncoder.ENCODE_TRANSFORMATION, true); file = new File(context.getCacheDir(), "test"); }
@Before public void setUp() { MockitoAnnotations.initMocks(this); context = RuntimeEnvironment.application; when(diskCacheFactory.build()).thenReturn(diskCache); Glide.init( context, File.class, InputStream.class, new ByteArrayInputStream(new byte[0]), registry); registerMockModelLoader( File.class, ParcelFileDescriptor.class, mock(ParcelFileDescriptor.class), registry); registerMockModelLoader(File.class, ByteBuffer.class, ByteBuffer.allocate(10), registry); imageView.setLayoutParams(new ViewGroup.LayoutParams(100, 100)); imageView.layout(0, 0, 100, 100); doAnswer(new CallSizeReady()).when(target).getSize(isA(SizeReadyCallback.class)); when(bgHandler.post(isA(Runnable.class))).thenAnswer(new Answer<Boolean>() { @Override public Boolean answer(InvocationOnMock invocation) {
@Before public void setUp() { MockitoAnnotations.initMocks(this); context = RuntimeEnvironment.application; doAnswer(new Util.WriteDigest("first")).when(first) .updateDiskCacheKey(any(MessageDigest.class)); doAnswer(new Util.WriteDigest("second")).when(second) .updateDiskCacheKey(any(MessageDigest.class)); }
@Before public void setUp() { MockitoAnnotations.initMocks(this); gifHeader = Mockito.spy(new GifHeader()); when(parser.parseHeader()).thenReturn(gifHeader); when(parserPool.obtain(isA(ByteBuffer.class))).thenReturn(parser); when(decoderFactory.build(isA(GifDecoder.BitmapProvider.class), eq(gifHeader), isA(ByteBuffer.class), anyInt())) .thenReturn(gifDecoder); List<ImageHeaderParser> parsers = new ArrayList<>(); parsers.add(new DefaultImageHeaderParser()); options = new Options(); decoder = new ByteBufferGifDecoder( RuntimeEnvironment.application, parsers, bitmapPool, new LruArrayPool(ARRAY_POOL_SIZE_BYTES), parserPool, decoderFactory); }
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); when(cache.addListener(anyString(), any(Cache.Listener.class))).thenReturn(new TreeSet<>()); tracker = new CachedRegionTracker(cache, CACHE_KEY, CHUNK_INDEX); cacheDir = Util.createTempDirectory(RuntimeEnvironment.application, "ExoPlayerTest"); index = new CachedContentIndex(cacheDir); }
@Before public void setUp() { MockitoAnnotations.initMocks(this); context = RuntimeEnvironment.application; connectivityMonitor = mock(ConnectivityMonitor.class); ConnectivityMonitorFactory factory = mock(ConnectivityMonitorFactory.class); when(factory.build(isA(Context.class), isA(ConnectivityMonitor.ConnectivityListener.class))) .thenAnswer(new Answer<ConnectivityMonitor>() { @Override public ConnectivityMonitor answer(InvocationOnMock invocation) {
@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]; } }); }
protected Statement withBefores(FrameworkMethod method, Object target, Statement statement) { this.target = target; // get new test listener and add it to the framework mockitoTestListener = listenerSupplier.get(); Mockito.framework().addListener(mockitoTestListener); // init annotated mocks before tests MockitoAnnotations.initMocks(target); return super.withBefores(method, target, statement); }
/** * Initializes objects annotated with Mockito annotations for given testClass: * @{@link org.mockito.Mock}, @{@link Spy}, @{@link Captor}, @{@link InjectMocks} * <p> * See examples in javadoc for {@link MockitoAnnotations} class. */ public static void initMocks(Object testClass) { if (testClass == null) { throw new MockitoException("testClass cannot be null. For info how to use @Mock annotations see examples in javadoc for MockitoAnnotations class"); } AnnotationEngine annotationEngine = new GlobalConfiguration().getAnnotationEngine(); Class<?> clazz = testClass.getClass(); //below can be removed later, when we get read rid of deprecated stuff if (annotationEngine.getClass() != new DefaultMockitoConfiguration().getAnnotationEngine().getClass()) { //this means user has his own annotation engine and we have to respect that. //we will do annotation processing the old way so that we are backwards compatible while (clazz != Object.class) { scanDeprecatedWay(annotationEngine, testClass, clazz); clazz = clazz.getSuperclass(); } } //anyway act 'the new' way annotationEngine.process(testClass.getClass(), testClass); }
@Before public void setUp() { MockitoAnnotations.initMocks(this); arrayPool = new LruArrayPool(); doAnswer(new Util.WriteDigest("transformation1")).when(transformation1) .updateDiskCacheKey(any(MessageDigest.class)); doAnswer(new Util.WriteDigest("transformation1")).when(transformation2) .updateDiskCacheKey(any(MessageDigest.class)); }
@Before public void setUp() throws PackageManager.NameNotFoundException { MockitoAnnotations.initMocks(this); applicationInfo = new ApplicationInfo(); applicationInfo.metaData = new Bundle(); String packageName = "com.bumptech.test"; when(context.getPackageName()).thenReturn(packageName); PackageManager pm = mock(PackageManager.class); when(pm.getApplicationInfo(eq(packageName), eq(PackageManager.GET_META_DATA))) .thenReturn(applicationInfo); when(context.getPackageManager()).thenReturn(pm); parser = new ManifestParser(context); }