简体   繁体   中英

HttpEntity<String> request = new HttpEntity<String>( ); How do I mock this in java

我试图模拟泛型我能够模拟一些通用表达式,但我不知道如何模拟通用初始化

Generic in java are a compiler trick implemented using erasure (with the option of some runtime artifacts, true). So there isn't really a separate class definition for HttpEntity<String> vs HttpEntity<Foo> .

So you would simply need to (A) simply cast and (B) make sure a mock that represents a certain type is only used with that type and not cast and re-used for another type.

If this is not answering your question, please paste the exact source code you are trying to unit test and indicate which component are you testing and which ones you are trying to mock.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM