Repository: alibaba/fescar
Pull request #239 (2019-01-23 06:42:01)

add unit test for some request class
<!-- Please make sure you have read and understood the contributing guidelines -->

### Ⅰ. Describe what this PR did


### Ⅱ. Does this pull request fix one issue?
<!-- If that, add "fixes #xxx" below in the next line, for example, fixes #97. -->


### Ⅲ. Why don't you add test cases (unit test/integration test)? 


### Ⅳ. Describe how to verify it


### Ⅴ. Special notes for reviews



CLAassistant: [![CLA assistant check](https://cla-assistant.io/pull/badge/not_signed)](https://cla-assistant.io/alibaba/fescar?pullRequest=239) <br/>Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you all sign our [Contributor License Agreement](https://cla-assistant.io/alibaba/fescar?pullRequest=239) before we can accept your contribution.<br/>**1** out of **2** committers have signed the CLA.<br/><br/>:white_check_mark: xiajunhust<br/>:x: xiajun<br/><hr/>**xiajun** seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please [add the email address used for this commit to your account](https://help.github.com/articles/why-are-my-commits-linked-to-the-wrong-user/#commits-are-not-linked-to-any-user).<br/><sub>You have signed the CLA already but the status is still pending? Let us [recheck](https://cla-assistant.io/check/alibaba/fescar?pullRequest=239) it.</sub>
codecov-io: # [Codecov](https://codecov.io/gh/alibaba/fescar/pull/239?src=pr&el=h1) Report
> Merging [#239](https://codecov.io/gh/alibaba/fescar/pull/239?src=pr&el=desc) into [master](https://codecov.io/gh/alibaba/fescar/commit/e10063c0553d8020ae6efe83fdf8f9be00c11d1d?src=pr&el=desc) will **increase** coverage by `1.76%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/alibaba/fescar/pull/239/graphs/tree.svg?width=650&token=Hy9a6MCc4p&height=150&src=pr)](https://codecov.io/gh/alibaba/fescar/pull/239?src=pr&el=tree)

```diff
@@            Coverage Diff            @@
##           master    #239      +/-   ##
=========================================
+ Coverage    4.62%   6.39%   +1.76%     
=========================================
  Files         184     184              
  Lines        6763    6802      +39     
  Branches      932     932              
=========================================
+ Hits          313     435     +122     
+ Misses       6432    6349      -83     
  Partials       18      18
```


| [Impacted Files](https://codecov.io/gh/alibaba/fescar/pull/239?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [...protocol/transaction/AbstractBranchEndRequest.java](https://codecov.io/gh/alibaba/fescar/pull/239/diff?src=pr&el=tree#diff-Y29yZS9zcmMvbWFpbi9qYXZhL2NvbS9hbGliYWJhL2Zlc2Nhci9jb3JlL3Byb3RvY29sL3RyYW5zYWN0aW9uL0Fic3RyYWN0QnJhbmNoRW5kUmVxdWVzdC5qYXZh) | `29.78% <100%> (+29.78%)` | :arrow_up: |
| [...rotocol/transaction/AbstractBranchEndResponse.java](https://codecov.io/gh/alibaba/fescar/pull/239/diff?src=pr&el=tree#diff-Y29yZS9zcmMvbWFpbi9qYXZhL2NvbS9hbGliYWJhL2Zlc2Nhci9jb3JlL3Byb3RvY29sL3RyYW5zYWN0aW9uL0Fic3RyYWN0QnJhbmNoRW5kUmVzcG9uc2UuamF2YQ==) | `52% <100%> (+52%)` | :arrow_up: |
| [...re/protocol/transaction/BranchRegisterRequest.java](https://codecov.io/gh/alibaba/fescar/pull/239/diff?src=pr&el=tree#diff-Y29yZS9zcmMvbWFpbi9qYXZhL2NvbS9hbGliYWJhL2Zlc2Nhci9jb3JlL3Byb3RvY29sL3RyYW5zYWN0aW9uL0JyYW5jaFJlZ2lzdGVyUmVxdWVzdC5qYXZh) | `35.38% <100%> (+35.38%)` | :arrow_up: |
| [.../alibaba/fescar/core/protocol/AbstractMessage.java](https://codecov.io/gh/alibaba/fescar/pull/239/diff?src=pr&el=tree#diff-Y29yZS9zcmMvbWFpbi9qYXZhL2NvbS9hbGliYWJhL2Zlc2Nhci9jb3JlL3Byb3RvY29sL0Fic3RyYWN0TWVzc2FnZS5qYXZh) | `3.38% <0%> (+3.38%)` | :arrow_up: |
| [...tocol/transaction/AbstractTransactionResponse.java](https://codecov.io/gh/alibaba/fescar/pull/239/diff?src=pr&el=tree#diff-Y29yZS9zcmMvbWFpbi9qYXZhL2NvbS9hbGliYWJhL2Zlc2Nhci9jb3JlL3Byb3RvY29sL3RyYW5zYWN0aW9uL0Fic3RyYWN0VHJhbnNhY3Rpb25SZXNwb25zZS5qYXZh) | `12.5% <0%> (+12.5%)` | :arrow_up: |
| [...ba/fescar/core/protocol/AbstractResultMessage.java](https://codecov.io/gh/alibaba/fescar/pull/239/diff?src=pr&el=tree#diff-Y29yZS9zcmMvbWFpbi9qYXZhL2NvbS9hbGliYWJhL2Zlc2Nhci9jb3JlL3Byb3RvY29sL0Fic3RyYWN0UmVzdWx0TWVzc2FnZS5qYXZh) | `14.28% <0%> (+14.28%)` | :arrow_up: |
| [...core/protocol/transaction/BranchCommitRequest.java](https://codecov.io/gh/alibaba/fescar/pull/239/diff?src=pr&el=tree#diff-Y29yZS9zcmMvbWFpbi9qYXZhL2NvbS9hbGliYWJhL2Zlc2Nhci9jb3JlL3Byb3RvY29sL3RyYW5zYWN0aW9uL0JyYW5jaENvbW1pdFJlcXVlc3QuamF2YQ==) | `33.33% <0%> (+33.33%)` | :arrow_up: |
| ... and [8 more](https://codecov.io/gh/alibaba/fescar/pull/239/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/alibaba/fescar/pull/239?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/alibaba/fescar/pull/239?src=pr&el=footer). Last update [e10063c...0b4bab3](https://codecov.io/gh/alibaba/fescar/pull/239?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/core/src/main/java/com/alibaba/fescar/core/protocol/transaction/AbstractBranchEndRequest.java b/core/src/main/java/com/alibaba/fescar/core/protocol/transaction/AbstractBranchEndRequest.java
index e1385d587..d74e297ef 100644
--- a/core/src/main/java/com/alibaba/fescar/core/protocol/transaction/AbstractBranchEndRequest.java
+++ b/core/src/main/java/com/alibaba/fescar/core/protocol/transaction/AbstractBranchEndRequest.java
@@ -170,4 +170,25 @@ public abstract class AbstractBranchEndRequest extends AbstractTransactionReques
 
         return true;
     }
+    
+    @Override
+    public String toString() {
+        StringBuilder result = new StringBuilder();
+        result.append("xid=");
+        result.append(xid);
+        result.append(",");
+        result.append("branchId=");
+        result.append(branchId);
+        result.append(",");
+        result.append("branchType=");
+        result.append(branchType);
+        result.append(",");
+        result.append("resourceId=");
+        result.append(resourceId);
+        result.append(",");
+        result.append("applicationData=");
+        result.append(applicationData);
+
+        return result.toString();
+    }
 }
diff --git a/core/src/main/java/com/alibaba/fescar/core/protocol/transaction/AbstractBranchEndResponse.java b/core/src/main/java/com/alibaba/fescar/core/protocol/transaction/AbstractBranchEndResponse.java
index 7eb79ab06..d77f14b27 100644
--- a/core/src/main/java/com/alibaba/fescar/core/protocol/transaction/AbstractBranchEndResponse.java
+++ b/core/src/main/java/com/alibaba/fescar/core/protocol/transaction/AbstractBranchEndResponse.java
@@ -55,4 +55,19 @@ public abstract class AbstractBranchEndResponse extends AbstractTransactionRespo
         branchStatus = BranchStatus.get(in.readByte());
         return true;
     }
+    
+    @Override
+    public String toString() {
+        StringBuilder result = new StringBuilder();
+        result.append("branchStatus=");
+        result.append(branchStatus);
+        result.append(",");
+        result.append("result code =");
+        result.append(getResultCode());
+        result.append(",");
+        result.append("getMsg =");
+        result.append(getMsg());
+
+        return result.toString();
+    }
 }
diff --git a/core/src/main/java/com/alibaba/fescar/core/protocol/transaction/BranchRegisterRequest.java b/core/src/main/java/com/alibaba/fescar/core/protocol/transaction/BranchRegisterRequest.java
index dc0509dd2..f17f21a49 100644
--- a/core/src/main/java/com/alibaba/fescar/core/protocol/transaction/BranchRegisterRequest.java
+++ b/core/src/main/java/com/alibaba/fescar/core/protocol/transaction/BranchRegisterRequest.java
@@ -136,4 +136,22 @@ public class BranchRegisterRequest extends AbstractTransactionRequestToTC implem
     public AbstractTransactionResponse handle(RpcContext rpcContext) {
         return handler.handle(this, rpcContext);
     }
+    
+    @Override
+    public String toString() {
+        StringBuilder result = new StringBuilder();
+        result.append("transactionId=");
+        result.append(transactionId);
+        result.append(",");
+        result.append("branchType=");
+        result.append(branchType);
+        result.append(",");
+        result.append("resourceId=");
+        result.append(resourceId);
+        result.append(",");
+        result.append("lockKey=");
+        result.append(lockKey);
+
+        return result.toString();
+    }
 }


Test patch:
diff --git a/core/src/test/java/com/alibaba/fescar/core/message/BranchCommitRequestTest.java b/core/src/test/java/com/alibaba/fescar/core/message/BranchCommitRequestTest.java
new file mode 100644
index 000000000..554b62144
--- /dev/null
+++ b/core/src/test/java/com/alibaba/fescar/core/message/BranchCommitRequestTest.java
@@ -0,0 +1,29 @@
+package com.alibaba.fescar.core.message;
+
+import com.alibaba.fescar.core.model.BranchType;
+import com.alibaba.fescar.core.protocol.transaction.BranchCommitRequest;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author xiajun.0706@163.com
+ * @since 2019/1/23
+ */
+public class BranchCommitRequestTest {
+
+  @Test
+  public void toStringTest() throws Exception{
+    BranchCommitRequest branchCommitRequest = new BranchCommitRequest();
+
+    branchCommitRequest.setXid("127.0.0.1:9999:39875642");
+    branchCommitRequest.setBranchId(1);
+    branchCommitRequest.setBranchType(BranchType.AT);
+    branchCommitRequest.setResourceId("resource1");
+    branchCommitRequest.setApplicationData("app1");
+
+    Assert.assertEquals("xid=127.0.0.1:9999:39875642,branchId=1,branchType=AT,"
+                        + "resourceId=resource1,applicationData=app1", branchCommitRequest.toString());
+
+  }
+}
diff --git a/core/src/test/java/com/alibaba/fescar/core/message/BranchCommitResponseTest.java b/core/src/test/java/com/alibaba/fescar/core/message/BranchCommitResponseTest.java
new file mode 100644
index 000000000..943c04634
--- /dev/null
+++ b/core/src/test/java/com/alibaba/fescar/core/message/BranchCommitResponseTest.java
@@ -0,0 +1,28 @@
+package com.alibaba.fescar.core.message;
+
+import com.alibaba.fescar.core.model.BranchStatus;
+import com.alibaba.fescar.core.protocol.ResultCode;
+import com.alibaba.fescar.core.protocol.transaction.BranchCommitResponse;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author xiajun.0706@163.com
+ * @since 2019/1/23
+ */
+public class BranchCommitResponseTest {
+  @Test
+  public void toStringTest() throws Exception{
+    BranchCommitResponse branchCommitResponse = new BranchCommitResponse();
+
+    branchCommitResponse.setBranchStatus(BranchStatus.PhaseOne_Done);
+    branchCommitResponse.setResultCode(ResultCode.Success);
+    branchCommitResponse.setMsg("");
+
+    System.out.println(branchCommitResponse.toString());
+
+    Assert.assertEquals("branchStatus=PhaseOne_Done,result code =Success,getMsg =", branchCommitResponse.toString());
+
+  }
+}
diff --git a/core/src/test/java/com/alibaba/fescar/core/message/BranchRegisterRequestTest.java b/core/src/test/java/com/alibaba/fescar/core/message/BranchRegisterRequestTest.java
new file mode 100644
index 000000000..7b3c271d6
--- /dev/null
+++ b/core/src/test/java/com/alibaba/fescar/core/message/BranchRegisterRequestTest.java
@@ -0,0 +1,28 @@
+package com.alibaba.fescar.core.message;
+
+import com.alibaba.fescar.core.model.BranchType;
+import com.alibaba.fescar.core.protocol.transaction.BranchRegisterRequest;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author xiajun.0706@163.com
+ * @since 2019/1/23
+ */
+public class BranchRegisterRequestTest {
+  @Test
+  public void toStringTest() throws Exception{
+    BranchRegisterRequest branchRegisterRequest = new BranchRegisterRequest();
+
+    branchRegisterRequest.setTransactionId(123456);
+    branchRegisterRequest.setBranchType(BranchType.AT);
+    branchRegisterRequest.setResourceId("resource1");
+    branchRegisterRequest.setLockKey("lock_key_1");
+
+    System.out.println(branchRegisterRequest.toString());
+
+    Assert.assertEquals("transactionId=123456,branchType=AT,resourceId=resource1,lockKey=lock_key_1", branchRegisterRequest.toString());
+
+  }
+}