Guest User

Untitled

a guest
Oct 19th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. public void isFeatureFlagOn(String featureFlagId, TransactionContext transContext, boolean defaultReturnState)
  2. throws TAServiceException {
  3. boolean returnState = defaultReturnState;
  4. try {
  5. LDUser ldUser = new LDUser.Builder(transContext.getAuthId()).build();
  6. returnState = ldClient.boolVariation(featureFlagId, ldUser, defaultReturnState);
  7. } catch (Exception e) {
  8. returnState = defaultReturnState;
  9. }
  10.  
  11. if (!returnState) {
  12. throw new TAServiceException("This service is not available", HttpStatus.NOT_FOUND);
  13. }
  14. }
  15.  
  16. // ...
  17. when(mockLdUserBuilder.build()).thenReturn(mockLdUser);
  18. classUnderTest.methodUnderTest(mockLdUserBuilder);
  19. // ... assert/verify stuff
  20.  
  21. public void isFeatureFlagOn(...) throws TAServiceException {
  22. boolean returnState = defaultReturnState;
  23. try {
  24. getBuilder(transContext.getAuthId()).build();
  25. ...
  26. }
  27. ...
  28. }
  29. //package method
  30. Builder (int authId) {
  31. return new LDUser.Builder(authId);
  32. }
  33.  
  34. @Mock
  35. LDUser.Builder builder;
  36.  
  37. @Test
  38. public void test1() {
  39. MyClass myClass = new MyClass() {
  40. @Override
  41. Builder (int authId) {
  42. return builder;
  43. }
  44. }
  45. myClass.isFeatureFlagOn(...);
  46. ...
  47. }
Add Comment
Please, Sign In to add comment