|
7 | 7 | import static org.junit.Assert.fail;
|
8 | 8 | import static org.mockito.Mockito.mock;
|
9 | 9 | import static org.mockito.Mockito.mockStatic;
|
| 10 | +import static org.mockito.Mockito.never; |
10 | 11 |
|
11 | 12 | import android.webkit.WebSettings;
|
12 | 13 | import androidx.webkit.WebSettingsCompat;
|
| 14 | +import androidx.webkit.WebViewFeature; |
| 15 | + |
13 | 16 | import org.junit.Test;
|
14 | 17 | import org.mockito.MockedStatic;
|
15 | 18 |
|
16 | 19 | public class WebSettingsCompatTest {
|
17 | 20 | @Test
|
18 |
| - public void setPaymentRequestEnabled() { |
| 21 | + public void setPaymentRequestEnabled_PAYMENT_REQUEST_is_supported() { |
19 | 22 | final PigeonApiWebSettingsCompat api =
|
20 | 23 | new TestProxyApiRegistrar().getPigeonApiWebSettingsCompat();
|
21 | 24 |
|
22 | 25 | final WebSettings webSettings = mock(WebSettings.class);
|
| 26 | + |
| 27 | + try (MockedStatic<WebSettingsCompat> mockedStatic = mockStatic(WebSettingsCompat.class)) { |
| 28 | + try(MockedStatic<WebViewFeature> mockedWebViewFeature = mockStatic(WebViewFeature.class)) { |
| 29 | + mockedWebViewFeature.when(() -> WebViewFeature.isFeatureSupported(WebViewFeature.PAYMENT_REQUEST)).thenReturn(true); |
| 30 | + api.setPaymentRequestEnabled(webSettings, true); |
| 31 | + mockedStatic.verify(() -> WebSettingsCompat.setPaymentRequestEnabled(webSettings, true)); |
| 32 | + } catch (Exception e) { |
| 33 | + fail(e.toString()); |
| 34 | + } |
| 35 | + } catch (Exception e) { |
| 36 | + fail(e.toString()); |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + public void setPaymentRequestEnabled_PAYMENT_REQUEST_is_NOT_supported() { |
| 42 | + final PigeonApiWebSettingsCompat api = |
| 43 | + new TestProxyApiRegistrar().getPigeonApiWebSettingsCompat(); |
| 44 | + |
| 45 | + final WebSettings webSettings = mock(WebSettings.class); |
| 46 | + |
23 | 47 | try (MockedStatic<WebSettingsCompat> mockedStatic = mockStatic(WebSettingsCompat.class)) {
|
24 |
| - api.setPaymentRequestEnabled(webSettings, true); |
25 |
| - mockedStatic.verify(() -> WebSettingsCompat.setPaymentRequestEnabled(webSettings, true)); |
| 48 | + try(MockedStatic<WebViewFeature> mockedWebViewFeature = mockStatic(WebViewFeature.class)) { |
| 49 | + mockedWebViewFeature.when(() -> WebViewFeature.isFeatureSupported(WebViewFeature.PAYMENT_REQUEST)).thenReturn(false); |
| 50 | + api.setPaymentRequestEnabled(webSettings, true); |
| 51 | + mockedStatic.verify(() -> WebSettingsCompat.setPaymentRequestEnabled(webSettings, true), never()); |
| 52 | + } catch (Exception e) { |
| 53 | + fail(e.toString()); |
| 54 | + } |
26 | 55 | } catch (Exception e) {
|
27 | 56 | fail(e.toString());
|
28 | 57 | }
|
|
0 commit comments