Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
佳 邓
Gitlab4j Api
Commits
acb7de3e
Commit
acb7de3e
authored
6 years ago
by
Greg Messner
Browse files
Options
Download
Email Patches
Plain Diff
Added methods to return the JSON for both the item and list.
parent
529d54a6
main
5.0.x
5.0.x.jdk17
6.x
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/test/java/org/gitlab4j/api/FakeResponse.java
+24
-17
src/test/java/org/gitlab4j/api/FakeResponse.java
with
24 additions
and
17 deletions
+24
-17
src/test/java/org/gitlab4j/api/FakeResponse.java
+
24
-
17
View file @
acb7de3e
package
org.gitlab4j.api
;
package
org.gitlab4j.api
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayInputStream
;
import
java.io.InputStreamReader
;
import
java.util.List
;
import
java.util.List
;
import
javax.ws.rs.core.GenericType
;
import
javax.ws.rs.core.GenericType
;
import
javax.ws.rs.core.Response
;
import
javax.ws.rs.core.Response
;
/**
/**
* This class can be used as a spy for Mockito to test the individual APIs
getXxxxx() methods without the
* This class can be used as a spy for Mockito to test the individual APIs
* need to have a GitLab server available.
*
getXxxxx() methods without the
need to have a GitLab server available.
*
*
* Supports getXxxxx() methods that return a List of items, single items, and Optional items.
* Supports getXxxxx() methods that return a List of items, single items,
* Optional items, and Pagers of items.
*/
*/
public
abstract
class
FakeResponse
extends
Response
{
public
abstract
class
FakeResponse
extends
Response
{
private
List
<?>
responseList
;
private
List
<?>
responseList
;
private
ByteArrayInputStream
responseInputStream
;
private
Object
responseItem
;
private
Object
responseItem
;
private
int
perPage
=
20
;
private
int
perPage
=
20
;
private
String
itemJson
;
private
String
listJson
;
public
<
T
>
void
init
(
Class
<
T
>
type
,
String
itemFilename
,
String
listFilename
)
throws
Exception
{
public
<
T
>
void
init
(
Class
<
T
>
type
,
String
itemFilename
,
String
listFilename
)
throws
Exception
{
if
(
itemFilename
!=
null
)
{
if
(
itemFilename
!=
null
)
{
InputStreamReader
reader
=
new
InputStreamReader
(
TestGitLabApiBeans
.
class
.
getResourceAsStream
(
itemFilename
)
)
;
itemJson
=
JsonUtils
.
readResource
(
itemFilename
);
responseItem
=
JsonUtils
.
unmarshal
(
type
,
reader
);
responseItem
=
JsonUtils
.
unmarshal
(
type
,
itemJson
);
}
else
{
}
else
{
responseItem
=
null
;
responseItem
=
null
;
}
}
if
(
listFilename
!=
null
)
{
if
(
listFilename
!=
null
)
{
String
listJson
=
JsonUtils
.
readResource
(
listFilename
);
listJson
=
JsonUtils
.
readResource
(
listFilename
);
responseList
=
(
List
<?>)
JsonUtils
.
unmarshalList
(
type
,
listJson
);
responseList
=
(
List
<?>)
JsonUtils
.
unmarshalList
(
type
,
listJson
);
responseInputStream
=
new
ByteArrayInputStream
(
listJson
.
getBytes
());
}
else
{
}
else
{
responseList
=
null
;
responseList
=
null
;
responseInputStream
=
null
;
}
}
}
}
public
String
getItemJson
()
{
return
(
itemJson
);
}
public
String
getListJson
()
{
return
(
listJson
);
}
public
void
setPerPageHeaderValue
(
int
perPage
)
{
public
void
setPerPageHeaderValue
(
int
perPage
)
{
this
.
perPage
=
perPage
;
this
.
perPage
=
perPage
;
}
}
// The below methods allow this abstract class to act as a fake Resource
// instance.
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
@Override
@Override
public
<
T
>
T
readEntity
(
GenericType
<
T
>
entityType
)
{
public
<
T
>
T
readEntity
(
GenericType
<
T
>
entityType
)
{
...
@@ -57,12 +68,7 @@ public abstract class FakeResponse extends Response {
...
@@ -57,12 +68,7 @@ public abstract class FakeResponse extends Response {
@Override
@Override
public
Object
getEntity
()
{
public
Object
getEntity
()
{
if
(
responseInputStream
==
null
)
{
return
(
listJson
!=
null
?
new
ByteArrayInputStream
(
listJson
.
getBytes
())
:
null
);
return
(
null
);
}
responseInputStream
.
reset
();
return
(
responseInputStream
);
}
}
@Override
@Override
...
@@ -72,7 +78,8 @@ public abstract class FakeResponse extends Response {
...
@@ -72,7 +78,8 @@ public abstract class FakeResponse extends Response {
return
(
responseList
!=
null
?
Integer
.
toString
(
perPage
)
:
"0"
);
return
(
responseList
!=
null
?
Integer
.
toString
(
perPage
)
:
"0"
);
case
Constants
.
TOTAL_PAGES_HEADER
:
case
Constants
.
TOTAL_PAGES_HEADER
:
return
(
responseList
!=
null
?
Integer
.
toString
((
int
)
Math
.
ceil
((
double
)
responseList
.
size
()
/
20.0
))
:
"0"
);
return
(
responseList
!=
null
?
Integer
.
toString
((
int
)
Math
.
ceil
((
double
)
responseList
.
size
()
/
20.0
))
:
"0"
);
case
Constants
.
TOTAL_HEADER
:
case
Constants
.
TOTAL_HEADER
:
return
(
responseList
!=
null
?
Integer
.
toString
(
responseList
.
size
())
:
"0"
);
return
(
responseList
!=
null
?
Integer
.
toString
(
responseList
.
size
())
:
"0"
);
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets