Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wd1105040417
retrofit
提交
5b188b5d
R
retrofit
项目概览
wd1105040417
/
retrofit
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
retrofit
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5b188b5d
编写于
8月 31, 2012
作者:
P
Patrick Forhan
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #52 from square/jw/tests
Re-enable 'android' and 'io' tests. Switch to FEST.
上级
312b0e02
3ad08752
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
233 addition
and
183 deletion
+233
-183
android/pom.xml
android/pom.xml
+5
-0
android/src/test/java/retrofit/android/ShakeDetectorTest.java
...oid/src/test/java/retrofit/android/ShakeDetectorTest.java
+17
-17
http/pom.xml
http/pom.xml
+5
-0
http/src/test/java/retrofit/http/FetcherTest.java
http/src/test/java/retrofit/http/FetcherTest.java
+14
-10
http/src/test/java/retrofit/http/HttpRequestBuilderTest.java
http/src/test/java/retrofit/http/HttpRequestBuilderTest.java
+33
-32
http/src/test/java/retrofit/http/RestAdapterTest.java
http/src/test/java/retrofit/http/RestAdapterTest.java
+45
-27
io/pom.xml
io/pom.xml
+5
-0
io/src/test/java/retrofit/io/FilesTest.java
io/src/test/java/retrofit/io/FilesTest.java
+14
-13
io/src/test/java/retrofit/io/QueueFileTest.java
io/src/test/java/retrofit/io/QueueFileTest.java
+53
-54
io/src/test/java/retrofit/io/TypedByteArrayTest.java
io/src/test/java/retrofit/io/TypedByteArrayTest.java
+12
-10
io/src/test/java/retrofit/io/TypedFileTest.java
io/src/test/java/retrofit/io/TypedFileTest.java
+16
-15
io/src/test/java/retrofit/io/internal/ObjectsTest.java
io/src/test/java/retrofit/io/internal/ObjectsTest.java
+8
-5
pom.xml
pom.xml
+6
-0
未找到文件。
android/pom.xml
浏览文件 @
5b188b5d
...
...
@@ -31,6 +31,11 @@
<artifactId>
junit
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.easytesting
</groupId>
<artifactId>
fest-assert
</artifactId>
<scope>
test
</scope>
</dependency>
</dependencies>
<build>
...
...
android/src/test/java/retrofit/android/ShakeDetectorTest.java
浏览文件 @
5b188b5d
...
...
@@ -2,21 +2,21 @@
package
retrofit.android
;
import
org.junit.Test
;
import
java.util.List
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
fest
.
assertions
.
Assertions
.
assertThat
;
/** @author Eric Burke (eric@squareup.com) */
public
class
ShakeDetectorTest
{
public
void
testInitialShaking
()
{
@Test
public
void
testInitialShaking
()
{
ShakeDetector
.
SampleQueue
q
=
new
ShakeDetector
.
SampleQueue
();
assert
False
(
"shaking"
,
q
.
isShaking
()
);
assert
That
(
q
.
isShaking
()).
isFalse
(
);
}
/** Tests LG Ally sample rate. */
public
void
testShakingSampleCount3
()
{
@Test
public
void
testShakingSampleCount3
()
{
ShakeDetector
.
SampleQueue
q
=
new
ShakeDetector
.
SampleQueue
();
// These times approximate the data rate of the slowest device we've
...
...
@@ -29,26 +29,26 @@ public class ShakeDetectorTest {
q
.
add
(
1600000000L
,
false
);
q
.
add
(
1900000000L
,
false
);
assertContent
(
q
,
false
,
false
,
false
,
false
);
assert
False
(
"shaking"
,
q
.
isShaking
()
);
assert
That
(
q
.
isShaking
()).
isFalse
(
);
// The oldest two entries will be removed.
q
.
add
(
2200000000L
,
true
);
q
.
add
(
2500000000L
,
true
);
assertContent
(
q
,
false
,
false
,
true
,
true
);
assert
False
(
"shaking"
,
q
.
isShaking
()
);
assert
That
(
q
.
isShaking
()).
isFalse
(
);
// Another entry should be removed, now 3 out of 4 are true.
q
.
add
(
2800000000L
,
true
);
assertContent
(
q
,
false
,
true
,
true
,
true
);
assertT
rue
(
"shaking"
,
q
.
isShaking
()
);
assertT
hat
(
q
.
isShaking
()).
isTrue
(
);
q
.
add
(
3100000000L
,
false
);
assertContent
(
q
,
true
,
true
,
true
,
false
);
assertT
rue
(
"shaking"
,
q
.
isShaking
()
);
assertT
hat
(
q
.
isShaking
()).
isTrue
(
);
q
.
add
(
3400000000L
,
false
);
assertContent
(
q
,
true
,
true
,
false
,
false
);
assert
False
(
"shaking"
,
q
.
isShaking
()
);
assert
That
(
q
.
isShaking
()).
isFalse
(
);
}
private
void
assertContent
(
ShakeDetector
.
SampleQueue
q
,
boolean
...
expected
)
{
...
...
@@ -59,20 +59,20 @@ public class ShakeDetectorTest {
sb
.
append
(
String
.
format
(
"[%b,%d] "
,
s
.
accelerating
,
s
.
timestamp
));
}
assert
Equals
(
sb
.
toString
(),
expected
.
length
,
samples
.
size
());
assert
That
(
samples
.
size
()).
isEqualTo
(
expected
.
length
).
as
(
sb
.
toString
());
for
(
int
i
=
0
;
i
<
expected
.
length
;
i
++)
{
assert
Equals
(
"sample["
+
i
+
"] accelerating"
,
expected
[
i
],
samples
.
get
(
i
).
accelerating
);
assert
That
(
samples
.
get
(
i
).
accelerating
).
isEqualTo
(
expected
[
i
])
.
as
(
"sample["
+
i
+
"] accelerating"
);
}
}
public
void
testClear
()
{
@Test
public
void
testClear
()
{
ShakeDetector
.
SampleQueue
q
=
new
ShakeDetector
.
SampleQueue
();
q
.
add
(
1000000000L
,
true
);
q
.
add
(
1200000000L
,
true
);
q
.
add
(
1400000000L
,
true
);
assertT
rue
(
"shaking"
,
q
.
isShaking
()
);
assertT
hat
(
q
.
isShaking
()).
isTrue
(
);
q
.
clear
();
assert
False
(
"shaking"
,
q
.
isShaking
()
);
assert
That
(
q
.
isShaking
()).
isFalse
(
);
}
}
http/pom.xml
浏览文件 @
5b188b5d
...
...
@@ -43,6 +43,11 @@
<artifactId>
junit
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.easytesting
</groupId>
<artifactId>
fest-assert
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.easymock
</groupId>
<artifactId>
easymock
</artifactId>
...
...
http/src/test/java/retrofit/http/FetcherTest.java
浏览文件 @
5b188b5d
...
...
@@ -3,13 +3,13 @@ package retrofit.http;
import
com.google.gson.Gson
;
import
junit.framework.Assert
;
import
junit.framework.TestCase
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.HttpResponse
;
import
org.apache.http.StatusLine
;
import
org.apache.http.client.HttpClient
;
import
org.apache.http.client.ResponseHandler
;
import
org.apache.http.client.methods.HttpUriRequest
;
import
org.junit.Test
;
import
retrofit.io.ByteSink
;
import
javax.inject.Provider
;
...
...
@@ -19,14 +19,20 @@ import java.io.InputStream;
import
java.util.Arrays
;
import
java.util.concurrent.Executor
;
import
static
org
.
easymock
.
EasyMock
.*;
import
static
org
.
easymock
.
EasyMock
.
anyInt
;
import
static
org
.
easymock
.
EasyMock
.
createMock
;
import
static
org
.
easymock
.
EasyMock
.
expect
;
import
static
org
.
easymock
.
EasyMock
.
expectLastCall
;
import
static
org
.
easymock
.
EasyMock
.
replay
;
import
static
org
.
easymock
.
EasyMock
.
verify
;
import
static
org
.
fest
.
assertions
.
Assertions
.
assertThat
;
/**
* Fetcher test cases.
*
* @author Bob Lee (bob@squareup.com)
*/
public
class
FetcherTest
extends
TestCase
{
public
class
FetcherTest
{
private
static
final
String
URL
=
"http://crazybob.org/"
;
...
...
@@ -39,7 +45,7 @@ public class FetcherTest extends TestCase {
private
ProgressListener
progressListener
=
createMock
(
ProgressListener
.
class
);
public
void
testSuccessfulFetch
()
throws
Exception
{
@Test
public
void
testSuccessfulFetch
()
throws
Exception
{
DummyInputStream
in
=
new
DummyInputStream
();
final
SingletonHttpClient
httpClient
=
new
SingletonHttpClient
(
response
);
DummyExecutor
executor
=
new
DummyExecutor
();
...
...
@@ -65,12 +71,10 @@ public class FetcherTest extends TestCase {
fetcher
.
fetch
(
URL
,
sinkFactory
,
callback
,
progressListener
);
verifyAll
();
assertEquals
(
1
,
executor
.
calls
);
assertTrue
(
uiThread
.
calls
>
1
);
// result + progress updates
assertEquals
(
1
,
httpClient
.
calls
);
byte
[]
output
=
sink
.
toArray
();
assertTrue
(
"Expected {1, 2, 3}. Got "
+
Arrays
.
toString
(
output
),
Arrays
.
equals
(
new
byte
[]
{
1
,
2
,
3
},
output
));
assertThat
(
executor
.
calls
).
isEqualTo
(
1
);
assertThat
(
uiThread
.
calls
).
isGreaterThan
(
1
);
// result + progress updates
assertThat
(
httpClient
.
calls
).
isEqualTo
(
1
);
assertThat
(
sink
.
toArray
()).
isEqualTo
(
new
byte
[]
{
1
,
2
,
3
});
}
private
void
replayAll
()
{
...
...
http/src/test/java/retrofit/http/HttpRequestBuilderTest.java
浏览文件 @
5b188b5d
...
...
@@ -2,20 +2,24 @@
package
retrofit.http
;
import
com.google.gson.Gson
;
import
org.apache.http.HttpMessage
;
import
org.apache.http.client.methods.HttpGet
;
import
org.apache.http.client.methods.HttpPut
;
import
org.apache.http.client.methods.HttpUriRequest
;
import
org.junit.Test
;
import
javax.inject.Named
;
import
java.io.ByteArrayOutputStream
;
import
java.lang.reflect.Method
;
import
java.net.URISyntaxException
;
import
java.util.Set
;
import
java.util.UUID
;
import
javax.inject.Named
;
import
junit.framework.TestCase
;
import
org.apache.http.HttpMessage
;
import
org.apache.http.client.methods.HttpGet
;
import
org.apache.http.client.methods.HttpPut
;
import
org.apache.http.client.methods.HttpUriRequest
;
import
static
org
.
fest
.
assertions
.
Assertions
.
assertThat
;
import
static
org
.
fest
.
assertions
.
Fail
.
fail
;
/** @author Eric Denman (edenman@squareup.com) */
public
class
HttpRequestBuilderTest
extends
TestCase
{
public
class
HttpRequestBuilderTest
{
public
static
final
String
API_URL
=
"http://taqueria.com/lengua/taco"
;
public
static
final
Headers
BLANK_HEADERS
=
new
Headers
()
{
@Override
public
void
setOn
(
HttpMessage
message
,
String
mimeType
)
{
...
...
@@ -36,28 +40,28 @@ public class HttpRequestBuilderTest extends TestCase {
private
void
expectParams
(
String
path
,
String
...
expected
)
{
Set
<
String
>
calculated
=
HttpRequestBuilder
.
getPathParameters
(
path
);
assert
Equals
(
expected
.
length
,
calculated
.
size
()
);
assert
That
(
calculated
.
size
()).
isEqualTo
(
expected
.
length
);
for
(
String
val
:
expected
)
{
assertT
rue
(
calculated
.
contains
(
val
)
);
assertT
hat
(
calculated
).
contains
(
val
);
}
}
public
void
testNormalGet
()
throws
Exception
{
@Test
public
void
testNormalGet
()
throws
Exception
{
Method
method
=
MyService
.
class
.
getMethod
(
"normalGet"
,
String
.
class
,
Callback
.
class
);
String
expectedId
=
UUID
.
randomUUID
().
toString
();
Object
[]
args
=
new
Object
[]
{
expectedId
,
new
MyCallback
()};
HttpUriRequest
request
=
build
(
method
,
args
);
assertT
rue
(
request
instanceof
HttpGet
);
assertT
hat
(
request
).
isInstanceOf
(
HttpGet
.
class
);
HttpGet
put
=
(
HttpGet
)
request
;
// Make sure the url param got translated.
final
String
uri
=
put
.
getURI
().
toString
();
assert
Equals
(
API_URL
+
"/foo/bar?id="
+
expectedId
,
uri
);
assert
That
(
uri
).
isEqualTo
(
API_URL
+
"/foo/bar?id="
+
expectedId
);
}
public
void
testGetWithPathParam
()
throws
Exception
{
@Test
public
void
testGetWithPathParam
()
throws
Exception
{
Method
method
=
MyService
.
class
.
getMethod
(
"getWithPathParam"
,
String
.
class
,
String
.
class
,
Callback
.
class
);
String
expectedId
=
UUID
.
randomUUID
().
toString
();
...
...
@@ -65,15 +69,15 @@ public class HttpRequestBuilderTest extends TestCase {
Object
[]
args
=
new
Object
[]
{
expectedId
,
category
,
new
MyCallback
()};
HttpUriRequest
request
=
build
(
method
,
args
);
assertT
rue
(
request
instanceof
HttpGet
);
assertT
hat
(
request
).
isInstanceOf
(
HttpGet
.
class
);
HttpGet
put
=
(
HttpGet
)
request
;
// Make sure the url param got translated.
final
String
uri
=
put
.
getURI
().
toString
();
assert
Equals
(
API_URL
+
"/foo/"
+
expectedId
+
"/bar?category="
+
category
,
uri
);
assert
That
(
uri
).
isEqualTo
(
API_URL
+
"/foo/"
+
expectedId
+
"/bar?category="
+
category
);
}
public
void
testSingleEntityWithPathParams
()
throws
Exception
{
@Test
public
void
testSingleEntityWithPathParams
()
throws
Exception
{
Method
method
=
MyService
.
class
.
getMethod
(
"singleEntityPut"
,
MyJsonObj
.
class
,
String
.
class
,
Callback
.
class
);
String
expectedId
=
UUID
.
randomUUID
().
toString
();
...
...
@@ -81,21 +85,21 @@ public class HttpRequestBuilderTest extends TestCase {
Object
[]
args
=
new
Object
[]
{
new
MyJsonObj
(
bodyText
),
expectedId
,
new
MyCallback
()};
HttpUriRequest
request
=
build
(
method
,
args
);
assertT
rue
(
request
instanceof
HttpPut
);
assertT
hat
(
request
).
isInstanceOf
(
HttpPut
.
class
);
HttpPut
put
=
(
HttpPut
)
request
;
// Make sure the url param got translated.
final
String
uri
=
put
.
getURI
().
toString
();
assert
Equals
(
API_URL
+
"/foo/bar/"
+
expectedId
,
uri
);
assert
That
(
uri
).
isEqualTo
(
API_URL
+
"/foo/bar/"
+
expectedId
);
// Make sure the request body has the json string.
ByteArrayOutputStream
out
=
new
ByteArrayOutputStream
();
put
.
getEntity
().
writeTo
(
out
);
final
String
requestBody
=
out
.
toString
();
assert
Equals
(
"{\"bodyText\":\""
+
bodyText
+
"\"}"
,
requestBody
);
assert
That
(
requestBody
).
isEqualTo
(
"{\"bodyText\":\""
+
bodyText
+
"\"}"
);
}
public
void
testNormalPutWithPathParams
()
throws
Exception
{
@Test
public
void
testNormalPutWithPathParams
()
throws
Exception
{
Method
method
=
MyService
.
class
.
getMethod
(
"normalPut"
,
String
.
class
,
String
.
class
,
Callback
.
class
);
String
expectedId
=
UUID
.
randomUUID
().
toString
();
...
...
@@ -103,21 +107,21 @@ public class HttpRequestBuilderTest extends TestCase {
Object
[]
args
=
new
Object
[]
{
expectedId
,
bodyText
,
new
MyCallback
()};
HttpUriRequest
request
=
build
(
method
,
args
);
assertT
rue
(
request
instanceof
HttpPut
);
assertT
hat
(
request
).
isInstanceOf
(
HttpPut
.
class
);
HttpPut
put
=
(
HttpPut
)
request
;
// Make sure the url param got translated.
final
String
uri
=
put
.
getURI
().
toString
();
assert
Equals
(
API_URL
+
"/foo/bar/"
+
expectedId
,
uri
);
assert
That
(
uri
).
isEqualTo
(
API_URL
+
"/foo/bar/"
+
expectedId
);
// Make sure the request body has the json string.
ByteArrayOutputStream
out
=
new
ByteArrayOutputStream
();
put
.
getEntity
().
writeTo
(
out
);
final
String
requestBody
=
out
.
toString
();
assert
Equals
(
"id="
+
expectedId
+
"&body="
+
bodyText
,
requestBody
);
assert
That
(
requestBody
).
isEqualTo
(
"id="
+
expectedId
+
"&body="
+
bodyText
);
}
public
void
testSingleEntityWithTooManyParams
()
throws
Exception
{
@Test
public
void
testSingleEntityWithTooManyParams
()
throws
Exception
{
Method
method
=
MyService
.
class
.
getMethod
(
"tooManyParams"
,
MyJsonObj
.
class
,
String
.
class
,
String
.
class
,
Callback
.
class
);
...
...
@@ -127,12 +131,11 @@ public class HttpRequestBuilderTest extends TestCase {
try
{
build
(
method
,
args
);
fail
(
"Didn't throw exception with too many params"
);
}
catch
(
IllegalArgumentException
e
)
{
// Expected
}
catch
(
IllegalArgumentException
expected
)
{
}
}
public
void
testSingleEntityWithNoPathParam
()
throws
Exception
{
@Test
public
void
testSingleEntityWithNoPathParam
()
throws
Exception
{
Method
method
=
MyService
.
class
.
getMethod
(
"singleEntityNoPathParam"
,
MyJsonObj
.
class
,
Callback
.
class
);
String
bodyText
=
UUID
.
randomUUID
().
toString
();
...
...
@@ -140,20 +143,18 @@ public class HttpRequestBuilderTest extends TestCase {
try
{
build
(
method
,
args
);
fail
(
"Didn't throw exception with too few params"
);
}
catch
(
IllegalArgumentException
e
)
{
// Expected
}
catch
(
IllegalArgumentException
expected
)
{
}
}
public
void
testRegularWithNoPathParam
()
throws
Exception
{
@Test
public
void
testRegularWithNoPathParam
()
throws
Exception
{
Method
method
=
MyService
.
class
.
getMethod
(
"regularNoPathParam"
,
String
.
class
,
Callback
.
class
);
String
otherParam
=
UUID
.
randomUUID
().
toString
();
Object
[]
args
=
new
Object
[]
{
otherParam
,
new
MyCallback
()};
try
{
build
(
method
,
args
);
fail
(
"Didn't throw exception with too few params"
);
}
catch
(
IllegalArgumentException
e
)
{
// Expected
}
catch
(
IllegalArgumentException
expected
)
{
}
}
...
...
http/src/test/java/retrofit/http/RestAdapterTest.java
浏览文件 @
5b188b5d
package
retrofit.http
;
import
com.google.gson.Gson
;
import
java.io.IOException
;
import
java.io.UnsupportedEncodingException
;
import
java.util.concurrent.Executor
;
import
javax.inject.Named
;
import
javax.inject.Provider
;
import
junit.framework.TestCase
;
import
org.apache.http.HttpMessage
;
import
org.apache.http.HttpResponse
;
import
org.apache.http.ProtocolVersion
;
...
...
@@ -21,6 +15,13 @@ import org.apache.http.message.BasicStatusLine;
import
org.easymock.Capture
;
import
org.easymock.IAnswer
;
import
org.junit.Before
;
import
org.junit.Test
;
import
javax.inject.Named
;
import
javax.inject.Provider
;
import
java.io.IOException
;
import
java.io.UnsupportedEncodingException
;
import
java.util.concurrent.Executor
;
import
static
org
.
easymock
.
EasyMock
.
capture
;
import
static
org
.
easymock
.
EasyMock
.
createMock
;
...
...
@@ -29,8 +30,9 @@ import static org.easymock.EasyMock.expectLastCall;
import
static
org
.
easymock
.
EasyMock
.
isA
;
import
static
org
.
easymock
.
EasyMock
.
replay
;
import
static
org
.
easymock
.
EasyMock
.
verify
;
import
static
org
.
fest
.
assertions
.
Assertions
.
assertThat
;
public
class
RestAdapterTest
extends
TestCase
{
public
class
RestAdapterTest
{
private
static
final
String
ID
=
"123"
;
private
static
final
String
ENTITY
=
"entity"
;
private
static
final
String
ENTITY_PATH_PARAM
=
"entity/{id}"
;
...
...
@@ -47,7 +49,7 @@ public class RestAdapterTest extends TestCase {
private
HttpResponse
mockResponse
;
private
Gson
gson
=
new
Gson
();
@
Override
@
Before
public
void
setUp
()
throws
Exception
{
@Before
public
void
setUp
()
throws
Exception
{
mockHttpClient
=
createMock
(
HttpClient
.
class
);
mockExecutor
=
createMock
(
Executor
.
class
);
mockMainThread
=
createMock
(
MainThread
.
class
);
...
...
@@ -65,7 +67,8 @@ public class RestAdapterTest extends TestCase {
mockHeaders
,
gson
,
HttpProfiler
.
NONE
);
}
@SuppressWarnings
(
"unchecked"
)
public
void
testServiceDeleteSimple
()
throws
IOException
{
@SuppressWarnings
(
"unchecked"
)
@Test
public
void
testServiceDeleteSimple
()
throws
IOException
{
expectLifecycle
(
HttpDelete
.
class
,
GET_DELETE_SIMPLE_URL
);
replayAll
();
...
...
@@ -74,7 +77,8 @@ public class RestAdapterTest extends TestCase {
verifyAll
();
}
@SuppressWarnings
(
"unchecked"
)
public
void
testServiceDeleteParam
()
throws
IOException
{
@SuppressWarnings
(
"unchecked"
)
@Test
public
void
testServiceDeleteParam
()
throws
IOException
{
expectLifecycle
(
HttpDelete
.
class
,
GET_DELETE_SIMPLE_URL
+
"id="
+
ID
);
replayAll
();
...
...
@@ -83,7 +87,8 @@ public class RestAdapterTest extends TestCase {
verifyAll
();
}
@SuppressWarnings
(
"unchecked"
)
public
void
testServiceDeleteWithFixedParam
()
throws
IOException
{
@SuppressWarnings
(
"unchecked"
)
@Test
public
void
testServiceDeleteWithFixedParam
()
throws
IOException
{
expectLifecycle
(
HttpDelete
.
class
,
GET_DELETE_SIMPLE_URL
+
"filter=merchant&"
+
"id="
+
ID
);
replayAll
();
...
...
@@ -94,7 +99,7 @@ public class RestAdapterTest extends TestCase {
}
@SuppressWarnings
(
"unchecked"
)
public
void
testServiceDeleteWithMultipleFixedParam
()
throws
IOException
{
@Test
public
void
testServiceDeleteWithMultipleFixedParam
()
throws
IOException
{
expectLifecycle
(
HttpDelete
.
class
,
GET_DELETE_SIMPLE_URL
+
"filter=merchant&name2=value2&"
+
"id="
+
ID
);
replayAll
();
...
...
@@ -104,7 +109,8 @@ public class RestAdapterTest extends TestCase {
verifyAll
();
}
@SuppressWarnings
(
"unchecked"
)
public
void
testServiceDeletePathParam
()
throws
IOException
{
@SuppressWarnings
(
"unchecked"
)
@Test
public
void
testServiceDeletePathParam
()
throws
IOException
{
expectLifecycle
(
HttpDelete
.
class
,
PATH_URL_PREFIX
+
ID
+
"?"
);
replayAll
();
...
...
@@ -113,7 +119,8 @@ public class RestAdapterTest extends TestCase {
verifyAll
();
}
@SuppressWarnings
(
"unchecked"
)
public
void
testServiceGetSimple
()
throws
IOException
{
@SuppressWarnings
(
"unchecked"
)
@Test
public
void
testServiceGetSimple
()
throws
IOException
{
expectLifecycle
(
HttpGet
.
class
,
GET_DELETE_SIMPLE_URL
);
replayAll
();
...
...
@@ -122,7 +129,8 @@ public class RestAdapterTest extends TestCase {
verifyAll
();
}
@SuppressWarnings
(
"unchecked"
)
public
void
testServiceGetParam
()
throws
IOException
{
@SuppressWarnings
(
"unchecked"
)
@Test
public
void
testServiceGetParam
()
throws
IOException
{
expectLifecycle
(
HttpGet
.
class
,
GET_DELETE_SIMPLE_URL
+
"id="
+
ID
);
replayAll
();
...
...
@@ -131,7 +139,8 @@ public class RestAdapterTest extends TestCase {
verifyAll
();
}
@SuppressWarnings
(
"unchecked"
)
public
void
testServiceGetWithFixedParam
()
throws
IOException
{
@SuppressWarnings
(
"unchecked"
)
@Test
public
void
testServiceGetWithFixedParam
()
throws
IOException
{
expectLifecycle
(
HttpGet
.
class
,
GET_DELETE_SIMPLE_URL
+
"filter=merchant&"
+
"id="
+
ID
);
replayAll
();
...
...
@@ -142,7 +151,7 @@ public class RestAdapterTest extends TestCase {
}
@SuppressWarnings
(
"unchecked"
)
public
void
testServiceGetWithMultipleFixedParams
()
throws
IOException
{
@Test
public
void
testServiceGetWithMultipleFixedParams
()
throws
IOException
{
expectLifecycle
(
HttpGet
.
class
,
GET_DELETE_SIMPLE_URL
+
"filter=merchant&name2=value2&"
+
"id="
+
ID
);
replayAll
();
...
...
@@ -152,7 +161,8 @@ public class RestAdapterTest extends TestCase {
verifyAll
();
}
@SuppressWarnings
(
"unchecked"
)
public
void
testServiceGetPathParam
()
throws
IOException
{
@SuppressWarnings
(
"unchecked"
)
@Test
public
void
testServiceGetPathParam
()
throws
IOException
{
expectLifecycle
(
HttpGet
.
class
,
PATH_URL_PREFIX
+
ID
+
"?"
);
replayAll
();
...
...
@@ -161,7 +171,8 @@ public class RestAdapterTest extends TestCase {
verifyAll
();
}
@SuppressWarnings
(
"unchecked"
)
public
void
testServicePostSimple
()
throws
IOException
{
@SuppressWarnings
(
"unchecked"
)
@Test
public
void
testServicePostSimple
()
throws
IOException
{
expectLifecycle
(
HttpPost
.
class
,
BASE_URL
);
replayAll
();
...
...
@@ -170,7 +181,8 @@ public class RestAdapterTest extends TestCase {
verifyAll
();
}
@SuppressWarnings
(
"unchecked"
)
public
void
testServicePostSimpleClientError
()
throws
IOException
{
@SuppressWarnings
(
"unchecked"
)
@Test
public
void
testServicePostSimpleClientError
()
throws
IOException
{
expectLifecycleClientError
(
HttpPost
.
class
,
BASE_URL
);
replayAll
();
...
...
@@ -179,7 +191,8 @@ public class RestAdapterTest extends TestCase {
verifyAll
();
}
@SuppressWarnings
(
"unchecked"
)
public
void
testServicePostSimpleServerError
()
throws
IOException
{
@SuppressWarnings
(
"unchecked"
)
@Test
public
void
testServicePostSimpleServerError
()
throws
IOException
{
expectLifecycleServerError
(
HttpPost
.
class
,
BASE_URL
);
replayAll
();
...
...
@@ -188,7 +201,8 @@ public class RestAdapterTest extends TestCase {
verifyAll
();
}
@SuppressWarnings
(
"unchecked"
)
public
void
testServicePostParam
()
throws
IOException
{
@SuppressWarnings
(
"unchecked"
)
@Test
public
void
testServicePostParam
()
throws
IOException
{
expectLifecycle
(
HttpPost
.
class
,
BASE_URL
);
replayAll
();
...
...
@@ -197,7 +211,8 @@ public class RestAdapterTest extends TestCase {
verifyAll
();
}
@SuppressWarnings
(
"unchecked"
)
public
void
testServicePostPathParam
()
throws
IOException
{
@SuppressWarnings
(
"unchecked"
)
@Test
public
void
testServicePostPathParam
()
throws
IOException
{
expectLifecycle
(
HttpPost
.
class
,
PATH_URL_PREFIX
+
ID
);
replayAll
();
...
...
@@ -206,7 +221,8 @@ public class RestAdapterTest extends TestCase {
verifyAll
();
}
@SuppressWarnings
(
"unchecked"
)
public
void
testServicePutSimple
()
throws
IOException
{
@SuppressWarnings
(
"unchecked"
)
@Test
public
void
testServicePutSimple
()
throws
IOException
{
expectLifecycle
(
HttpPut
.
class
,
BASE_URL
);
replayAll
();
...
...
@@ -215,7 +231,8 @@ public class RestAdapterTest extends TestCase {
verifyAll
();
}
@SuppressWarnings
(
"unchecked"
)
public
void
testServicePutParam
()
throws
IOException
{
@SuppressWarnings
(
"unchecked"
)
@Test
public
void
testServicePutParam
()
throws
IOException
{
expectLifecycle
(
HttpPut
.
class
,
BASE_URL
);
replayAll
();
...
...
@@ -224,7 +241,8 @@ public class RestAdapterTest extends TestCase {
verifyAll
();
}
@SuppressWarnings
(
"unchecked"
)
public
void
testServicePutPathParam
()
throws
IOException
{
@SuppressWarnings
(
"unchecked"
)
@Test
public
void
testServicePutPathParam
()
throws
IOException
{
expectLifecycle
(
HttpPut
.
class
,
PATH_URL_PREFIX
+
ID
);
replayAll
();
...
...
@@ -319,7 +337,7 @@ public class RestAdapterTest extends TestCase {
expectLastCall
().
andAnswer
(
new
IAnswer
<
Object
>()
{
@Override
public
Object
answer
()
throws
Throwable
{
T
request
=
expectedRequestClass
.
cast
(
capture
.
getValue
());
assert
Equals
(
"uri should match expectations"
,
expectedUri
,
request
.
getURI
().
toString
()
);
assert
That
(
request
.
getURI
().
toString
()).
isEqualTo
(
expectedUri
);
return
null
;
}
});
...
...
io/pom.xml
浏览文件 @
5b188b5d
...
...
@@ -29,6 +29,11 @@
<artifactId>
junit
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.easytesting
</groupId>
<artifactId>
fest-assert
</artifactId>
<scope>
test
</scope>
</dependency>
</dependencies>
<build>
...
...
io/src/test/java/retrofit/io/FilesTest.java
浏览文件 @
5b188b5d
// Copyright 2011 Square, Inc.
package
retrofit.io
;
import
org.junit.Test
;
import
java.io.File
;
import
java.io.FileWriter
;
import
java.io.PrintWriter
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assert
.
fail
;
import
static
org
.
fest
.
assertions
.
Assertions
.
assertThat
;
import
static
org
.
fest
.
assertions
.
Fail
.
fail
;
/**
* @author Paul Hawke (psh@squareup.com)
*/
public
class
FilesTest
{
public
void
testDelete
()
throws
Exception
{
@Test
public
void
testDelete
()
throws
Exception
{
File
tmpFile
=
File
.
createTempFile
(
"prefix"
,
".tmp"
);
PrintWriter
pw
=
new
PrintWriter
(
new
FileWriter
(
tmpFile
));
pw
.
println
(
"content"
);
pw
.
close
();
assertT
rue
(
tmpFile
.
exists
()
);
assertT
rue
(
Files
.
delete
(
tmpFile
)
);
assert
False
(
tmpFile
.
exists
()
);
assertT
hat
(
tmpFile
.
exists
()).
isTrue
(
);
assertT
hat
(
Files
.
delete
(
tmpFile
)).
isTrue
(
);
assert
That
(
tmpFile
.
exists
()).
isFalse
(
);
}
public
void
testDeleteFileThatDoesntExist
()
throws
Exception
{
@Test
public
void
testDeleteFileThatDoesntExist
()
throws
Exception
{
File
tmpFile
=
File
.
createTempFile
(
"foobar"
,
".tmp"
);
assertT
rue
(
"unable to delete temporary file"
,
tmpFile
.
delete
()
);
assertT
hat
(
tmpFile
.
delete
()).
as
(
"unable to delete temporary file"
).
isTrue
(
);
assert
False
(
tmpFile
.
exists
()
);
assertT
rue
(
Files
.
delete
(
tmpFile
)
);
assert
False
(
tmpFile
.
exists
()
);
assert
That
(
tmpFile
.
exists
()).
isFalse
(
);
assertT
hat
(
Files
.
delete
(
tmpFile
)).
isTrue
(
);
assert
That
(
tmpFile
.
exists
()).
isFalse
(
);
}
public
void
testDeleteNullFile
()
throws
Exception
{
@Test
public
void
testDeleteNullFile
()
throws
Exception
{
try
{
Files
.
delete
(
null
);
fail
(
"Expected an IAE"
);
...
...
io/src/test/java/retrofit/io/QueueFileTest.java
浏览文件 @
5b188b5d
...
...
@@ -3,6 +3,7 @@ package retrofit.io;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
...
...
@@ -13,7 +14,7 @@ import java.util.LinkedList;
import
java.util.Queue
;
import
java.util.logging.Logger
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
fest
.
assertions
.
Assertions
.
assertThat
;
import
static
org
.
junit
.
Assert
.
fail
;
/**
...
...
@@ -30,7 +31,7 @@ public class QueueFileTest {
* Takes up 33401 bytes in the queue (N*(N+1)/2+4*N). Picked 254 instead of
* 255 so that the number of bytes isn't a multiple of 4.
*/
private
static
int
N
=
254
;
//
private
static
int
N
=
254
;
private
static
byte
[][]
values
=
new
byte
[
N
][];
static
{
...
...
@@ -44,27 +45,27 @@ public class QueueFileTest {
private
File
file
;
@Before
p
rotected
void
setUp
()
throws
Exception
{
@Before
p
ublic
void
setUp
()
throws
Exception
{
file
=
File
.
createTempFile
(
"test.queue"
,
null
);
file
.
delete
();
}
@After
p
rotected
void
tearDown
()
throws
Exception
{
@After
p
ublic
void
tearDown
()
throws
Exception
{
file
.
delete
();
}
public
void
testAddOneElement
()
throws
IOException
{
@Test
public
void
testAddOneElement
()
throws
IOException
{
// This test ensures that we update 'first' correctly.
QueueFile
queue
=
new
QueueFile
(
file
);
byte
[]
expected
=
values
[
253
];
queue
.
add
(
expected
);
assert
Equals
(
expected
,
queue
.
peek
()
);
assert
That
(
queue
.
peek
()).
isEqualTo
(
expected
);
queue
.
close
();
queue
=
new
QueueFile
(
file
);
assert
Equals
(
expected
,
queue
.
peek
()
);
assert
That
(
queue
.
peek
()).
isEqualTo
(
expected
);
}
public
void
testAddAndRemoveElements
()
throws
IOException
{
@Test
public
void
testAddAndRemoveElements
()
throws
IOException
{
long
start
=
System
.
nanoTime
();
Queue
<
byte
[]>
expected
=
new
LinkedList
<
byte
[]>();
...
...
@@ -79,7 +80,7 @@ public class QueueFileTest {
// Leave N elements in round N, 15 total for 5 rounds. Removing all the
// elements would be like starting with an empty queue.
for
(
int
i
=
0
;
i
<
N
-
round
-
1
;
i
++)
{
assert
Equals
(
expected
.
remove
(),
queue
.
peek
());
assert
That
(
queue
.
peek
()).
isEqualTo
(
expected
.
remove
());
queue
.
remove
();
}
queue
.
close
();
...
...
@@ -87,10 +88,10 @@ public class QueueFileTest {
// Remove and validate remaining 15 elements.
QueueFile
queue
=
new
QueueFile
(
file
);
assert
Equals
(
15
,
queue
.
size
()
);
assert
Equals
(
expected
.
size
(),
queue
.
size
());
assert
That
(
queue
.
size
()).
isEqualTo
(
15
);
assert
That
(
queue
.
size
()).
isEqualTo
(
expected
.
size
());
while
(!
expected
.
isEmpty
())
{
assert
Equals
(
expected
.
remove
(),
queue
.
peek
());
assert
That
(
queue
.
peek
()).
isEqualTo
(
expected
.
remove
());
queue
.
remove
();
}
queue
.
close
();
...
...
@@ -102,7 +103,7 @@ public class QueueFileTest {
}
/** Tests queue expansion when the data crosses EOF. */
public
void
testSplitExpansion
()
throws
IOException
{
@Test
public
void
testSplitExpansion
()
throws
IOException
{
// This should result in 3560 bytes.
int
max
=
80
;
...
...
@@ -116,7 +117,7 @@ public class QueueFileTest {
// Remove all but 1.
for
(
int
i
=
1
;
i
<
max
;
i
++)
{
assert
Equals
(
expected
.
remove
(),
queue
.
peek
());
assert
That
(
queue
.
peek
()).
isEqualTo
(
expected
.
remove
());
queue
.
remove
();
}
...
...
@@ -127,14 +128,14 @@ public class QueueFileTest {
}
while
(!
expected
.
isEmpty
())
{
assert
Equals
(
expected
.
remove
(),
queue
.
peek
());
assert
That
(
queue
.
peek
()).
isEqualTo
(
expected
.
remove
());
queue
.
remove
();
}
queue
.
close
();
}
public
void
testFailedAdd
()
throws
IOException
{
@Test
public
void
testFailedAdd
()
throws
IOException
{
QueueFile
queueFile
=
new
QueueFile
(
file
);
queueFile
.
add
(
values
[
253
]);
queueFile
.
close
();
...
...
@@ -155,13 +156,13 @@ public class QueueFileTest {
queueFile
.
close
();
queueFile
=
new
QueueFile
(
file
);
assert
Equals
(
2
,
queueFile
.
size
()
);
assert
Equals
(
values
[
253
],
queueFile
.
peek
()
);
assert
That
(
queueFile
.
size
()).
isEqualTo
(
2
);
assert
That
(
queueFile
.
peek
()).
isEqualTo
(
values
[
253
]
);
queueFile
.
remove
();
assert
Equals
(
values
[
251
],
queueFile
.
peek
()
);
assert
That
(
queueFile
.
peek
()).
isEqualTo
(
values
[
251
]
);
}
public
void
testFailedRemoval
()
throws
IOException
{
@Test
public
void
testFailedRemoval
()
throws
IOException
{
QueueFile
queueFile
=
new
QueueFile
(
file
);
queueFile
.
add
(
values
[
253
]);
queueFile
.
close
();
...
...
@@ -177,15 +178,15 @@ public class QueueFileTest {
queueFile
.
close
();
queueFile
=
new
QueueFile
(
file
);
assert
Equals
(
1
,
queueFile
.
size
()
);
assert
Equals
(
values
[
253
],
queueFile
.
peek
()
);
assert
That
(
queueFile
.
size
()).
isEqualTo
(
1
);
assert
That
(
queueFile
.
peek
()).
isEqualTo
(
values
[
253
]
);
queueFile
.
add
(
values
[
99
]);
queueFile
.
remove
();
assert
Equals
(
values
[
99
],
queueFile
.
peek
()
);
assert
That
(
queueFile
.
peek
()).
isEqualTo
(
values
[
99
]
);
}
public
void
testFailedExpansion
()
throws
IOException
{
@Test
public
void
testFailedExpansion
()
throws
IOException
{
QueueFile
queueFile
=
new
QueueFile
(
file
);
queueFile
.
add
(
values
[
253
]);
queueFile
.
close
();
...
...
@@ -203,16 +204,16 @@ public class QueueFileTest {
queueFile
=
new
QueueFile
(
file
);
assert
Equals
(
1
,
queueFile
.
size
()
);
assert
Equals
(
values
[
253
],
queueFile
.
peek
()
);
assert
Equals
(
4096
,
queueFile
.
fileLength
);
assert
That
(
queueFile
.
size
()).
isEqualTo
(
1
);
assert
That
(
queueFile
.
peek
()).
isEqualTo
(
values
[
253
]
);
assert
That
(
queueFile
.
fileLength
).
isEqualTo
(
4096
);
queueFile
.
add
(
values
[
99
]);
queueFile
.
remove
();
assert
Equals
(
values
[
99
],
queueFile
.
peek
()
);
assert
That
(
queueFile
.
peek
()).
isEqualTo
(
values
[
99
]
);
}
public
void
testPeekWithElementReader
()
throws
IOException
{
@Test
public
void
testPeekWithElementReader
()
throws
IOException
{
QueueFile
queueFile
=
new
QueueFile
(
file
);
final
byte
[]
a
=
{
1
,
2
};
queueFile
.
add
(
a
);
...
...
@@ -221,19 +222,19 @@ public class QueueFileTest {
queueFile
.
peek
(
new
QueueFile
.
ElementReader
()
{
@Override
public
void
read
(
InputStream
in
,
int
length
)
throws
IOException
{
assert
Equals
(
length
,
2
);
assert
That
(
length
).
isEqualTo
(
2
);
byte
[]
actual
=
new
byte
[
length
];
in
.
read
(
actual
);
assert
Equals
(
a
,
actual
);
assert
That
(
actual
).
isEqualTo
(
a
);
}
});
queueFile
.
peek
(
new
QueueFile
.
ElementReader
()
{
@Override
public
void
read
(
InputStream
in
,
int
length
)
throws
IOException
{
assert
Equals
(
length
,
2
);
assert
Equals
(
1
,
in
.
read
()
);
assert
Equals
(
2
,
in
.
read
()
);
assert
Equals
(-
1
,
in
.
read
()
);
assert
That
(
length
).
isEqualTo
(
2
);
assert
That
(
in
.
read
()).
isEqualTo
(
1
);
assert
That
(
in
.
read
()).
isEqualTo
(
2
);
assert
That
(
in
.
read
()).
isEqualTo
(-
1
);
}
});
...
...
@@ -241,18 +242,18 @@ public class QueueFileTest {
queueFile
.
peek
(
new
QueueFile
.
ElementReader
()
{
@Override
public
void
read
(
InputStream
in
,
int
length
)
throws
IOException
{
assert
Equals
(
length
,
3
);
assert
That
(
length
).
isEqualTo
(
3
);
byte
[]
actual
=
new
byte
[
length
];
in
.
read
(
actual
);
assert
Equals
(
b
,
actual
);
assert
That
(
actual
).
isEqualTo
(
b
);
}
});
assert
Equals
(
b
,
queueFile
.
peek
()
);
assert
Equals
(
1
,
queueFile
.
size
()
);
assert
That
(
queueFile
.
peek
()).
isEqualTo
(
b
);
assert
That
(
queueFile
.
size
()).
isEqualTo
(
1
);
}
public
void
testForEach
()
throws
IOException
{
@Test
public
void
testForEach
()
throws
IOException
{
QueueFile
queueFile
=
new
QueueFile
(
file
);
final
byte
[]
a
=
{
1
,
2
};
...
...
@@ -264,15 +265,15 @@ public class QueueFileTest {
QueueFile
.
ElementReader
elementReader
=
new
QueueFile
.
ElementReader
()
{
@Override
public
void
read
(
InputStream
in
,
int
length
)
throws
IOException
{
if
(
iteration
[
0
]
==
0
)
{
assert
Equals
(
length
,
2
);
assert
That
(
length
).
isEqualTo
(
2
);
byte
[]
actual
=
new
byte
[
length
];
in
.
read
(
actual
);
assert
Equals
(
a
,
actual
);
assert
That
(
actual
).
isEqualTo
(
a
);
}
else
if
(
iteration
[
0
]
==
1
)
{
assert
Equals
(
length
,
3
);
assert
That
(
length
).
isEqualTo
(
3
);
byte
[]
actual
=
new
byte
[
length
];
in
.
read
(
actual
);
assert
Equals
(
b
,
actual
);
assert
That
(
actual
).
isEqualTo
(
b
);
}
else
{
fail
();
}
...
...
@@ -282,8 +283,8 @@ public class QueueFileTest {
queueFile
.
forEach
(
elementReader
);
assert
Equals
(
a
,
queueFile
.
peek
()
);
assert
Equals
(
2
,
iteration
[
0
]
);
assert
That
(
queueFile
.
peek
()).
isEqualTo
(
a
);
assert
That
(
iteration
[
0
]).
isEqualTo
(
2
);
}
/**
...
...
@@ -291,7 +292,7 @@ public class QueueFileTest {
* QueueFile was forced to expand in size and a portion of the final Element
* had been wrapped into space at the beginning of the file.
*/
public
void
testFileExpansionDoesntCorruptWrappedElements
()
@Test
public
void
testFileExpansionDoesntCorruptWrappedElements
()
throws
IOException
{
QueueFile
queue
=
new
QueueFile
(
file
);
...
...
@@ -326,9 +327,8 @@ public class QueueFileTest {
queue
.
remove
();
for
(
int
i
=
0
;
i
<
value
.
length
;
i
++)
{
assertEquals
(
"Block "
+
(
blockNum
+
1
)
+
" corrupted at byte index "
+
i
,
(
byte
)
(
blockNum
+
1
),
value
[
i
]);
assertThat
(
value
[
i
]).
isEqualTo
((
byte
)
(
blockNum
+
1
))
.
as
(
"Block "
+
(
blockNum
+
1
)
+
" corrupted at byte index "
+
i
);
}
}
...
...
@@ -342,7 +342,7 @@ public class QueueFileTest {
* Elements have been written to empty buffer space at the start does the
* expansion correctly update all their positions?
*/
public
void
testFileExpansionCorrectlyMovesElements
()
throws
IOException
{
@Test
public
void
testFileExpansionCorrectlyMovesElements
()
throws
IOException
{
QueueFile
queue
=
new
QueueFile
(
file
);
// Create test data - 1k blocks marked consecutively 1, 2, 3, 4 and 5.
...
...
@@ -394,9 +394,8 @@ public class QueueFileTest {
queue
.
remove
();
for
(
int
i
=
0
;
i
<
value
.
length
;
i
++)
{
assertEquals
(
"Block "
+
(
expectedBlockNumber
)
+
" corrupted at byte index "
+
i
,
expectedBlockNumber
,
value
[
i
]);
assertThat
(
value
[
i
]).
isEqualTo
(
expectedBlockNumber
)
.
as
(
"Block "
+
expectedBlockNumber
+
" corrupted at byte index "
+
i
);
}
}
...
...
io/src/test/java/retrofit/io/TypedByteArrayTest.java
浏览文件 @
5b188b5d
// Copyright 2010 Square, Inc.
package
retrofit.io
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
org.junit.Test
;
import
static
org
.
fest
.
assertions
.
Assertions
.
assertThat
;
/** @author Eric Burke (eric@squareup.com) */
public
class
TypedByteArrayTest
{
public
void
testEquals
()
{
TypedByteArray
a1
=
new
TypedByteArray
(
new
byte
[]{
10
,
20
},
MimeType
.
GIF
);
TypedByteArray
a2
=
new
TypedByteArray
(
new
byte
[]{
10
,
20
},
MimeType
.
GIF
);
TypedByteArray
b
=
new
TypedByteArray
(
new
byte
[]{
8
,
12
},
MimeType
.
GIF
);
@Test
public
void
testEquals
()
{
TypedByteArray
a1
=
new
TypedByteArray
(
new
byte
[]{
10
,
20
},
MimeType
.
GIF
);
TypedByteArray
a2
=
new
TypedByteArray
(
new
byte
[]{
10
,
20
},
MimeType
.
GIF
);
TypedByteArray
b
=
new
TypedByteArray
(
new
byte
[]{
8
,
12
},
MimeType
.
GIF
);
assert
Equals
(
"equals"
,
a1
,
a2
);
assert
Equals
(
"hashCode"
,
a1
.
hashCode
(),
a2
.
hashCode
());
assert
False
(
"equals"
,
a1
.
equals
(
b
)
);
assert
False
(
"hashCode"
,
a1
.
hashCode
()
==
b
.
hashCode
());
assert
That
(
a1
).
isEqualTo
(
a2
);
assert
That
(
a1
.
hashCode
()).
isEqualTo
(
a2
.
hashCode
());
assert
That
(
a1
).
isNotEqualTo
(
b
);
assert
That
(
a1
.
hashCode
()).
isNotEqualTo
(
b
.
hashCode
());
}
}
io/src/test/java/retrofit/io/TypedFileTest.java
浏览文件 @
5b188b5d
// Copyright 2010 Square, Inc.
package
retrofit.io
;
import
org.junit.Test
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
fest
.
assertions
.
Assertions
.
assertThat
;
/** @author Eric Burke (eric@squareup.com) */
public
class
TypedFileTest
{
public
void
testNotEquals
()
{
@Test
public
void
testNotEquals
()
{
TypedFile
a
=
new
TypedFile
(
new
File
(
"a.png"
),
MimeType
.
PNG
);
TypedFile
b
=
new
TypedFile
(
new
File
(
"b.png"
),
MimeType
.
PNG
);
assert
False
(
"equals"
,
a
.
equals
(
b
)
);
assert
False
(
"hash code"
,
a
.
hashCode
()
==
b
.
hashCode
());
assert
That
(
a
).
isNotEqualTo
(
b
);
assert
That
(
a
.
hashCode
()).
isNotEqualTo
(
b
.
hashCode
());
}
public
void
testEquals
()
{
@Test
public
void
testEquals
()
{
TypedFile
a1
=
new
TypedFile
(
new
File
(
"a.png"
),
MimeType
.
PNG
);
TypedFile
a2
=
new
TypedFile
(
new
File
(
"a.png"
),
MimeType
.
PNG
);
assert
Equals
(
a1
,
a2
);
assert
Equals
(
"hash code"
,
a1
.
hashCode
(),
a2
.
hashCode
());
assert
That
(
a1
).
isEqualTo
(
a2
);
assert
That
(
a1
.
hashCode
()).
isEqualTo
(
a2
.
hashCode
());
}
public
void
testToString
()
{
@Test
public
void
testToString
()
{
File
file
=
new
File
(
"/path/to/file.png"
);
assert
Equals
(
file
.
getAbsolutePath
()
+
" (PNG)"
,
new
TypedFile
(
file
,
MimeType
.
PNG
).
toString
()
);
assert
That
(
new
TypedFile
(
file
,
MimeType
.
PNG
).
toString
())
.
isEqualTo
(
file
.
getAbsolutePath
()
+
" (PNG)"
);
}
public
void
testLength
()
throws
IOException
{
@Test
public
void
testLength
()
throws
IOException
{
File
tempFile
=
File
.
createTempFile
(
"foo"
,
".tmp"
);
try
{
TypedFile
typedFile
=
new
TypedFile
(
tempFile
,
MimeType
.
PNG
);
assert
Equals
(
"length"
,
0
,
typedFile
.
length
()
);
assert
That
(
typedFile
.
length
()).
isZero
(
);
writeToFile
(
tempFile
,
new
byte
[]{
0
,
1
,
2
,
3
,
4
});
assert
Equals
(
"file length"
,
5
,
tempFile
.
length
()
);
assert
Equals
(
"typed file length"
,
5
,
typedFile
.
length
()
);
assert
That
(
tempFile
.
length
()).
isEqualTo
(
5
);
assert
That
(
typedFile
.
length
()).
isEqualTo
(
5
);
}
finally
{
//noinspection ResultOfMethodCallIgnored
...
...
io/src/test/java/retrofit/io/internal/ObjectsTest.java
浏览文件 @
5b188b5d
// Copyright 2010 Square, Inc.
package
retrofit.io.internal
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
fail
;
import
org.junit.Test
;
import
static
org
.
fest
.
assertions
.
Assertions
.
assertThat
;
import
static
org
.
fest
.
assertions
.
Fail
.
fail
;
/** @author Eric Burke (eric@squareup.com) */
public
class
ObjectsTest
{
public
void
testNonNull
()
{
@Test
public
void
testNonNull
()
{
Objects
.
nonNull
(
10
,
"whatever"
);
String
message
=
"fail"
;
try
{
Objects
.
nonNull
(
null
,
"fail"
);
Objects
.
nonNull
(
null
,
message
);
fail
(
"Expected NullPointerException"
);
}
catch
(
NullPointerException
expected
)
{
assert
Equals
(
"fail"
,
expected
.
getMessage
()
);
assert
That
(
expected
.
getMessage
()).
isEqualTo
(
message
);
}
}
}
pom.xml
浏览文件 @
5b188b5d
...
...
@@ -59,6 +59,7 @@
<!-- Test Dependencies -->
<junit.version>
4.10
</junit.version>
<fest.version>
1.4
</fest.version>
<easymock.version>
3.1
</easymock.version>
</properties>
...
...
@@ -138,6 +139,11 @@
<artifactId>
junit
</artifactId>
<version>
${junit.version}
</version>
</dependency>
<dependency>
<groupId>
org.easytesting
</groupId>
<artifactId>
fest-assert
</artifactId>
<version>
${fest.version}
</version>
</dependency>
</dependencies>
</dependencyManagement>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录