久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

是否可以使用 EasyMock 創(chuàng)建一個實(shí)現(xiàn)多個接口的模

Is it possible to create a mock object that implements multiple interfaces with EasyMock?(是否可以使用 EasyMock 創(chuàng)建一個實(shí)現(xiàn)多個接口的模擬對象?)
本文介紹了是否可以使用 EasyMock 創(chuàng)建一個實(shí)現(xiàn)多個接口的模擬對象?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

是否可以使用 EasyMock 創(chuàng)建一個實(shí)現(xiàn)多個接口的模擬對象?

Is it possible to create a mock object that implements several interfaces with EasyMock?

例如接口Foo和接口Closeable?

在 Rhino Mocks 中,你可以在創(chuàng)建 mock 對象時提供多個接口,但 EasyMock 的 createMock() 方法只接受一種類型.

In Rhino Mocks you can provide multiple interfaces when creating a mock object, but EasyMock's createMock() method only takes one type.

是否可以使用 EasyMock 來實(shí)現(xiàn)這一點(diǎn),而無需求助于創(chuàng)建一個擴(kuò)展 FooCloseable 的臨時接口,然后對其進(jìn)行模擬?

Is it possbile to achieve this with EasyMock, without resorting to the fallback of creating a temporary interface that extends both Foo and Closeable, and then mocking that?

推薦答案

EasyMock 不支持此功能,因此您只能使用臨時界面的回退.

EasyMock doesn't support this so you're stuck with fallback of the temporary interface.

順便說一句,我聞到了一點(diǎn)代碼的味道——如果一個方法真的將一個對象視為 2 個不同的東西,FooCloseable 接口這個案例?

As an aside, I smell a little bit of a code wiff - should a method really be treating an object as 2 different things, the Foo and Closeable interface in this case?

這對我來說意味著該方法正在執(zhí)行多個操作,雖然我懷疑其中一個操作是關(guān)閉"Closeable,但調(diào)用代碼決定是否更有意義是否需要關(guān)閉"?

This implies to me that the method is performing multiple operations and while I suspect one of those operations is to 'close' the Closeable, wouldn't it make more sense for the calling code to decide whether or not the 'close' is required?

以這種方式構(gòu)建代碼將打開"和關(guān)閉"保持在同一個 try ... finally 塊中,恕我直言,讓代碼更具可讀性,更不用說該方法更通用,并允許您傳遞僅實(shí)現(xiàn) Foo 的對象.

Structuring the code this way keeps the 'open' and 'close' in the same try ... finally block and IMHO makes the code more readable not to mention the method more general and allows you to pass objects that only implement Foo.

這篇關(guān)于是否可以使用 EasyMock 創(chuàng)建一個實(shí)現(xiàn)多個接口的模擬對象?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How to mock super reference (on super class)?(如何模擬超級參考(在超級類上)?)
Java mock database connection(Java 模擬數(shù)據(jù)庫連接)
Mockito ClassCastException - A mock cannot be cast(Mockito ClassCastException - 無法投射模擬)
Set value to mocked object but get null(將值設(shè)置為模擬對象但獲取 null)
How to mock DriverManager.getConnection(...)?(如何模擬 DriverManager.getConnection(...)?)
Mockito; verify method was called with list, ignore order of elements in list(模擬;使用列表調(diào)用驗(yàn)證方法,忽略列表中元素的順序)
主站蜘蛛池模板: 黑人精品欧美一区二区蜜桃 | 黄在线 | 日日天天 | 久久国产一区二区三区 | 在线国产一区 | 欧美黄色小视频 | 国产日韩精品视频 | 亚洲精品在线视频 | 欧美日韩一区二区三区不卡视频 | 午夜丁香视频在线观看 | 欧美一区二区三区在线 | 美女在线观看国产 | 国产日韩久久 | 久久久久久久一区 | 人人精品| 久久男人 | 日本又色又爽又黄的大片 | 精品免费看 | 久久99精品国产 | a级在线免费观看 | 亚洲第1页| 成人激情视频网 | 中文在线一区二区 | 成人高清在线视频 | 精品国产18久久久久久二百 | 久久久久久国模大尺度人体 | 国产高清久久 | 国产精品久久久久久妇女6080 | 免费黄色网址视频 | 亚洲国产成人在线观看 | 国产成人精品久久二区二区91 | 亚洲福利av | 午夜精品久久久久久 | 国产免费一区二区三区网站免费 | 亚洲一区二区精品 | 青青草av | 在线观看视频91 | 国产日韩一区二区三免费高清 | 丝袜 亚洲 另类 欧美 综合 | 欧美不卡一区二区 | www.888www看片|