第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

如何使用Java中的注釋相關(guān)參數(shù)檢查自定義運(yùn)行時(shí)異常屬性

如何使用Java中的注釋相關(guān)參數(shù)檢查自定義運(yùn)行時(shí)異常屬性

精慕HU 2021-11-03 14:28:52
這是我的班級結(jié)構(gòu)public class OrderRuntimeException extends RuntimeException{  private final Field field;   public OrderManagementServiceRuntimeException(String messege, MyError myError)  {    super(messege);    this.field = field;  }}public Class MyError{    String name;    Sttring description;    public MyError(String name, String description){        this.name = name;        this.description = description;    } }public void getOrders(Order order){    .......    throw new  OrderRuntimeException("Invalid Order",new MyError("Illegale","this is an illegal..."))}我想用 Junit 測試這個(gè)異常和 MeError 類型的對象(名稱和描述)。我寫了這個(gè)public class MyTest { @Rule public ExpectedException thrown = ExpectedException.none();@Test(expectedExceptions = OrderRuntimeException.class, expectedExceptionsMessageRegExp = "Invalid Order")  public void testSetRequestTime_invalidRequestDTOImplType()  {    thrown.expect(......);  }}我使用 @Rule .. 來獲取 throw.expect() 功能。但是我無法從這個(gè)測試中得到 MyError 類型的對象。請發(fā)表評論或回答,如果有人對解決方案有想法。
查看完整描述

1 回答

?
蕭十郎

TA貢獻(xiàn)1815條經(jīng)驗(yàn) 獲得超13個(gè)贊

我認(rèn)為你可以org.hamcrest.Matchers用來做出這種類型的斷言。


expectedException.expect(OrderRuntimeException.class);

    expectedException.expect(org.hamcrest.Matchers.hasProperty("myError", allOf(

            org.hamcrest.Matchers.hasProperty("name", is("exampleName")),

            org.hamcrest.Matchers.hasProperty("description", is("exampleDescription"))

    )));


查看完整回答
反對 回復(fù) 2021-11-03
  • 1 回答
  • 0 關(guān)注
  • 194 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號