Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to mock a Java protocol buffer message?

Protocol buffer classes are marked final, presumably for efficiency; however, this makes them quite difficult to test with -- Mockito can't mock/spy on final classes. I've tried using PowerMockito with no success: I get a ClassFormatError when preparing the final class for the test.

My solution up until now is to create mockable adapter interfaces, but I'm hoping there's a less laborious approach.

like image 668
cdleary Avatar asked Jan 26 '10 11:01

cdleary


1 Answers

JMockit can handle final and static. Just pay attention to how to set it up as it requires the -javaagent JVM parameter, or classpath tweaks, or extra annotations to be able to mock final and static stuffs.

like image 176
aberrant80 Avatar answered Oct 04 '22 21:10

aberrant80