### Question:
WXImage extends WXComponent<ImageView> { @Override protected ImageView initComponentHostView(@NonNull Context context) { WXImageView view = new WXImageView(context); view.setScaleType(ScaleType.FIT_XY); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { view.setCropToPadding(true); } view.holdComponent(this); return view; } @Deprecated  WXImage(WXSDKInstance instance, WXDomObject dom, WXVContainer parent, String instanceId, boolean isLazy);  WXImage(WXSDKInstance instance, WXDomObject node,
                  WXVContainer parent); @Override void refreshData(WXComponent component); @WXComponentProp(name = Constants.Name.RESIZE_MODE) void setResizeMode(String resizeMode); @WXComponentProp(name = Constants.Name.RESIZE) void setResize(String resize); @WXComponentProp(name = Constants.Name.SRC) void setSrc(String src); @Override void recycled(); void autoReleaseImage(); void autoRecoverImage(); @Override void updateProperties(Map<String, Object> props); @JSMethod(uiThread = false) void save(final JSCallback saveStatuCallback); void destroy(); static final String SUCCEED; static final String ERRORDESC; }### Answer:
@Test @PrepareForTest(WXImageView.class) public void testInitComponentHostView() throws Exception { ImageView imageView = mWXImage.initComponentHostView(Robolectric.setupActivity(TestActivity.class)); assertEquals(imageView.getClass(), WXImageView.class); }
@Test @PrepareForTest(WXImageView.class) public void testSetBackgroundColor() throws Exception { ImageView imageView = mWXImage.initComponentHostView(Robolectric.setupActivity(TestActivity.class)); mWXImage.mHost = imageView; mWXImage.setBackgroundColor("#FFFFFF"); Drawable drawable = mWXImage.getHostView().getBackground(); assertEquals(drawable instanceof BorderDrawable, true); }
@Test public void testSetImageBitmap(){ ImageView imageView = mWXImage.initComponentHostView(Robolectric.setupActivity(TestActivity.class)); imageView.setLayoutParams(new ViewGroup.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); imageView.setImageBitmap(null); assertNull(imageView.getDrawable()); imageView.setImageBitmap(Bitmap.createBitmap(100, 100, Bitmap.Config.RGB_565)); assertNotNull(imageView.getDrawable()); }