Skip to content

Term Balance Object#40

Merged
natsuki-yamanaka merged 18 commits intomasterfrom
nyamanaka/term-balance
Apr 11, 2024
Merged

Term Balance Object#40
natsuki-yamanaka merged 18 commits intomasterfrom
nyamanaka/term-balance

Conversation

@natsuki-yamanaka
Copy link
Copy Markdown
Contributor

@natsuki-yamanaka natsuki-yamanaka commented Mar 27, 2024

The following actions uses node12 which is deprecated and will be forced to run on node16: actions/checkout@v2, actions/setup-java@v2. For more info: https://github.blog/changelog/2023-06-13-github-actions-all-actions-will-run-on-node16-instead-of-node12-by-default/
- uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v2
uses: actions/setup-java@v4
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

直近のactionsで下記のメッセージが出てた
The following actions uses node12 which is deprecated and will be forced to run on node16: actions/checkout@v2, actions/setup-java@v2. For more info: https://github.blog/changelog/2023-06-13-github-actions-all-actions-will-run-on-node16-instead-of-node12-by-default/

String json = resource("term_event.json");
Event e = gson.fromJson(json, Event.class);

assertEquals(Term.class, e.getData().getClass());
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PayjpObjectDeserializerにTermへの変換を追加しないとPayjpObjectになってこれが落ちる


public class BalanceTest extends BasePayjpTest {
@Test
public void testDeserialize() throws PayjpException, IOException {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

テストで確かめているのは

  • レスポンスJSONが指定のオブジェクトに変換される
  • 子供のオブジェクトがあればそれも想定の型に変換される
  • リクエストURLが /v1/balances/:id , /v1/balances である

あたり

Comment on lines +45 to +47
assertEquals("tm_b92b879e60f62b532d6756ae12aa", term.getId());
assertEquals(Long.valueOf("1438354812"), term.getCreated());
assertEquals((Integer)987, term.getChargeCount());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

大した数ではないので Term オブジェクトの中身全部チェックしてもいいかと思います。
getter のテストということで。逆にここで動いていれば他の箇所は全チェックはなくてもよい。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert足しました。BalanceTestも。
ついでに目についたとこリファクタと、listのリクエスト先URLがおかしいバグが見つかったので修正しました

Comment on lines +67 to +69
Term term = terms.get(0);
String id = term.getId();
assertEquals(id, "term1");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

List のテストなので中身2つ作ってテストしてもいいとは思いました。

{
  "count": 2,
  "data": [
    {"id": "term1"},
    {"id": "term2"},
  ]
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

足しました

Comment on lines +46 to +51
assertEquals("ba_b92b879e60f62b532d6756ae56af", balance.getId());
assertEquals(Long.valueOf("1438354824"), balance.getCreated());
assertEquals(BigInteger.valueOf(Long.valueOf("12300000000")), balance.getNet());
StatementCollection statements = balance.getStatements();
assertEquals("st_178fd25dc7ab7b75906f1c3c4b0e6", statements.getData().get(0).getId());
assertEquals("st_b4a569b0122a7d08b358f198cf263", statements.getData().get(1).getId());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

全チェックしてもいいのではと思いました。
テストしない理由があれば聞いておきたいです。
bank_info とか null ありえますよね。そういうテストのほうが大事な気がしました。

Comment on lines +55 to +57
public BankInfo getBankInfo() {
return bankInfo;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bank_info は null があり得るので、ぬるぽ出ませんかね?

balance.getBankInfo().getBankCode()

他にも該当するコードはありそう。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GSONでのシリアライズ時点では出ないです。一応ローカルのbalance.jsonに "bank_info": null 書いて確かめましたがbalance.getBankInfo()でもnullが返ってくるだけ。
Javaのプリミティブ型以外は全部nullがあり得るのでその先のnull考慮は使用者の責任かと。
以降のnullの話も同じくです

Comment on lines +55 to +57
objectMap.put("term", Term.class);
objectMap.put("statement", Statement.class);
objectMap.put("balance", Balance.class);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tab と space 気になったけどどっちに揃えるのがいいんでしょう。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4スペースが多そう

現状いろんなとこで入り混じってるので揃えるなら別PRにしてlinter入れたい

Comment on lines +51 to +53
public String getDueDate() {
return dueDate;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここも null ありえそうですが、String のメソッド使えないくらいなので影響はそれほどなんですかね。
これは質問の割合のほうが大きいです。

Comment on lines +66 to +74
public void testList() throws PayjpException {
Map<String, Object> listParams = new HashMap<String, Object>();
listParams.put("limit", 1);
stubNetwork(BalanceCollection.class, "{\"count\":1,\"data\":[{\"id\":\"balance1\"}]}");
List<Balance> balances = Balance.all(listParams).getData();
Balance balance = balances.get(0);
String id = balance.getId();
assertEquals(id, "balance1");
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここも Term と同上

Comment on lines +80 to +87
"bank_info": {
"bank_code": "0000",
"bank_branch_code": "123",
"bank_account_type": "普通",
"bank_account_number": "1234567",
"bank_account_holder_name": "ペイ タロウ",
"bank_account_status": "pending"
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

上のほうでコメントした null 関連のやつ、ここが null でテスト通るなら全然スルーで良い認識。

Comment thread src/main/java/jp/pay/model/Balance.java Outdated
Copy link
Copy Markdown
Member

@nonz250 nonz250 Mar 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

めちゃ細かくて申し訳ない。
L33 の import jp.pay.model.Event; 使ってなさそうなら削除したいです。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

消しました

Copy link
Copy Markdown
Contributor Author

@natsuki-yamanaka natsuki-yamanaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

返信

Comment on lines +55 to +57
public BankInfo getBankInfo() {
return bankInfo;
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GSONでのシリアライズ時点では出ないです。一応ローカルのbalance.jsonに "bank_info": null 書いて確かめましたがbalance.getBankInfo()でもnullが返ってくるだけ。
Javaのプリミティブ型以外は全部nullがあり得るのでその先のnull考慮は使用者の責任かと。
以降のnullの話も同じくです

Comment on lines +55 to +57
objectMap.put("term", Term.class);
objectMap.put("statement", Statement.class);
objectMap.put("balance", Balance.class);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4スペースが多そう

現状いろんなとこで入り混じってるので揃えるなら別PRにしてlinter入れたい

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

消しました

Comment on lines +45 to +47
assertEquals("tm_b92b879e60f62b532d6756ae12aa", term.getId());
assertEquals(Long.valueOf("1438354812"), term.getCreated());
assertEquals((Integer)987, term.getChargeCount());
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert足しました。BalanceTestも。
ついでに目についたとこリファクタと、listのリクエスト先URLがおかしいバグが見つかったので修正しました

Comment on lines +67 to +69
Term term = terms.get(0);
String id = term.getId();
assertEquals(id, "term1");
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

足しました

Copy link
Copy Markdown
Member

@nonz250 nonz250 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved.

動作確認まで待ちます。


public BigInteger getNet() {
return net;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

title の getter がなさそう?
他には updated の getter がなさそうですが理由はあるように見えるので聞いておきたいです。

@natsuki-yamanaka natsuki-yamanaka merged commit caaa1d4 into master Apr 11, 2024
@natsuki-yamanaka natsuki-yamanaka deleted the nyamanaka/term-balance branch April 11, 2024 01:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants