本文整理汇总了Java中org.robolectric.RuntimeEnvironment类的典型用法代码示例。如果您正苦于以下问题:Java RuntimeEnvironment类的具体用法?Java RuntimeEnvironment怎么用?Java RuntimeEnvironment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RuntimeEnvironment类属于org.robolectric包,在下文中一共展示了RuntimeEnvironment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: migratePgpInlineEncryptedMessage
import org.robolectric.RuntimeEnvironment; //导入依赖的package包/类
@Test
public void migratePgpInlineEncryptedMessage() throws Exception {
SQLiteDatabase db = createV50Database();
insertPgpInlineEncryptedMessage(db);
db.close();
LocalStore localStore = LocalStore.getInstance(account, RuntimeEnvironment.application);
LocalMessage msg = localStore.getFolder("dev").getMessage("7");
FetchProfile fp = new FetchProfile();
fp.add(FetchProfile.Item.BODY);
localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null);
Assert.assertEquals(6, msg.getDatabaseId());
Assert.assertEquals(12, msg.getHeaderNames().size());
Assert.assertEquals("text/plain", msg.getMimeType());
Assert.assertEquals(0, msg.getAttachmentCount());
Assert.assertTrue(msg.getBody() instanceof BinaryMemoryBody);
String msgTextContent = MessageExtractor.getTextFromPart(msg);
Assert.assertEquals(OpenPgpUtils.PARSE_RESULT_MESSAGE, OpenPgpUtils.parseMessage(msgTextContent));
}
示例2: migrateTextHtml
import org.robolectric.RuntimeEnvironment; //导入依赖的package包/类
@Test
public void migrateTextHtml() throws Exception {
SQLiteDatabase db = createV50Database();
insertMultipartAlternativeMessage(db);
db.close();
LocalStore localStore = LocalStore.getInstance(account, RuntimeEnvironment.application);
LocalMessage msg = localStore.getFolder("dev").getMessage("9");
FetchProfile fp = new FetchProfile();
fp.add(FetchProfile.Item.BODY);
localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null);
Assert.assertEquals(8, msg.getDatabaseId());
Assert.assertEquals(9, msg.getHeaderNames().size());
Assert.assertEquals("multipart/alternative", msg.getMimeType());
Assert.assertEquals(0, msg.getAttachmentCount());
Multipart msgBody = (Multipart) msg.getBody();
Assert.assertEquals("------------060200010509000000040004", msgBody.getBoundary());
}
示例3: check
import org.robolectric.RuntimeEnvironment; //导入依赖的package包/类
/**
* Verify assets can be read with robolectric.
*
* @throws IOException if failed.
*/
@Test
public void check() throws IOException {
final InputStream s = RuntimeEnvironment.application.getAssets()
.open(new File("check.txt").getPath());
Assert.assertNotNull(s);
try {
MatcherAssert.assertThat(
IOUtils.toString(s),
Matchers.equalTo("check")
);
} finally {
//noinspection ThrowFromFinallyBlock
s.close();
}
}
示例4: testGetProxiedUrlForPartialCache
import org.robolectric.RuntimeEnvironment; //导入依赖的package包/类
@Test
public void testGetProxiedUrlForPartialCache() throws Exception {
File cacheDir = RuntimeEnvironment.application.getExternalCacheDir();
File file = new File(cacheDir, new Md5FileNameGenerator().generate(HTTP_DATA_URL));
int partialCacheSize = 1000;
byte[] partialData = ProxyCacheTestUtils.generate(partialCacheSize);
File partialCacheFile = ProxyCacheTestUtils.getTempFile(file);
IoUtils.saveToFile(partialData, partialCacheFile);
HttpProxyCacheServer proxy = newProxy(cacheFolder);
String expectedUrl = "http://127.0.0.1:" + getPort(proxy) + "/" + ProxyCacheUtils.encode(HTTP_DATA_URL);
assertThat(proxy.getProxyUrl(HTTP_DATA_URL)).isEqualTo(expectedUrl);
assertThat(proxy.getProxyUrl(HTTP_DATA_URL, true)).isEqualTo(expectedUrl);
assertThat(proxy.getProxyUrl(HTTP_DATA_URL, false)).isEqualTo(expectedUrl);
proxy.shutdown();
}
示例5: testReuseSourceInfo
import org.robolectric.RuntimeEnvironment; //导入依赖的package包/类
@Test
public void testReuseSourceInfo() throws Exception {
SourceInfoStorage sourceInfoStorage = SourceInfoStorageFactory.newSourceInfoStorage(RuntimeEnvironment.application);
HttpUrlSource source = new HttpUrlSource(HTTP_DATA_URL, sourceInfoStorage);
File cacheFile = newCacheFile();
HttpProxyCache proxyCache = new HttpProxyCache(source, new FileCache(cacheFile));
processRequest(proxyCache, "GET /" + HTTP_DATA_URL + " HTTP/1.1");
HttpUrlSource notOpenableSource = ProxyCacheTestUtils.newNotOpenableHttpUrlSource(HTTP_DATA_URL, sourceInfoStorage);
HttpProxyCache proxyCache2 = new HttpProxyCache(notOpenableSource, new FileCache(cacheFile));
Response response = processRequest(proxyCache2, "GET /" + HTTP_DATA_URL + " HTTP/1.1");
proxyCache.shutdown();
assertThat(response.data).isEqualTo(loadAssetFile(ASSETS_DATA_NAME));
assertThat(response.contentLength).isEqualTo(HTTP_DATA_SIZE);
assertThat(response.contentType).isEqualTo("image/jpeg");
}
示例6: create_with_custom_sharables
import org.robolectric.RuntimeEnvironment; //导入依赖的package包/类
@Test
public void create_with_custom_sharables() {
final List<Shareable> shareables = Stream.generate(() -> mock(Shareable.class)).limit(2)
.collect(Collectors.toList());
final PhialBuilder builder = new PhialBuilder(RuntimeEnvironment.application);
shareables.forEach(builder::addShareable);
final PhialCore phialCore = PhialCore.create(builder);
final List<Shareable> createdShareables = phialCore.getShareManager()
.getUserShareItems()
.stream()
.map(item -> (UserShareItem) item)
.map(UserShareItem::getShareable)
.collect(Collectors.toList());
assertEquals(shareables, createdShareables);
}
示例7: setUp
import org.robolectric.RuntimeEnvironment; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
Glide.tearDown();
RobolectricPackageManager pm = RuntimeEnvironment.getRobolectricPackageManager();
ApplicationInfo info =
pm.getApplicationInfo(RuntimeEnvironment.application.getPackageName(), 0);
info.metaData = new Bundle();
info.metaData.putString(SetupModule.class.getName(), "GlideModule");
// Ensure that target's size ready callback will be called synchronously.
target = mock(Target.class);
imageView = new ImageView(RuntimeEnvironment.application);
imageView.setLayoutParams(new ViewGroup.LayoutParams(100, 100));
imageView.layout(0, 0, 100, 100);
doAnswer(new CallSizeReady()).when(target).getSize(isA(SizeReadyCallback.class));
Handler bgHandler = mock(Handler.class);
when(bgHandler.post(isA(Runnable.class))).thenAnswer(new Answer<Boolean>() {
@Override
public Boolean answer(InvocationOnMock invocation) throws Throwable {
Runnable runnable = (Runnable) invocation.getArguments()[0];
runnable.run();
return true;
}
});
Lifecycle lifecycle = mock(Lifecycle.class);
RequestManagerTreeNode treeNode = mock(RequestManagerTreeNode.class);
requestManager = new RequestManager(Glide.get(getContext()), lifecycle, treeNode);
requestManager.resumeRequests();
}
示例8: createIntentForAction_matchingPackage
import org.robolectric.RuntimeEnvironment; //导入依赖的package包/类
@Test
public void createIntentForAction_matchingPackage() {
shadowPackageManager.addResolveInfoForIntent(
saveIntent,
createResolveInfo(EXAMPLE_PROVIDER_PACKAGE, EXAMPLE_PROVIDER_ACTIVITY_CLASS));
Intent intentForAction = ProviderResolver.createIntentForAction(
RuntimeEnvironment.application,
EXAMPLE_PROVIDER_PACKAGE,
ProtocolConstants.SAVE_CREDENTIAL_ACTION);
assertThat(intentForAction).isNotNull();
assertThat(intentForAction.getAction())
.isEqualTo(ProtocolConstants.SAVE_CREDENTIAL_ACTION);
assertThat(intentForAction.getCategories())
.containsExactly(ProtocolConstants.OPENYOLO_CATEGORY);
assertThat(intentForAction.getComponent()).isNotNull();
assertThat(intentForAction.getComponent().getPackageName())
.isEqualTo(EXAMPLE_PROVIDER_PACKAGE);
assertThat(intentForAction.getComponent().getClassName())
.isEqualTo(EXAMPLE_PROVIDER_ACTIVITY_CLASS);
}
示例9: testCustomTabIntent
import org.robolectric.RuntimeEnvironment; //导入依赖的package包/类
@Test
public void testCustomTabIntent() {
final SessionManager sessionManager = SessionManager.getInstance();
final SafeIntent intent = new SafeIntent(new CustomTabsIntent.Builder()
.setToolbarColor(Color.GREEN)
.addDefaultShareMenuItem()
.build()
.intent
.setData(Uri.parse(TEST_URL)));
sessionManager.handleIntent(RuntimeEnvironment.application, intent, null);
final List<Session> sessions = sessionManager.getSessions().getValue();
assertNotNull(sessions);
assertEquals(1, sessions.size());
final Session session = sessions.get(0);
assertEquals(TEST_URL, session.getUrl().getValue());
assertTrue(sessionManager.hasSession());
}
示例10: testHandlesPaths
import org.robolectric.RuntimeEnvironment; //导入依赖的package包/类
@Test
public void testHandlesPaths() throws IOException {
// TODO on windows it will fail with schema being the drive letter (C:\... -> C)
assumeTrue(!Util.isWindows());
File f = RuntimeEnvironment.application.getCacheDir();
Uri expected = Uri.fromFile(f);
when(uriLoader.buildLoadData(eq(expected), eq(IMAGE_SIDE), eq(IMAGE_SIDE), eq(options)))
.thenReturn(new ModelLoader.LoadData<>(key, fetcher));
assertTrue(loader.handles(f.getAbsolutePath()));
assertEquals(
fetcher,
Preconditions.checkNotNull(
loader.buildLoadData(f.getAbsolutePath(), IMAGE_SIDE, IMAGE_SIDE, options)).fetcher);
}
示例11: testDispatchDraw
import org.robolectric.RuntimeEnvironment; //导入依赖的package包/类
@Test
public void testDispatchDraw(){
Canvas canvas = Mockito.mock(Canvas.class);
ShadowSelectorView view = new ShadowSelectorView(RuntimeEnvironment.application);
view.setIndicatorPoint(new PointF(0, 0));
view.setSelectorCircleSize(20);
view.triggerOnLayout(true, 0, 0, 500, 500);
view.triggerDispatchDraw(canvas);
final ArgumentCaptor<Paint> captor = ArgumentCaptor.forClass(Paint.class);
verify(canvas).drawCircle(eq(0f), eq(0f), eq(20f), captor.capture());
Paint paint = captor.getValue();
Assert.assertEquals(Color.LTGRAY, paint.getColor());
verify(canvas).drawLine(eq(0f), eq(0f), eq(250f), eq(250f), captor.capture());
}
示例12: setUp
import org.robolectric.RuntimeEnvironment; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
options = new Options();
DisplayMetrics displayMetrics =
RuntimeEnvironment.application.getResources().getDisplayMetrics();
when(byteArrayPool.get(anyInt(), Matchers.eq(byte[].class)))
.thenReturn(new byte[ArrayPool.STANDARD_BUFFER_SIZE_BYTES]);
List<ImageHeaderParser> parsers = new ArrayList<ImageHeaderParser>();
parsers.add(new DefaultImageHeaderParser());
downsampler = new Downsampler(parsers, displayMetrics, bitmapPool, byteArrayPool);
initialSdkVersion = Build.VERSION.SDK_INT;
}
示例13: testReturnsOpenedInputStreamWhenFileFound
import org.robolectric.RuntimeEnvironment; //导入依赖的package包/类
@Test
public void testReturnsOpenedInputStreamWhenFileFound() throws FileNotFoundException {
InputStream expected = new ByteArrayInputStream(new byte[0]);
Shadows.shadowOf(RuntimeEnvironment.application.getContentResolver())
.registerInputStream(harness.uri, expected);
assertEquals(expected, harness.get().open(harness.uri));
}
示例14: setUp
import org.robolectric.RuntimeEnvironment; //导入依赖的package包/类
@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) throws Throwable {
connectivityListener = (ConnectivityListener) invocation.getArguments()[1];
return connectivityMonitor;
}
});
target = new BaseTarget<Drawable>() {
@Override
public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) {
// Empty.
}
@Override
public void getSize(SizeReadyCallback cb) {
// Empty.
}
@Override
public void removeCallback(SizeReadyCallback cb) {
// Empty.
}
};
requestTracker = mock(RequestTracker.class);
manager =
new RequestManager(
Glide.get(RuntimeEnvironment.application),
lifecycle,
treeNode,
requestTracker,
factory,
context);
}
示例15: testDoesNotWorkWithoutCustomProxySelector
import org.robolectric.RuntimeEnvironment; //导入依赖的package包/类
@Test // https://github.com/danikula/AndroidVideoCache/issues/28
public void testDoesNotWorkWithoutCustomProxySelector() throws Exception {
HttpProxyCacheServer httpProxyCacheServer = new HttpProxyCacheServer(RuntimeEnvironment.application);
// IgnoreHostProxySelector is set in HttpProxyCacheServer constructor. So let reset it by custom.
installExternalSystemProxy();
String proxiedUrl = httpProxyCacheServer.getProxyUrl(HTTP_DATA_URL);
// server can't proxy this url due to it is not alive (can't ping itself), so it returns original url
assertThat(proxiedUrl).isEqualTo(HTTP_DATA_URL);
}