Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
沉迷打码的小凳子
glide
提交
51d3546e
G
glide
项目概览
沉迷打码的小凳子
/
glide
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
glide
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
51d3546e
编写于
11月 15, 2014
作者:
S
Sam Judd
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add tests for AppWidget and NotificationTargets
上级
f5d05829
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
232 addition
and
0 deletion
+232
-0
library/src/androidTest/java/com/bumptech/glide/request/target/AppWidgetTargetTest.java
...om/bumptech/glide/request/target/AppWidgetTargetTest.java
+136
-0
library/src/androidTest/java/com/bumptech/glide/request/target/NotificationTargetTest.java
...bumptech/glide/request/target/NotificationTargetTest.java
+96
-0
未找到文件。
library/src/androidTest/java/com/bumptech/glide/request/target/AppWidgetTargetTest.java
0 → 100644
浏览文件 @
51d3546e
package
com.bumptech.glide.request.target
;
import
static
com
.
google
.
common
.
truth
.
Truth
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
mockito
.
Matchers
.
eq
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
android.appwidget.AppWidgetManager
;
import
android.content.ComponentName
;
import
android.graphics.Bitmap
;
import
android.widget.RemoteViews
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.robolectric.Robolectric
;
import
org.robolectric.RobolectricTestRunner
;
import
org.robolectric.annotation.Config
;
import
org.robolectric.annotation.Implementation
;
import
org.robolectric.annotation.Implements
;
import
org.robolectric.shadows.ShadowAppWidgetManager
;
@RunWith
(
RobolectricTestRunner
.
class
)
@Config
(
manifest
=
Config
.
NONE
,
emulateSdk
=
18
,
shadows
=
AppWidgetTargetTest
.
UpdateShadowAppWidgetManager
.
class
)
public
class
AppWidgetTargetTest
{
private
UpdateShadowAppWidgetManager
shadowManager
;
private
RemoteViews
views
;
private
int
viewId
;
@Before
public
void
setUp
()
{
shadowManager
=
Robolectric
.
shadowOf_
(
AppWidgetManager
.
getInstance
(
Robolectric
.
application
));
viewId
=
1234
;
views
=
mock
(
RemoteViews
.
class
);
}
@Test
public
void
testSetsBitmapOnRemoteViewsWithViewIdWhenCreatedWithComponentName
()
{
ComponentName
componentName
=
mock
(
ComponentName
.
class
);
AppWidgetTarget
target
=
new
AppWidgetTarget
(
Robolectric
.
application
,
views
,
viewId
,
componentName
);
Bitmap
bitmap
=
Bitmap
.
createBitmap
(
100
,
100
,
Bitmap
.
Config
.
ARGB_8888
);
target
.
onResourceReady
(
bitmap
,
null
/*glideAnimation*/
);
verify
(
views
).
setImageViewBitmap
(
eq
(
viewId
),
eq
(
bitmap
));
}
@Test
public
void
testUpdatesAppWidgetWhenCreatedWithComponentName
()
{
ComponentName
componentName
=
mock
(
ComponentName
.
class
);
AppWidgetTarget
target
=
new
AppWidgetTarget
(
Robolectric
.
application
,
views
,
viewId
,
componentName
);
target
.
onResourceReady
(
Bitmap
.
createBitmap
(
100
,
100
,
Bitmap
.
Config
.
ARGB_8888
),
null
/*glideAnimation*/
);
assertEquals
(
componentName
,
shadowManager
.
updatedComponentName
);
assertEquals
(
views
,
shadowManager
.
updatedRemoteViews
);
}
@Test
public
void
testSetsBitmapOnRemoteViewsWithViewIdWhenCreatedWithWidgetIds
()
{
int
[]
widgetIds
=
new
int
[]
{
1
};
AppWidgetTarget
target
=
new
AppWidgetTarget
(
Robolectric
.
application
,
views
,
viewId
,
widgetIds
);
Bitmap
bitmap
=
Bitmap
.
createBitmap
(
100
,
200
,
Bitmap
.
Config
.
RGB_565
);
target
.
onResourceReady
(
bitmap
,
null
/*glideAnimation*/
);
verify
(
views
).
setImageViewBitmap
(
eq
(
viewId
),
eq
(
bitmap
));
}
@Test
public
void
testUpdatesAppWidgetWhenCreatedWithWidgetIds
()
{
int
[]
widgetIds
=
new
int
[]
{
1
};
AppWidgetTarget
target
=
new
AppWidgetTarget
(
Robolectric
.
application
,
views
,
viewId
,
widgetIds
);
target
.
onResourceReady
(
Bitmap
.
createBitmap
(
200
,
100
,
Bitmap
.
Config
.
ARGB_8888
),
null
/*glideAnimation*/
);
assertThat
(
widgetIds
).
isEqualTo
(
shadowManager
.
updatedWidgetIds
);
assertEquals
(
views
,
shadowManager
.
updatedRemoteViews
);
}
@Test
(
expected
=
NullPointerException
.
class
)
public
void
testThrowsWhenGivenNullContextWithWidgetIds
()
{
new
AppWidgetTarget
(
null
/*context*/
,
views
,
1234
/*viewId*/
,
1
/*widgetIds*/
);
}
@Test
(
expected
=
NullPointerException
.
class
)
public
void
testThrowsWhenGivenNullContextWithComponentName
()
{
new
AppWidgetTarget
(
null
/*context*/
,
views
,
1234
/*viewId*/
,
mock
(
ComponentName
.
class
));
}
@Test
(
expected
=
NullPointerException
.
class
)
public
void
testThrowsWhenGivenNullRemoteViewsWithWidgetIds
()
{
new
AppWidgetTarget
(
Robolectric
.
application
,
null
/*remoteViews*/
,
viewId
,
1
/*widgetIds*/
);
}
@Test
(
expected
=
NullPointerException
.
class
)
public
void
testThrowsWhenGivenNullRemoteViewsWithComponentName
()
{
new
AppWidgetTarget
(
Robolectric
.
application
,
null
/*remoteViews*/
,
viewId
,
mock
(
ComponentName
.
class
));
}
@Test
(
expected
=
NullPointerException
.
class
)
public
void
testThrowsWhenGivenNullWidgetIds
()
{
new
AppWidgetTarget
(
Robolectric
.
application
,
views
,
viewId
,
(
int
[])
null
/*widgetIds*/
);
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
testThrowsWhenGivenEmptyWidgetIds
()
{
new
AppWidgetTarget
(
Robolectric
.
application
,
views
,
viewId
);
}
@Test
(
expected
=
NullPointerException
.
class
)
public
void
testThrowsWhenGivenNullComponentName
()
{
new
AppWidgetTarget
(
Robolectric
.
application
,
views
,
viewId
,
(
ComponentName
)
null
);
}
@Implements
(
AppWidgetManager
.
class
)
public
static
class
UpdateShadowAppWidgetManager
extends
ShadowAppWidgetManager
{
public
int
[]
updatedWidgetIds
;
public
RemoteViews
updatedRemoteViews
;
public
ComponentName
updatedComponentName
;
@Implementation
public
void
updateAppWidget
(
int
[]
appWidgetIds
,
RemoteViews
views
)
{
updatedWidgetIds
=
appWidgetIds
;
updatedRemoteViews
=
views
;
}
@Implementation
public
void
updateAppWidget
(
ComponentName
componentName
,
RemoteViews
views
)
{
updatedComponentName
=
componentName
;
updatedRemoteViews
=
views
;
}
}
}
\ No newline at end of file
library/src/androidTest/java/com/bumptech/glide/request/target/NotificationTargetTest.java
0 → 100644
浏览文件 @
51d3546e
package
com.bumptech.glide.request.target
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
mockito
.
Matchers
.
eq
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
android.app.Notification
;
import
android.app.NotificationManager
;
import
android.content.Context
;
import
android.graphics.Bitmap
;
import
android.widget.RemoteViews
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.robolectric.Robolectric
;
import
org.robolectric.RobolectricTestRunner
;
import
org.robolectric.annotation.Config
;
import
org.robolectric.annotation.Implementation
;
import
org.robolectric.annotation.Implements
;
import
org.robolectric.shadows.ShadowNotificationManager
;
@RunWith
(
RobolectricTestRunner
.
class
)
@Config
(
manifest
=
Config
.
NONE
,
emulateSdk
=
18
,
shadows
=
NotificationTargetTest
.
UpdateShadowNotificationManager
.
class
)
public
class
NotificationTargetTest
{
private
UpdateShadowNotificationManager
shadowManager
;
private
RemoteViews
remoteViews
;
private
int
viewId
;
private
Notification
notification
;
private
int
notificationId
;
private
NotificationTarget
target
;
@Before
public
void
setUp
()
{
NotificationManager
notificationManager
=
(
NotificationManager
)
Robolectric
.
application
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
);
shadowManager
=
Robolectric
.
shadowOf_
(
notificationManager
);
remoteViews
=
mock
(
RemoteViews
.
class
);
viewId
=
123
;
notification
=
mock
(
Notification
.
class
);
notificationId
=
456
;
target
=
new
NotificationTarget
(
Robolectric
.
application
,
remoteViews
,
viewId
,
100
/*width*/
,
100
/*height*/
,
notification
,
notificationId
);
}
@Test
public
void
testSetsBitmapOnRemoteViewsWithGivenImageIdOnResourceReady
()
{
Bitmap
bitmap
=
Bitmap
.
createBitmap
(
100
,
100
,
Bitmap
.
Config
.
ARGB_8888
);
target
.
onResourceReady
(
bitmap
,
null
/*glideAnimation*/
);
verify
(
remoteViews
).
setImageViewBitmap
(
eq
(
viewId
),
eq
(
bitmap
));
}
@Test
public
void
updatesNotificationManagerWithNotificationIdAndNotificationOnResourceReady
()
{
target
.
onResourceReady
(
Bitmap
.
createBitmap
(
100
,
100
,
Bitmap
.
Config
.
ARGB_8888
),
null
/*glideAnimation*/
);
assertEquals
(
notificationId
,
shadowManager
.
updatedNotificationId
);
assertEquals
(
notification
,
shadowManager
.
updatedNotification
);
}
@Test
(
expected
=
NullPointerException
.
class
)
public
void
testThrowsIfContextIsNull
()
{
new
NotificationTarget
(
null
/*context*/
,
mock
(
RemoteViews
.
class
),
123
/*viewId*/
,
100
/*width*/
,
100
/*height*/
,
mock
(
Notification
.
class
),
456
/*notificationId*/
);
}
@Test
(
expected
=
NullPointerException
.
class
)
public
void
testThrowsIfNotificationIsNull
()
{
new
NotificationTarget
(
Robolectric
.
application
,
mock
(
RemoteViews
.
class
),
123
/*viewId*/
,
100
/*width*/
,
100
/*height*/
,
null
/*notification*/
,
456
/*notificationId*/
);
}
@Test
(
expected
=
NullPointerException
.
class
)
public
void
testThrowsIfRemoteViewsIsNull
()
{
new
NotificationTarget
(
Robolectric
.
application
,
null
/*remoteViews*/
,
123
/*viewId*/
,
100
/*width*/
,
100
/*height*/
,
mock
(
Notification
.
class
),
456
/*notificationId*/
);
}
@Implements
(
NotificationManager
.
class
)
public
static
class
UpdateShadowNotificationManager
extends
ShadowNotificationManager
{
int
updatedNotificationId
;
Notification
updatedNotification
;
@Implementation
public
void
notify
(
int
notificationId
,
Notification
notification
)
{
updatedNotificationId
=
notificationId
;
updatedNotification
=
notification
;
}
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录