Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
沉迷打码的小凳子
glide
提交
0be7fb30
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,体验更适合开发者的 AI 搜索 >>
提交
0be7fb30
编写于
6月 25, 2014
作者:
S
Sam Judd
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Check for original in cache before getting source.
上级
17326862
变更
17
隐藏空白更改
内联
并排
Showing
17 changed file
with
237 addition
and
59 deletion
+237
-59
library/src/main/java/com/bumptech/glide/OriginalEngineKey.java
...y/src/main/java/com/bumptech/glide/OriginalEngineKey.java
+42
-0
library/src/main/java/com/bumptech/glide/load/engine/DefaultResourceRunnerFactory.java
...ptech/glide/load/engine/DefaultResourceRunnerFactory.java
+3
-3
library/src/main/java/com/bumptech/glide/load/engine/Engine.java
.../src/main/java/com/bumptech/glide/load/engine/Engine.java
+4
-3
library/src/main/java/com/bumptech/glide/load/engine/EngineKey.java
...c/main/java/com/bumptech/glide/load/engine/EngineKey.java
+9
-0
library/src/main/java/com/bumptech/glide/load/engine/EngineKeyFactory.java
...java/com/bumptech/glide/load/engine/EngineKeyFactory.java
+4
-4
library/src/main/java/com/bumptech/glide/load/engine/KeyFactory.java
.../main/java/com/bumptech/glide/load/engine/KeyFactory.java
+0
-13
library/src/main/java/com/bumptech/glide/load/engine/ResourceRunner.java
...n/java/com/bumptech/glide/load/engine/ResourceRunner.java
+2
-3
library/src/main/java/com/bumptech/glide/load/engine/ResourceRunnerFactory.java
...com/bumptech/glide/load/engine/ResourceRunnerFactory.java
+2
-3
library/src/main/java/com/bumptech/glide/load/engine/SourceResourceRunner.java
.../com/bumptech/glide/load/engine/SourceResourceRunner.java
+27
-15
library/src/main/java/com/bumptech/glide/load/resource/transcode/UnitTranscoder.java
...umptech/glide/load/resource/transcode/UnitTranscoder.java
+1
-1
library/src/test/java/com/bumptech/glide/OriginalEngineKeyTest.java
...c/test/java/com/bumptech/glide/OriginalEngineKeyTest.java
+48
-0
library/src/test/java/com/bumptech/glide/load/UnitTransformationTest.java
.../java/com/bumptech/glide/load/UnitTransformationTest.java
+22
-0
library/src/test/java/com/bumptech/glide/load/engine/DefaultResourceRunnerFactoryTest.java
...h/glide/load/engine/DefaultResourceRunnerFactoryTest.java
+1
-2
library/src/test/java/com/bumptech/glide/load/engine/EngineTest.java
.../test/java/com/bumptech/glide/load/engine/EngineTest.java
+2
-2
library/src/test/java/com/bumptech/glide/load/engine/ResourceRunnerTest.java
...va/com/bumptech/glide/load/engine/ResourceRunnerTest.java
+3
-1
library/src/test/java/com/bumptech/glide/load/engine/SourceResourceRunnerTest.java
.../bumptech/glide/load/engine/SourceResourceRunnerTest.java
+65
-5
library/src/test/java/com/bumptech/glide/load/resource/transcode/UnitTranscoderTest.java
...ech/glide/load/resource/transcode/UnitTranscoderTest.java
+2
-4
未找到文件。
library/src/main/java/com/bumptech/glide/OriginalEngineKey.java
0 → 100644
浏览文件 @
0be7fb30
package
com.bumptech.glide
;
import
com.bumptech.glide.load.Key
;
import
java.io.UnsupportedEncodingException
;
import
java.security.MessageDigest
;
public
class
OriginalEngineKey
implements
Key
{
private
String
id
;
public
OriginalEngineKey
(
String
id
)
{
this
.
id
=
id
;
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
{
return
true
;
}
if
(!(
o
instanceof
OriginalEngineKey
))
{
return
false
;
}
OriginalEngineKey
that
=
(
OriginalEngineKey
)
o
;
if
(!
id
.
equals
(
that
.
id
))
{
return
false
;
}
return
true
;
}
@Override
public
int
hashCode
()
{
return
id
.
hashCode
();
}
@Override
public
void
updateDiskCacheKey
(
MessageDigest
messageDigest
)
throws
UnsupportedEncodingException
{
messageDigest
.
update
(
id
.
getBytes
(
"UTF-8"
));
}
}
library/src/main/java/com/bumptech/glide/load/engine/DefaultResourceRunnerFactory.java
浏览文件 @
0be7fb30
...
...
@@ -30,15 +30,15 @@ class DefaultResourceRunnerFactory implements ResourceRunnerFactory {
}
@Override
public
<
T
,
Z
,
R
>
ResourceRunner
<
Z
,
R
>
build
(
Key
key
,
int
width
,
int
height
,
public
<
T
,
Z
,
R
>
ResourceRunner
<
Z
,
R
>
build
(
Engine
Key
key
,
int
width
,
int
height
,
ResourceDecoder
<
InputStream
,
Z
>
cacheDecoder
,
DataFetcher
<
T
>
fetcher
,
ResourceDecoder
<
T
,
Z
>
decoder
,
Transformation
<
Z
>
transformation
,
ResourceEncoder
<
Z
>
encoder
,
ResourceTranscoder
<
Z
,
R
>
transcoder
,
Priority
priority
,
boolean
isMemoryCacheable
,
EngineJobListener
listener
)
{
EngineJob
engineJob
=
new
EngineJob
(
key
,
mainHandler
,
isMemoryCacheable
,
listener
);
SourceResourceRunner
<
T
,
Z
,
R
>
sourceRunner
=
new
SourceResourceRunner
<
T
,
Z
,
R
>(
key
,
width
,
height
,
fetch
er
,
decoder
,
transformation
,
encoder
,
transcoder
,
diskCache
,
priority
,
engineJob
);
SourceResourceRunner
<
T
,
Z
,
R
>
sourceRunner
=
new
SourceResourceRunner
<
T
,
Z
,
R
>(
key
,
width
,
height
,
cacheLoad
er
,
cacheDecoder
,
fetcher
,
decoder
,
transformation
,
encoder
,
transcoder
,
diskCache
,
priority
,
engineJob
);
return
new
ResourceRunner
<
Z
,
R
>(
key
,
width
,
height
,
cacheLoader
,
cacheDecoder
,
transformation
,
transcoder
,
sourceRunner
,
diskCacheService
,
service
,
engineJob
,
priority
);
...
...
library/src/main/java/com/bumptech/glide/load/engine/Engine.java
浏览文件 @
0be7fb30
...
...
@@ -27,7 +27,7 @@ public class Engine implements EngineJobListener, MemoryCache.ResourceRemovedLis
private
static
final
String
TAG
=
"Engine"
;
private
final
Map
<
Key
,
ResourceRunner
>
runners
;
private
final
ResourceRunnerFactory
factory
;
private
final
KeyFactory
keyFactory
;
private
final
Engine
KeyFactory
keyFactory
;
private
final
MemoryCache
cache
;
private
final
Map
<
Key
,
WeakReference
<
Resource
>>
activeResources
;
private
final
ReferenceQueue
<
Resource
>
resourceReferenceQueue
;
...
...
@@ -52,7 +52,7 @@ public class Engine implements EngineJobListener, MemoryCache.ResourceRemovedLis
}
Engine
(
ResourceRunnerFactory
factory
,
MemoryCache
cache
,
DiskCache
diskCache
,
ExecutorService
resizeService
,
ExecutorService
diskCacheService
,
Map
<
Key
,
ResourceRunner
>
runners
,
KeyFactory
keyFactory
,
ExecutorService
diskCacheService
,
Map
<
Key
,
ResourceRunner
>
runners
,
Engine
KeyFactory
keyFactory
,
Map
<
Key
,
WeakReference
<
Resource
>>
activeResources
)
{
this
.
cache
=
cache
;
...
...
@@ -101,7 +101,8 @@ public class Engine implements EngineJobListener, MemoryCache.ResourceRemovedLis
long
startTime
=
LogTime
.
getLogTime
();
final
String
id
=
fetcher
.
getId
();
Key
key
=
keyFactory
.
buildKey
(
id
,
width
,
height
,
cacheDecoder
,
decoder
,
transformation
,
encoder
,
transcoder
);
EngineKey
key
=
keyFactory
.
buildKey
(
id
,
width
,
height
,
cacheDecoder
,
decoder
,
transformation
,
encoder
,
transcoder
);
Resource
cached
=
cache
.
remove
(
key
);
if
(
cached
!=
null
)
{
...
...
library/src/main/java/com/bumptech/glide/load/engine/EngineKey.java
浏览文件 @
0be7fb30
package
com.bumptech.glide.load.engine
;
import
com.bumptech.glide.OriginalEngineKey
;
import
com.bumptech.glide.load.Key
;
import
com.bumptech.glide.load.ResourceDecoder
;
import
com.bumptech.glide.load.ResourceEncoder
;
...
...
@@ -23,6 +24,7 @@ public class EngineKey implements Key {
private
ResourceTranscoder
transcoder
;
private
String
stringKey
;
private
int
hashCode
;
private
OriginalEngineKey
originalKey
;
public
EngineKey
(
String
id
,
int
width
,
int
height
,
ResourceDecoder
cacheDecoder
,
ResourceDecoder
decoder
,
Transformation
transformation
,
ResourceEncoder
encoder
,
ResourceTranscoder
transcoder
)
{
...
...
@@ -36,6 +38,13 @@ public class EngineKey implements Key {
this
.
transcoder
=
transcoder
;
}
public
Key
getOriginalKey
()
{
if
(
originalKey
==
null
)
{
originalKey
=
new
OriginalEngineKey
(
id
);
}
return
originalKey
;
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
{
...
...
library/src/main/java/com/bumptech/glide/load/engine/EngineKeyFactory.java
浏览文件 @
0be7fb30
package
com.bumptech.glide.load.engine
;
import
com.bumptech.glide.load.Key
;
import
com.bumptech.glide.load.ResourceDecoder
;
import
com.bumptech.glide.load.ResourceEncoder
;
import
com.bumptech.glide.load.Transformation
;
import
com.bumptech.glide.load.resource.transcode.ResourceTranscoder
;
public
class
EngineKeyFactory
implements
KeyFactory
{
@Override
public
Key
buildKey
(
String
id
,
int
width
,
int
height
,
ResourceDecoder
cacheDecoder
,
ResourceDecoder
sourceDecoder
,
public
class
EngineKeyFactory
{
public
Engine
Key
buildKey
(
String
id
,
int
width
,
int
height
,
ResourceDecoder
cacheDecoder
,
ResourceDecoder
sourceDecoder
,
Transformation
transformation
,
ResourceEncoder
encoder
,
ResourceTranscoder
transcoder
)
{
return
new
EngineKey
(
id
,
width
,
height
,
cacheDecoder
,
sourceDecoder
,
transformation
,
encoder
,
transcoder
);
}
}
library/src/main/java/com/bumptech/glide/load/engine/KeyFactory.java
已删除
100644 → 0
浏览文件 @
17326862
package
com.bumptech.glide.load.engine
;
import
com.bumptech.glide.load.Key
;
import
com.bumptech.glide.load.ResourceDecoder
;
import
com.bumptech.glide.load.ResourceEncoder
;
import
com.bumptech.glide.load.Transformation
;
import
com.bumptech.glide.load.resource.transcode.ResourceTranscoder
;
public
interface
KeyFactory
{
public
Key
buildKey
(
String
id
,
int
width
,
int
height
,
ResourceDecoder
cacheDecoder
,
ResourceDecoder
sourceDecoder
,
Transformation
transformation
,
ResourceEncoder
encoder
,
ResourceTranscoder
transcoder
);
}
library/src/main/java/com/bumptech/glide/load/engine/ResourceRunner.java
浏览文件 @
0be7fb30
...
...
@@ -4,7 +4,6 @@ import android.os.SystemClock;
import
android.util.Log
;
import
com.bumptech.glide.CacheLoader
;
import
com.bumptech.glide.Priority
;
import
com.bumptech.glide.load.Key
;
import
com.bumptech.glide.load.ResourceDecoder
;
import
com.bumptech.glide.load.Transformation
;
import
com.bumptech.glide.load.engine.executor.Prioritized
;
...
...
@@ -22,7 +21,7 @@ import java.util.concurrent.Future;
public
class
ResourceRunner
<
Z
,
R
>
implements
Runnable
,
Prioritized
{
private
static
final
String
TAG
=
"ResourceRunner"
;
private
final
Key
key
;
private
final
Engine
Key
key
;
private
final
Transformation
<
Z
>
transformation
;
private
final
ResourceTranscoder
<
Z
,
R
>
transcoder
;
private
final
SourceResourceRunner
sourceRunner
;
...
...
@@ -37,7 +36,7 @@ public class ResourceRunner<Z, R> implements Runnable, Prioritized {
private
volatile
Future
<?>
future
;
private
volatile
boolean
isCancelled
;
public
ResourceRunner
(
Key
key
,
int
width
,
int
height
,
CacheLoader
cacheLoader
,
public
ResourceRunner
(
Engine
Key
key
,
int
width
,
int
height
,
CacheLoader
cacheLoader
,
ResourceDecoder
<
InputStream
,
Z
>
cacheDecoder
,
Transformation
<
Z
>
transformation
,
ResourceTranscoder
<
Z
,
R
>
transcoder
,
SourceResourceRunner
sourceRunner
,
ExecutorService
diskCacheService
,
ExecutorService
resizeService
,
EngineJob
job
,
Priority
priority
)
{
...
...
library/src/main/java/com/bumptech/glide/load/engine/ResourceRunnerFactory.java
浏览文件 @
0be7fb30
package
com.bumptech.glide.load.engine
;
import
com.bumptech.glide.Priority
;
import
com.bumptech.glide.load.Key
;
import
com.bumptech.glide.load.ResourceDecoder
;
import
com.bumptech.glide.load.ResourceEncoder
;
import
com.bumptech.glide.load.Transformation
;
import
com.bumptech.glide.load.resource.transcode.ResourceTranscoder
;
import
com.bumptech.glide.load.data.DataFetcher
;
import
com.bumptech.glide.load.resource.transcode.ResourceTranscoder
;
import
java.io.InputStream
;
...
...
@@ -25,7 +24,7 @@ interface ResourceRunnerFactory {
* @param <R> The type of the resource that will be transcoded to from the decoded resource.
* @return
*/
public
<
T
,
Z
,
R
>
ResourceRunner
<
Z
,
R
>
build
(
Key
key
,
int
width
,
int
height
,
public
<
T
,
Z
,
R
>
ResourceRunner
<
Z
,
R
>
build
(
Engine
Key
key
,
int
width
,
int
height
,
ResourceDecoder
<
InputStream
,
Z
>
cacheDecoder
,
DataFetcher
<
T
>
fetcher
,
ResourceDecoder
<
T
,
Z
>
decoder
,
Transformation
<
Z
>
transformation
,
ResourceEncoder
<
Z
>
encoder
,
ResourceTranscoder
<
Z
,
R
>
transcoder
,
Priority
priority
,
boolean
isMemoryCacheable
,
EngineJobListener
listener
);
...
...
library/src/main/java/com/bumptech/glide/load/engine/SourceResourceRunner.java
浏览文件 @
0be7fb30
...
...
@@ -2,8 +2,8 @@ package com.bumptech.glide.load.engine;
import
android.os.SystemClock
;
import
android.util.Log
;
import
com.bumptech.glide.CacheLoader
;
import
com.bumptech.glide.Priority
;
import
com.bumptech.glide.load.Key
;
import
com.bumptech.glide.load.ResourceDecoder
;
import
com.bumptech.glide.load.ResourceEncoder
;
import
com.bumptech.glide.load.Transformation
;
...
...
@@ -13,6 +13,7 @@ import com.bumptech.glide.load.engine.executor.Prioritized;
import
com.bumptech.glide.load.resource.transcode.ResourceTranscoder
;
import
com.bumptech.glide.request.ResourceCallback
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
/**
...
...
@@ -23,26 +24,32 @@ import java.io.OutputStream;
*/
public
class
SourceResourceRunner
<
T
,
Z
,
R
>
implements
Runnable
,
DiskCache
.
Writer
,
Prioritized
{
private
static
final
String
TAG
=
"SourceRunner"
;
private
final
Key
key
;
private
final
Engine
Key
key
;
private
final
int
width
;
private
final
int
height
;
private
CacheLoader
cacheLoader
;
private
ResourceDecoder
<
InputStream
,
Z
>
cacheDecoder
;
private
final
DataFetcher
<
T
>
fetcher
;
private
final
ResourceDecoder
<
T
,
Z
>
decoder
;
private
Transformation
<
Z
>
transformation
;
private
final
Transformation
<
Z
>
transformation
;
private
final
ResourceEncoder
<
Z
>
encoder
;
private
ResourceTranscoder
<
Z
,
R
>
transcoder
;
private
DiskCache
diskCache
;
private
Priority
priority
;
private
ResourceCallback
cb
;
private
final
ResourceTranscoder
<
Z
,
R
>
transcoder
;
private
final
DiskCache
diskCache
;
private
final
Priority
priority
;
private
final
ResourceCallback
cb
;
private
Resource
<
Z
>
result
;
private
volatile
boolean
isCancelled
;
public
SourceResourceRunner
(
Key
key
,
int
width
,
int
height
,
DataFetcher
<
T
>
dataFetcher
,
ResourceDecoder
<
T
,
Z
>
decoder
,
Transformation
<
Z
>
transformation
,
ResourceEncoder
<
Z
>
encoder
,
ResourceTranscoder
<
Z
,
R
>
transcoder
,
DiskCache
diskCache
,
Priority
priority
,
ResourceCallback
cb
)
{
public
SourceResourceRunner
(
EngineKey
key
,
int
width
,
int
height
,
CacheLoader
cacheLoader
,
ResourceDecoder
<
InputStream
,
Z
>
cacheDecoder
,
DataFetcher
<
T
>
dataFetcher
,
ResourceDecoder
<
T
,
Z
>
decoder
,
Transformation
<
Z
>
transformation
,
ResourceEncoder
<
Z
>
encoder
,
ResourceTranscoder
<
Z
,
R
>
transcoder
,
DiskCache
diskCache
,
Priority
priority
,
ResourceCallback
cb
)
{
this
.
key
=
key
;
this
.
width
=
width
;
this
.
height
=
height
;
this
.
cacheLoader
=
cacheLoader
;
this
.
cacheDecoder
=
cacheDecoder
;
this
.
fetcher
=
dataFetcher
;
this
.
decoder
=
decoder
;
this
.
transformation
=
transformation
;
...
...
@@ -68,11 +75,16 @@ public class SourceResourceRunner<T, Z, R> implements Runnable, DiskCache.Writer
try
{
long
start
=
SystemClock
.
currentThreadTimeMillis
();
final
Resource
<
Z
>
decoded
=
decode
();
if
(
Log
.
isLoggable
(
TAG
,
Log
.
VERBOSE
))
{
Log
.
v
(
TAG
,
"Decoded from source in "
+
(
SystemClock
.
currentThreadTimeMillis
()
-
start
));
start
=
SystemClock
.
currentThreadTimeMillis
();
Resource
<
Z
>
decoded
=
cacheLoader
.
load
(
key
.
getOriginalKey
(),
cacheDecoder
,
width
,
height
);
if
(
decoded
==
null
)
{
decoded
=
decodeFromSource
();
if
(
Log
.
isLoggable
(
TAG
,
Log
.
VERBOSE
))
{
Log
.
v
(
TAG
,
"Decoded from source in "
+
(
SystemClock
.
currentThreadTimeMillis
()
-
start
));
start
=
SystemClock
.
currentThreadTimeMillis
();
}
}
if
(
decoded
!=
null
)
{
Resource
<
Z
>
transformed
=
transformation
.
transform
(
decoded
,
width
,
height
);
if
(
decoded
!=
transformed
)
{
...
...
@@ -101,7 +113,7 @@ public class SourceResourceRunner<T, Z, R> implements Runnable, DiskCache.Writer
}
}
private
Resource
<
Z
>
decode
()
throws
Exception
{
private
Resource
<
Z
>
decode
FromSource
()
throws
Exception
{
try
{
T
toDecode
=
fetcher
.
loadData
(
priority
);
if
(
toDecode
!=
null
)
{
...
...
library/src/main/java/com/bumptech/glide/load/resource/transcode/UnitTranscoder.java
浏览文件 @
0be7fb30
...
...
@@ -17,6 +17,6 @@ public class UnitTranscoder implements ResourceTranscoder {
@Override
public
String
getId
()
{
return
"
UnitTranscoder.com.bumptech.glide.load.resource.transcode
"
;
return
""
;
}
}
library/src/test/java/com/bumptech/glide/OriginalEngineKeyTest.java
0 → 100644
浏览文件 @
0be7fb30
package
com.bumptech.glide
;
import
org.junit.Test
;
import
java.io.UnsupportedEncodingException
;
import
java.security.MessageDigest
;
import
java.security.NoSuchAlgorithmException
;
import
java.util.Arrays
;
import
static
junit
.
framework
.
Assert
.
assertEquals
;
import
static
junit
.
framework
.
Assert
.
assertTrue
;
public
class
OriginalEngineKeyTest
{
@Test
public
void
testIsEqualToAnotherKeyWithSameId
()
{
String
id
=
"fakeId"
;
OriginalEngineKey
first
=
new
OriginalEngineKey
(
id
);
OriginalEngineKey
second
=
new
OriginalEngineKey
(
id
);
assertEquals
(
first
,
second
);
}
@Test
public
void
testReturnsSameHashCodeAsAnotherKeyWithSameId
()
{
String
id
=
"testId"
;
OriginalEngineKey
first
=
new
OriginalEngineKey
(
id
);
OriginalEngineKey
second
=
new
OriginalEngineKey
(
id
);
assertEquals
(
first
.
hashCode
(),
second
.
hashCode
());
}
@Test
public
void
testUpdatesDigestWithGivenId
()
throws
NoSuchAlgorithmException
,
UnsupportedEncodingException
{
String
id
=
"testId2"
;
OriginalEngineKey
firstKey
=
new
OriginalEngineKey
(
id
);
MessageDigest
firstDigest
=
MessageDigest
.
getInstance
(
"SHA-1"
);
firstKey
.
updateDiskCacheKey
(
firstDigest
);
byte
[]
firstBytes
=
firstDigest
.
digest
();
OriginalEngineKey
secondKey
=
new
OriginalEngineKey
(
id
);
MessageDigest
secondDigest
=
MessageDigest
.
getInstance
(
"SHA-1"
);
secondKey
.
updateDiskCacheKey
(
secondDigest
);
byte
[]
secondBytes
=
secondDigest
.
digest
();
assertTrue
(
Arrays
.
equals
(
firstBytes
,
secondBytes
));
}
}
library/src/test/java/com/bumptech/glide/load/UnitTransformationTest.java
0 → 100644
浏览文件 @
0be7fb30
package
com.bumptech.glide.load
;
import
com.bumptech.glide.load.engine.Resource
;
import
org.junit.Test
;
import
static
junit
.
framework
.
Assert
.
assertEquals
;
import
static
org
.
mockito
.
Mockito
.
mock
;
public
class
UnitTransformationTest
{
@Test
public
void
testReturnsGivenResource
()
{
Resource
resource
=
mock
(
Resource
.
class
);
UnitTransformation
transformation
=
UnitTransformation
.
get
();
assertEquals
(
resource
,
transformation
.
transform
(
resource
,
10
,
10
));
}
@Test
public
void
testHasEmptyId
()
{
assertEquals
(
""
,
UnitTransformation
.
get
().
getId
());
}
}
\ No newline at end of file
library/src/test/java/com/bumptech/glide/load/engine/DefaultResourceRunnerFactoryTest.java
浏览文件 @
0be7fb30
...
...
@@ -2,7 +2,6 @@ package com.bumptech.glide.load.engine;
import
android.os.Handler
;
import
com.bumptech.glide.Priority
;
import
com.bumptech.glide.load.Key
;
import
com.bumptech.glide.load.ResourceDecoder
;
import
com.bumptech.glide.load.ResourceEncoder
;
import
com.bumptech.glide.load.Transformation
;
...
...
@@ -56,7 +55,7 @@ public class DefaultResourceRunnerFactoryTest {
boolean
isMemoryCacheable
;
public
ResourceRunner
build
()
{
return
factory
.
build
(
mock
(
Key
.
class
),
width
,
height
,
cacheDecoder
,
fetcher
,
decoder
,
transformation
,
return
factory
.
build
(
mock
(
Engine
Key
.
class
),
width
,
height
,
cacheDecoder
,
fetcher
,
decoder
,
transformation
,
encoder
,
mock
(
ResourceTranscoder
.
class
),
priority
,
isMemoryCacheable
,
listener
);
}
}
...
...
library/src/test/java/com/bumptech/glide/load/engine/EngineTest.java
浏览文件 @
0be7fb30
...
...
@@ -378,8 +378,8 @@ public class EngineTest {
@SuppressWarnings
(
"unchecked"
)
private
static
class
EngineTestHarness
{
Key
cacheKey
=
mock
(
Key
.
class
);
KeyFactory
keyFactory
=
mock
(
KeyFactory
.
class
);
EngineKey
cacheKey
=
mock
(
Engine
Key
.
class
);
EngineKeyFactory
keyFactory
=
mock
(
Engine
KeyFactory
.
class
);
ResourceDecoder
<
InputStream
,
Object
>
cacheDecoder
=
mock
(
ResourceDecoder
.
class
);
DataFetcher
<
Object
>
fetcher
=
mock
(
DataFetcher
.
class
);
ResourceDecoder
<
Object
,
Object
>
decoder
=
mock
(
ResourceDecoder
.
class
);
...
...
library/src/test/java/com/bumptech/glide/load/engine/ResourceRunnerTest.java
浏览文件 @
0be7fb30
...
...
@@ -178,7 +178,8 @@ public class ResourceRunnerTest {
@SuppressWarnings
(
"unchecked"
)
private
static
class
ResourceRunnerHarness
{
Key
key
=
mock
(
Key
.
class
);
EngineKey
key
=
mock
(
EngineKey
.
class
);
Key
originalKey
=
mock
(
Key
.
class
);
ResourceDecoder
<
InputStream
,
Object
>
decoder
=
mock
(
ResourceDecoder
.
class
);
SourceResourceRunner
<
Object
,
Object
,
Object
>
sourceRunner
=
mock
(
SourceResourceRunner
.
class
);
ResourceTranscoder
<
Object
,
Object
>
transcoder
=
mock
(
ResourceTranscoder
.
class
);
...
...
@@ -200,6 +201,7 @@ public class ResourceRunnerTest {
public
ResourceRunnerHarness
()
{
when
(
key
.
toString
()).
thenReturn
(
ID
);
when
(
key
.
getOriginalKey
()).
thenReturn
(
originalKey
);
when
(
resizeService
.
submit
(
eq
(
runner
))).
thenReturn
(
future
);
when
(
resizeService
.
submit
(
eq
(
sourceRunner
))).
thenReturn
(
sourceFuture
);
when
(
cacheLoader
.
load
(
eq
(
key
),
eq
(
decoder
),
eq
(
width
),
eq
(
height
))).
thenReturn
(
decoded
);
...
...
library/src/test/java/com/bumptech/glide/load/engine/SourceResourceRunnerTest.java
浏览文件 @
0be7fb30
package
com.bumptech.glide.load.engine
;
import
com.bumptech.glide.CacheLoader
;
import
com.bumptech.glide.Priority
;
import
com.bumptech.glide.load.Key
;
import
com.bumptech.glide.load.ResourceDecoder
;
...
...
@@ -12,6 +13,8 @@ import com.bumptech.glide.request.ResourceCallback;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.invocation.InvocationOnMock
;
import
org.mockito.stubbing.Answer
;
import
org.robolectric.RobolectricTestRunner
;
import
java.io.ByteArrayInputStream
;
...
...
@@ -28,6 +31,7 @@ import static org.mockito.Matchers.anyInt;
import
static
org
.
mockito
.
Matchers
.
anyObject
;
import
static
org
.
mockito
.
Matchers
.
eq
;
import
static
org
.
mockito
.
Matchers
.
isNull
;
import
static
org
.
mockito
.
Mockito
.
doAnswer
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
never
;
import
static
org
.
mockito
.
Mockito
.
verify
;
...
...
@@ -43,7 +47,53 @@ public class SourceResourceRunnerTest {
}
@Test
public
void
testResourceFetcherIsCalled
()
throws
Exception
{
public
void
testCacheLoaderIsCalledWithOriginalKey
()
{
harness
.
runner
.
run
();
verify
(
harness
.
cacheLoader
).
load
(
eq
(
harness
.
originalKey
),
eq
(
harness
.
cacheDecoder
),
eq
(
harness
.
width
),
eq
(
harness
.
height
));
}
@Test
public
void
testIfCacheLoaderReturnsOriginalResourceFetcherIsNotCalled
()
throws
Exception
{
when
(
harness
.
cacheLoader
.
load
(
eq
(
harness
.
originalKey
),
eq
(
harness
.
cacheDecoder
),
eq
(
harness
.
width
),
eq
(
harness
.
height
))).
thenReturn
(
harness
.
decoded
);
harness
.
runner
.
run
();
verify
(
harness
.
fetcher
,
never
()).
loadData
(
any
(
Priority
.
class
));
}
@Test
public
void
testIfCacheLoaderReturnsOriginalResourceThenOriginalResourceIsTransformedAndReturned
()
{
when
(
harness
.
cacheLoader
.
load
(
eq
(
harness
.
originalKey
),
eq
(
harness
.
cacheDecoder
),
eq
(
harness
.
width
),
eq
(
harness
.
height
))).
thenReturn
(
harness
.
decoded
);
harness
.
runner
.
run
();
verify
(
harness
.
cb
).
onResourceReady
(
eq
(
harness
.
transcoded
));
}
@Test
public
void
testEncoderIsCalledWithTransformedIfOriginalResourceInCache
()
{
when
(
harness
.
cacheLoader
.
load
(
eq
(
harness
.
originalKey
),
eq
(
harness
.
cacheDecoder
),
eq
(
harness
.
width
),
eq
(
harness
.
height
))).
thenReturn
(
harness
.
decoded
);
final
OutputStream
expected
=
new
ByteArrayOutputStream
();
doAnswer
(
new
Answer
<
Object
>()
{
@Override
public
Object
answer
(
InvocationOnMock
invocation
)
throws
Throwable
{
harness
.
runner
.
write
(
expected
);
return
null
;
}
}).
when
(
harness
.
diskCache
).
put
(
eq
(
harness
.
key
),
eq
(
harness
.
runner
));
harness
.
runner
.
run
();
verify
(
harness
.
encoder
).
encode
(
eq
(
harness
.
transformed
),
eq
(
expected
));
}
@Test
public
void
testResourceFetcherIsCalledIfOriginalNotInCache
()
throws
Exception
{
harness
.
runner
.
run
();
verify
(
harness
.
fetcher
).
loadData
(
eq
(
harness
.
priority
));
...
...
@@ -82,7 +132,7 @@ public class SourceResourceRunnerTest {
harness
.
runner
.
run
();
harness
.
runner
.
write
(
expected
);
verify
(
harness
.
encoder
).
encode
(
eq
(
harness
.
decod
ed
),
eq
(
expected
));
verify
(
harness
.
encoder
).
encode
(
eq
(
harness
.
transform
ed
),
eq
(
expected
));
}
@Test
...
...
@@ -146,6 +196,8 @@ public class SourceResourceRunnerTest {
InputStream
is
=
new
ByteArrayInputStream
(
new
byte
[
0
]);
when
(
harness
.
fetcher
.
loadData
(
eq
(
harness
.
priority
))).
thenReturn
(
is
);
when
(
harness
.
decoder
.
decode
(
eq
(
is
),
eq
(
harness
.
width
),
eq
(
harness
.
height
))).
thenReturn
(
harness
.
decoded
);
when
(
harness
.
transformation
.
transform
(
eq
(
harness
.
decoded
),
eq
(
harness
.
width
),
eq
(
harness
.
height
)))
.
thenReturn
(
harness
.
decoded
);
harness
.
runner
.
run
();
...
...
@@ -204,6 +256,8 @@ public class SourceResourceRunnerTest {
@SuppressWarnings
(
"unchecked"
)
private
static
class
SourceResourceHarness
{
CacheLoader
cacheLoader
=
mock
(
CacheLoader
.
class
);
ResourceDecoder
<
InputStream
,
Object
>
cacheDecoder
=
mock
(
ResourceDecoder
.
class
);
DataFetcher
<
Object
>
fetcher
=
mock
(
DataFetcher
.
class
);
ResourceDecoder
<
Object
,
Object
>
decoder
=
mock
(
ResourceDecoder
.
class
);
ResourceEncoder
<
Object
>
encoder
=
mock
(
ResourceEncoder
.
class
);
...
...
@@ -212,16 +266,22 @@ public class SourceResourceRunnerTest {
Priority
priority
=
Priority
.
LOW
;
ResourceCallback
cb
=
mock
(
ResourceCallback
.
class
);
Resource
<
Object
>
decoded
=
mock
(
Resource
.
class
);
Resource
<
Object
>
transformed
=
mock
(
Resource
.
class
);
Resource
<
Object
>
transcoded
=
mock
(
Resource
.
class
);
Transformation
<
Object
>
transformation
=
mock
(
Transformation
.
class
);
int
width
=
150
;
int
height
=
200
;
EngineKey
key
=
mock
(
EngineKey
.
class
);
Key
originalKey
=
mock
(
Key
.
class
);
SourceResourceRunner
<
Object
,
Object
,
Object
>
runner
=
new
SourceResourceRunner
<
Object
,
Object
,
Object
>(
mock
(
Key
.
class
),
width
,
height
,
fetcher
,
decoder
,
transformation
,
encoder
,
transcoder
,
diskCache
,
priority
,
cb
);
key
,
width
,
height
,
cacheLoader
,
cacheDecoder
,
fetcher
,
decoder
,
transformation
,
encoder
,
transcoder
,
diskCache
,
priority
,
cb
);
public
SourceResourceHarness
()
{
when
(
transformation
.
transform
(
eq
(
decoded
),
eq
(
width
),
eq
(
height
))).
thenReturn
(
decoded
);
when
(
key
.
getOriginalKey
()).
thenReturn
(
originalKey
);
when
(
transformation
.
transform
(
eq
(
decoded
),
eq
(
width
),
eq
(
height
))).
thenReturn
(
transformed
);
when
(
transcoder
.
transcode
(
eq
(
transformed
))).
thenReturn
(
transcoded
);
}
}
}
library/src/test/java/com/bumptech/glide/load/resource/transcode/UnitTranscoderTest.java
浏览文件 @
0be7fb30
package
com.bumptech.glide.load.resource.transcode
;
import
com.bumptech.glide.load.engine.Resource
;
import
com.bumptech.glide.tests.Util
;
import
org.junit.Test
;
import
static
junit
.
framework
.
Assert
.
assertEquals
;
...
...
@@ -18,8 +17,7 @@ public class UnitTranscoderTest {
}
@Test
public
void
testHas
Valid
Id
()
{
Util
.
assertClassHasValidId
(
UnitTranscoder
.
class
,
UnitTranscoder
.
get
().
getId
());
public
void
testHas
Empty
Id
()
{
assertEquals
(
""
,
UnitTranscoder
.
get
().
getId
());
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录