Skip to content

Commit 28657fa

Browse files
feat(responsetemplate): add isPending method
centralnicgroup-public/hexonet-api-documentation#1
1 parent d951e59 commit 28657fa

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/main/java/net/hexonet/apiconnector/ResponseTemplate.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,17 @@ public boolean isTmpError() {
121121
String code = (String) this.hash.get("CODE");
122122
return code.charAt(0) == '4';
123123
}
124+
125+
/**
126+
* Check if current operation is returned as pending
127+
*
128+
* @return boolean result
129+
*/
130+
public boolean isPending() {
131+
String pending = (String) this.hash.get("PENDING");
132+
if (pending != null) {
133+
return pending.equals("1");
134+
}
135+
return false;
136+
}
124137
}

src/test/java/net/hexonet/apiconnector/ResponseTemplateTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,23 @@ public void getRuntime2() {
6666
"[RESPONSE]\r\ncode=423\r\ndescription=Empty API response\r\nruntime=0.12\r\nEOF\r\n");
6767
assertEquals(0.12, tpl.getRuntime(), 0);
6868
}
69+
70+
/**
71+
* Test isPending method #1
72+
*/
73+
@Test
74+
public void isPending1() {
75+
ResponseTemplate tpl = new ResponseTemplate("");
76+
assertEquals(false, tpl.isPending());
77+
}
78+
79+
/**
80+
* Test isPending method #2
81+
*/
82+
@Test
83+
public void isPending2() {
84+
ResponseTemplate tpl = new ResponseTemplate(
85+
"[RESPONSE]\r\ncode=423\r\ndescription=Empty API response\r\npending=1\r\nEOF\r\n");
86+
assertEquals(true, tpl.isPending());
87+
}
6988
}

0 commit comments

Comments
 (0)