Java源码示例:org.robolectric.shadows.ShadowMimeTypeMap

示例1
@Before
public void setUp() {
    final ShadowMimeTypeMap mimeTypeMap = (ShadowMimeTypeMap) ShadowExtractor
            .extract(MimeTypeMap.getSingleton());
    mimeTypeMap.addExtensionMimeTypMapping("jpg", "image/jpeg");
    mimeTypeMap.addExtensionMimeTypMapping("jpeg", "image/jpeg");
    mimeTypeMap.addExtensionMimeTypMapping("png", "image/png");
    this.mimeTypeMap = mimeTypeMap;
}
 
示例2
@Test
public void testExtractMimeNativelySupportedFileExtension() {
  ShadowMimeTypeMap mimeTypeMap = Shadows.shadowOf(MimeTypeMap.getSingleton());
  mimeTypeMap.addExtensionMimeTypMapping("jpg", "image/jpg");

  String path = "file/with/natively/supported/extension.jpg";
  assertThat(MediaUtils.extractMime(path)).isEqualTo("image/jpg");
}
 
示例3
@Test
public void itAddsExtension () throws Exception {
	final ShadowMimeTypeMap shadowMimeTypeMap = Robolectric.shadowOf(MimeTypeMap.getSingleton());
	shadowMimeTypeMap.addExtensionMimeTypMapping("png", "image/png");

	final File picFile = this.tmp.newFile();
	IoHelper.copy(new File("./res/drawable-hdpi/ic_hosaka_meji.png"), picFile); // Just something to test with.
	final List<File> actual = CachedImageFileProvider.addFileExtensions(Collections.singletonList(picFile));
	assertThat(actual, hasItem(new File(picFile.getAbsolutePath() + ".png")));
}