|
| 1 | +package com.instabug.instabugflutterexample; |
| 2 | + |
| 3 | +import com.instabug.instabugflutter.InstabugFlutterPlugin; |
| 4 | + |
| 5 | +import org.mockito.Mockito; |
| 6 | +import org.mockito.Spy; |
| 7 | + |
| 8 | +import java.util.ArrayList; |
| 9 | + |
| 10 | +import io.flutter.plugin.common.MethodCall; |
| 11 | +import io.flutter.plugin.common.MethodChannel.Result; |
| 12 | + |
| 13 | +import static org.mockito.Matchers.any; |
| 14 | +import static org.mockito.Mockito.spy; |
| 15 | +import static org.mockito.Mockito.verify; |
| 16 | + |
| 17 | +class OnMethodCallTests { |
| 18 | + |
| 19 | + @Spy |
| 20 | + private InstabugFlutterPlugin instabugMock; |
| 21 | + |
| 22 | + OnMethodCallTests() { |
| 23 | + instabugMock = spy(new InstabugFlutterPlugin()); |
| 24 | + } |
| 25 | + |
| 26 | + private void testMethodCall(final String methodName, final Object params) { |
| 27 | + final MethodCall methodCall = new MethodCall(methodName, params); |
| 28 | + final Result result = new Result() { |
| 29 | + @Override |
| 30 | + public void success(Object o) { |
| 31 | + } |
| 32 | + @Override |
| 33 | + public void error(String s, String s1, Object o) { |
| 34 | + } |
| 35 | + @Override |
| 36 | + public void notImplemented() { |
| 37 | + } |
| 38 | + }; |
| 39 | + instabugMock.onMethodCall(methodCall,result); |
| 40 | + } |
| 41 | + |
| 42 | + public void testShowWelcomeMessageWithMode() { |
| 43 | + String methodName = "showWelcomeMessageWithMode"; |
| 44 | + ArrayList<Object> argsList = new ArrayList<>(); |
| 45 | + argsList.add("WelcomeMessageMode.live"); |
| 46 | + Mockito.doNothing().when(instabugMock).showWelcomeMessageWithMode(any(String.class)); |
| 47 | + testMethodCall(methodName,argsList); |
| 48 | + verify(instabugMock).showWelcomeMessageWithMode("WelcomeMessageMode.live"); |
| 49 | + } |
| 50 | + |
| 51 | + public void testIdentifyUserWithEmail() { |
| 52 | + String methodName = "identifyUserWithEmail"; |
| 53 | + ArrayList<Object> argsList = new ArrayList<>(); |
| 54 | + argsList. add( "[email protected]"); |
| 55 | + argsList.add("Aly"); |
| 56 | + Mockito.doNothing().when(instabugMock).identifyUserWithEmail(any(String.class),any(String.class)); |
| 57 | + testMethodCall(methodName,argsList); |
| 58 | + verify( instabugMock). identifyUserWithEmail( "[email protected]", "Aly"); |
| 59 | + } |
| 60 | + |
| 61 | + public void testLogOut() { |
| 62 | + String methodName = "logOut"; |
| 63 | + Mockito.doNothing().when(instabugMock).logOut(); |
| 64 | + testMethodCall(methodName,null); |
| 65 | + verify(instabugMock).logOut(); |
| 66 | + } |
| 67 | + |
| 68 | + public void testAppendTags() { |
| 69 | + String methodName = "appendTags"; |
| 70 | + ArrayList<Object> argsList = new ArrayList<>(); |
| 71 | + ArrayList<String> tags = new ArrayList<>(); |
| 72 | + tags.add("tag1"); |
| 73 | + tags.add("tag2"); |
| 74 | + argsList.add(tags); |
| 75 | + Mockito.doNothing().when(instabugMock).appendTags(any(ArrayList.class)); |
| 76 | + testMethodCall(methodName,argsList); |
| 77 | + verify(instabugMock).appendTags(tags); |
| 78 | + } |
| 79 | + |
| 80 | + public void testInvokeWithMode() { |
| 81 | + String methodName = "invokeWithMode"; |
| 82 | + ArrayList<Object> argsList = new ArrayList<>(); |
| 83 | + ArrayList<String> options = new ArrayList<>(); |
| 84 | + options.add("commentFieldRequired"); |
| 85 | + options.add("disablePostSendingDialog"); |
| 86 | + argsList.add("bug"); |
| 87 | + argsList.add(options); |
| 88 | + Mockito.doNothing().when(instabugMock).invokeWithMode(any(String.class),any(ArrayList.class)); |
| 89 | + testMethodCall(methodName,argsList); |
| 90 | + verify(instabugMock).invokeWithMode("bug", options); |
| 91 | + } |
| 92 | + |
| 93 | + public void testSetSessionProfilerEnabled() { |
| 94 | + String methodName = "setSessionProfilerEnabled"; |
| 95 | + ArrayList<Object> argsList = new ArrayList<>(); |
| 96 | + argsList.add(true); |
| 97 | + Mockito.doNothing().when(instabugMock).setSessionProfilerEnabled(any(Boolean.class)); |
| 98 | + testMethodCall(methodName,argsList); |
| 99 | + verify(instabugMock).setSessionProfilerEnabled(true); |
| 100 | + } |
| 101 | + |
| 102 | + public void testSetPrimaryColor() { |
| 103 | + String methodName = "setPrimaryColor"; |
| 104 | + ArrayList<Object> argsList = new ArrayList<>(); |
| 105 | + argsList.add(12312331231233L); |
| 106 | + Mockito.doNothing().when(instabugMock).setPrimaryColor(any(Long.class)); |
| 107 | + testMethodCall(methodName,argsList); |
| 108 | + verify(instabugMock).setPrimaryColor(12312331231233L); |
| 109 | + } |
| 110 | + |
| 111 | + public void testAddFileAttachmentWithData() { |
| 112 | + String methodName = "addFileAttachmentWithData"; |
| 113 | + ArrayList<Object> argsList = new ArrayList<>(); |
| 114 | + String string = "myfile"; |
| 115 | + argsList.add(string.getBytes()); |
| 116 | + argsList.add(string); |
| 117 | + Mockito.doNothing().when(instabugMock).addFileAttachmentWithData(any(byte[].class), any(String.class)); |
| 118 | + testMethodCall(methodName,argsList); |
| 119 | + verify(instabugMock).addFileAttachmentWithData(string.getBytes(), string); |
| 120 | + } |
| 121 | + |
| 122 | + public void testSetEnabledAttachmentTypes() { |
| 123 | + String methodName = "setEnabledAttachmentTypes"; |
| 124 | + ArrayList<Object> argsList = new ArrayList<>(); |
| 125 | + argsList.add(true); |
| 126 | + argsList.add(true); |
| 127 | + argsList.add(true); |
| 128 | + argsList.add(true); |
| 129 | + Mockito.doNothing().when(instabugMock).setEnabledAttachmentTypes(any(Boolean.class),any(Boolean.class),any(Boolean.class),any(Boolean.class)); |
| 130 | + testMethodCall(methodName,argsList); |
| 131 | + verify(instabugMock).setEnabledAttachmentTypes(true,true,true,true); |
| 132 | + } |
| 133 | + |
| 134 | + public void testSetEmailFieldRequiredForFeatureRequests() { |
| 135 | + String methodName = "setEmailFieldRequiredForFeatureRequests"; |
| 136 | + ArrayList<Object> argsList = new ArrayList<>(); |
| 137 | + ArrayList<String> actions = new ArrayList<>(); |
| 138 | + actions.add("reportBug"); |
| 139 | + actions.add("requestNewFeature"); |
| 140 | + argsList.add(true); |
| 141 | + argsList.add(actions); |
| 142 | + Mockito.doNothing().when(instabugMock).setEmailFieldRequiredForFeatureRequests(any(Boolean.class),any(ArrayList.class)); |
| 143 | + testMethodCall(methodName,argsList); |
| 144 | + verify(instabugMock).setEmailFieldRequiredForFeatureRequests(true,actions); |
| 145 | + } |
| 146 | + |
| 147 | + |
| 148 | +} |
0 commit comments