Mocking CerbosBlockingAdminClient for testing #1870
Replies: 2 comments
-
Typically the way to mock external libraries is to create your own interface for the calls that you want to make from your code. Then you can swap that interface with a mock during tests. For example, you could create an interface with a method that takes the arguments you want to pass to Cerbos' |
Beta Was this translation helpful? Give feedback.
-
I think I found out why I got a problem. :) Adding the dependency |
Beta Was this translation helpful? Give feedback.
-
Hello!
I am currently struggling a little bit with my unit tests. I am using the Java SDK, i.e. my problem corresponds to the CerbosBlockingAdminClient.
My goal is to write a unit test for a Java method which contains a call to an instance of the CerbosBlockingAdminClient. Thus, I want to mock the CerbosBlockingAdminClient (like I did for other methods for the checkResources API), such that I only run/test my Java Code.
But I am facing the problem, that I could not find a wat to instantiate the returned value of the Client's function
cerbosBlockingAdminClient.addOrUpdatePolicy()
. The reason for this is the Builder class (AddOrUpdatePolicyRequestBuilder
) being private in the package. Is there a way to construct an instance of the Builder to be able to mock the function call (and consecutive chained calls on the Builder), that I maybe missed out?Thanks in advance!
Marco
Beta Was this translation helpful? Give feedback.
All reactions