How to use anyBoolean method of org.mockito.ArgumentMatchers class

Best Mockito code snippet using org.mockito.ArgumentMatchers.anyBoolean

Source:OfflineContentAggregatorNotificationBridgeUiTest.java Github

copy

Full Screen

...94 bridge.onVisualsAvailable(items.get(i).id, new OfflineItemVisuals());95 }96 verify(mNotifier, times(1))97 .notifyDownloadProgress(argThat(new DownloadInfoIdMatcher(items.get(0).id)),98 ArgumentMatchers.anyLong(), ArgumentMatchers.anyBoolean());99 verify(mNotifier, times(1))100 .notifyDownloadSuccessful(argThat(new DownloadInfoIdMatcher(items.get(2).id)),101 ArgumentMatchers.anyLong(), ArgumentMatchers.anyBoolean(),102 ArgumentMatchers.anyBoolean());103 verify(mNotifier, times(1))104 .notifyDownloadCanceled(items.get(3).id /* OfflineItemState.CANCELLED */);105 verify(mNotifier, times(1))106 .notifyDownloadInterrupted(argThat(new DownloadInfoIdMatcher(items.get(4).id)),107 ArgumentMatchers.anyBoolean(), eq(PendingState.NOT_PENDING));108 verify(mNotifier, times(1))109 .notifyDownloadFailed(argThat(new DownloadInfoIdMatcher(items.get(5).id)));110 verify(mNotifier, times(1))111 .notifyDownloadPaused(argThat(new DownloadInfoIdMatcher(items.get(6).id)));112 bridge.destroy();113 verify(mProvider, times(1)).removeObserver(bridge);114 }115 @Test116 public void testItemUpdatesGetSentToTheUi() {117 OfflineContentAggregatorNotificationBridgeUi bridge =118 new OfflineContentAggregatorNotificationBridgeUi(mProvider, mNotifier);119 verify(mProvider, times(1)).addObserver(bridge);120 ArrayList<OfflineItem> items = new ArrayList<OfflineItem>() {121 {122 add(buildOfflineItem(new ContentId("1", "A"), OfflineItemState.IN_PROGRESS));123 add(buildOfflineItem(new ContentId("2", "B"), OfflineItemState.PENDING));124 add(buildOfflineItem(new ContentId("3", "C"), OfflineItemState.COMPLETE));125 add(buildOfflineItem(new ContentId("4", "D"), OfflineItemState.CANCELLED));126 add(buildOfflineItem(new ContentId("5", "E"), OfflineItemState.INTERRUPTED));127 add(buildOfflineItem(new ContentId("6", "F"), OfflineItemState.FAILED));128 add(buildOfflineItem(new ContentId("7", "G"), OfflineItemState.PAUSED));129 }130 };131 for (int i = 0; i < items.size(); i++) bridge.onItemUpdated(items.get(i), null);132 verify(mProvider, times(1)).getVisualsForItem(items.get(0).id, bridge);133 verify(mProvider, times(1)).getVisualsForItem(items.get(1).id, bridge);134 verify(mProvider, times(1)).getVisualsForItem(items.get(2).id, bridge);135 verify(mProvider, never()).getVisualsForItem(items.get(3).id, bridge);136 verify(mProvider, times(1)).getVisualsForItem(items.get(4).id, bridge);137 verify(mProvider, times(1)).getVisualsForItem(items.get(5).id, bridge);138 verify(mProvider, times(1)).getVisualsForItem(items.get(6).id, bridge);139 for (int i = 0; i < items.size(); i++) {140 bridge.onVisualsAvailable(items.get(i).id, new OfflineItemVisuals());141 }142 verify(mNotifier, times(1))143 .notifyDownloadProgress(argThat(new DownloadInfoIdMatcher(items.get(0).id)),144 ArgumentMatchers.anyLong(), ArgumentMatchers.anyBoolean());145 verify(mNotifier, times(1))146 .notifyDownloadSuccessful(argThat(new DownloadInfoIdMatcher(items.get(2).id)),147 ArgumentMatchers.anyLong(), ArgumentMatchers.anyBoolean(),148 ArgumentMatchers.anyBoolean());149 verify(mNotifier, times(1))150 .notifyDownloadCanceled(items.get(3).id /* OfflineItemState.CANCELLED */);151 verify(mNotifier, times(1))152 .notifyDownloadInterrupted(argThat(new DownloadInfoIdMatcher(items.get(4).id)),153 ArgumentMatchers.anyBoolean(), eq(PendingState.NOT_PENDING));154 verify(mNotifier, times(1))155 .notifyDownloadFailed(argThat(new DownloadInfoIdMatcher(items.get(5).id)));156 verify(mNotifier, times(1))157 .notifyDownloadPaused(argThat(new DownloadInfoIdMatcher(items.get(6).id)));158 bridge.destroy();159 verify(mProvider, times(1)).removeObserver(bridge);160 }161 @Test162 public void testNullVisuals() {163 OfflineContentAggregatorNotificationBridgeUi bridge =164 new OfflineContentAggregatorNotificationBridgeUi(mProvider, mNotifier);165 verify(mProvider, times(1)).addObserver(bridge);166 OfflineItem item1 = buildOfflineItem(new ContentId("1", "A"), OfflineItemState.IN_PROGRESS);167 OfflineItem item2 = buildOfflineItem(new ContentId("2", "B"), OfflineItemState.IN_PROGRESS);168 OfflineItemVisuals visuals1 = new OfflineItemVisuals();169 visuals1.icon = Bitmap.createBitmap(1, 1, Bitmap.Config.ALPHA_8);170 bridge.onItemUpdated(item1, null);171 bridge.onItemUpdated(item2, null);172 verify(mProvider, times(1)).getVisualsForItem(item1.id, bridge);173 verify(mProvider, times(1)).getVisualsForItem(item2.id, bridge);174 ArgumentCaptor<DownloadInfo> captor = ArgumentCaptor.forClass(DownloadInfo.class);175 bridge.onVisualsAvailable(item1.id, visuals1);176 bridge.onVisualsAvailable(item2.id, null);177 verify(mNotifier, times(2))178 .notifyDownloadProgress(captor.capture(), ArgumentMatchers.anyLong(),179 ArgumentMatchers.anyBoolean());180 List<DownloadInfo> capturedInfo = captor.getAllValues();181 Assert.assertEquals(item1.id, capturedInfo.get(0).getContentId());182 Assert.assertEquals(visuals1.icon, capturedInfo.get(0).getIcon());183 Assert.assertEquals(item2.id, capturedInfo.get(1).getContentId());184 Assert.assertEquals(null, capturedInfo.get(1).getIcon());185 bridge.destroy();186 verify(mProvider, times(1)).removeObserver(bridge);187 }188 @Test189 public void testRemovedItemsGetRemovedFromTheUi() {190 OfflineContentAggregatorNotificationBridgeUi bridge =191 new OfflineContentAggregatorNotificationBridgeUi(mProvider, mNotifier);192 verify(mProvider, times(1)).addObserver(bridge);193 ContentId id = new ContentId("1", "A");194 bridge.onItemRemoved(id);195 verify(mNotifier, times(1)).notifyDownloadCanceled(id);196 bridge.destroy();197 verify(mProvider, times(1)).removeObserver(bridge);198 }199 @Test200 public void testRemovedItemsIgnoreVisualsCallback() {201 OfflineContentAggregatorNotificationBridgeUi bridge =202 new OfflineContentAggregatorNotificationBridgeUi(mProvider, mNotifier);203 verify(mProvider, times(1)).addObserver(bridge);204 OfflineItem item = buildOfflineItem(new ContentId("1", "A"), OfflineItemState.IN_PROGRESS);205 bridge.onItemUpdated(item, null);206 verify(mProvider, times(1)).getVisualsForItem(item.id, bridge);207 bridge.onItemRemoved(item.id);208 bridge.onVisualsAvailable(item.id, new OfflineItemVisuals());209 InOrder order = inOrder(mNotifier);210 order.verify(mNotifier, times(1)).notifyDownloadCanceled(item.id);211 order.verifyNoMoreInteractions();212 bridge.destroy();213 verify(mProvider, times(1)).removeObserver(bridge);214 }215 @Test216 public void testOnlyRequestsVisualsOnceForMultipleUpdates() {217 OfflineContentAggregatorNotificationBridgeUi bridge =218 new OfflineContentAggregatorNotificationBridgeUi(mProvider, mNotifier);219 verify(mProvider, times(1)).addObserver(bridge);220 OfflineItem item = buildOfflineItem(new ContentId("1", "A"), OfflineItemState.IN_PROGRESS);221 bridge.onItemUpdated(item, null);222 bridge.onItemUpdated(item, null);223 verify(mProvider, times(1)).getVisualsForItem(item.id, bridge);224 bridge.destroy();225 verify(mProvider, times(1)).removeObserver(bridge);226 }227 @Test228 public void testVisualsAreCachedForInterestingItems() {229 OfflineContentAggregatorNotificationBridgeUi bridge =230 new OfflineContentAggregatorNotificationBridgeUi(mProvider, mNotifier);231 verify(mProvider, times(1)).addObserver(bridge);232 ArrayList<OfflineItem> interestingItems = new ArrayList<OfflineItem>() {233 {234 add(buildOfflineItem(new ContentId("1", "A"), OfflineItemState.IN_PROGRESS));235 add(buildOfflineItem(new ContentId("2", "B"), OfflineItemState.PENDING));236 add(buildOfflineItem(new ContentId("3", "C"), OfflineItemState.COMPLETE));237 add(buildOfflineItem(new ContentId("5", "E"), OfflineItemState.INTERRUPTED));238 add(buildOfflineItem(new ContentId("7", "G"), OfflineItemState.PAUSED));239 }240 };241 ArrayList<OfflineItem> uninterestingItems = new ArrayList<OfflineItem>() {242 {243 add(buildOfflineItem(new ContentId("6", "F"), OfflineItemState.FAILED));244 }245 };246 for (int i = 0; i < interestingItems.size(); i++) {247 OfflineItem item = interestingItems.get(i);248 bridge.onItemUpdated(item, null);249 bridge.onVisualsAvailable(item.id, null);250 bridge.onItemUpdated(item, null);251 verify(mProvider, times(1)).getVisualsForItem(item.id, bridge);252 verify(mNotifier, times(2))253 .notifyDownloadProgress(ArgumentMatchers.any(), ArgumentMatchers.anyLong(),254 ArgumentMatchers.anyBoolean());255 }256 for (int i = 0; i < uninterestingItems.size(); i++) {257 OfflineItem item = uninterestingItems.get(i);258 bridge.onItemUpdated(item, null);259 bridge.onVisualsAvailable(item.id, null);260 bridge.onItemUpdated(item, null);261 verify(mProvider, times(2)).getVisualsForItem(item.id, bridge);262 }263 bridge.destroy();264 verify(mProvider, times(1)).removeObserver(bridge);265 }266 @Test267 public void testVisualsGetClearedForUninterestingItems() {268 OfflineContentAggregatorNotificationBridgeUi bridge =...

Full Screen

Full Screen

Source:MediaImageManagerTest.java Github

copy

Full Screen

2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4package org.chromium.components.browser_ui.media;5import static org.mockito.ArgumentMatchers.any;6import static org.mockito.ArgumentMatchers.anyBoolean;7import static org.mockito.ArgumentMatchers.anyInt;8import static org.mockito.ArgumentMatchers.anyString;9import static org.mockito.ArgumentMatchers.eq;10import static org.mockito.ArgumentMatchers.isNotNull;11import static org.mockito.ArgumentMatchers.isNull;12import static org.mockito.Mockito.doReturn;13import static org.mockito.Mockito.times;14import static org.mockito.Mockito.verify;15import android.graphics.Bitmap;16import android.graphics.Rect;17import org.junit.Before;18import org.junit.Test;19import org.junit.runner.RunWith;20import org.mockito.Mock;21import org.mockito.MockitoAnnotations;22import org.robolectric.annotation.Config;23import org.robolectric.shadows.ShadowLog;24import org.chromium.base.test.BaseRobolectricTestRunner;25import org.chromium.content_public.browser.WebContents;26import org.chromium.services.media_session.MediaImage;27import java.util.ArrayList;28/**29 * Robolectric tests for MediaImageManager.30 */31@RunWith(BaseRobolectricTestRunner.class)32@Config(manifest = Config.NONE)33public class MediaImageManagerTest {34 private static final int TINY_IMAGE_SIZE_PX = 50;35 private static final int MIN_IMAGE_SIZE_PX = 100;36 private static final int IDEAL_IMAGE_SIZE_PX = 200;37 private static final int REQUEST_ID_1 = 1;38 private static final int REQUEST_ID_2 = 2;39 private static final String IMAGE_URL_1 = "http://example.com/foo.png";40 private static final String IMAGE_URL_2 = "http://example.com/bar.png";41 @Mock42 private WebContents mWebContents;43 @Mock44 private MediaImageCallback mCallback;45 private MediaImageManager mMediaImageManager;46 // Prepared data for feeding.47 private ArrayList<MediaImage> mImages;48 private ArrayList<Bitmap> mBitmaps;49 private ArrayList<Rect> mOriginalImageSizes;50 @Before51 public void setUp() {52 ShadowLog.stream = System.out;53 MockitoAnnotations.initMocks(this);54 doReturn(REQUEST_ID_1)55 .when(mWebContents)56 .downloadImage(anyString(), anyBoolean(), anyInt(), anyBoolean(),57 any(MediaImageManager.class));58 mMediaImageManager = new MediaImageManager(MIN_IMAGE_SIZE_PX, IDEAL_IMAGE_SIZE_PX);59 mMediaImageManager.setWebContents(mWebContents);60 mImages = new ArrayList<MediaImage>();61 mImages.add(new MediaImage(IMAGE_URL_1, "", new ArrayList<Rect>()));62 mBitmaps = new ArrayList<Bitmap>();63 mBitmaps.add(Bitmap.createBitmap(64 IDEAL_IMAGE_SIZE_PX, IDEAL_IMAGE_SIZE_PX, Bitmap.Config.ARGB_8888));65 mOriginalImageSizes = new ArrayList<Rect>();66 mOriginalImageSizes.add(new Rect(0, 0, IDEAL_IMAGE_SIZE_PX, IDEAL_IMAGE_SIZE_PX));67 }68 @Test69 public void testDownloadImage() {70 mMediaImageManager.downloadImage(mImages, mCallback);71 verify(mWebContents)72 .downloadImage(eq(IMAGE_URL_1), eq(false),73 eq(MediaImageManager.MAX_BITMAP_SIZE_FOR_DOWNLOAD), eq(false),74 eq(mMediaImageManager));75 mMediaImageManager.onFinishDownloadImage(76 REQUEST_ID_1, 200, IMAGE_URL_1, mBitmaps, mOriginalImageSizes);77 verify(mCallback).onImageDownloaded((Bitmap) isNotNull());78 verify(mCallback, times(0)).onImageDownloaded((Bitmap) isNull());79 }80 @Test81 public void testDownloadSameImageTwice() {82 // First download.83 mMediaImageManager.downloadImage(mImages, mCallback);84 mMediaImageManager.onFinishDownloadImage(85 REQUEST_ID_1, 200, IMAGE_URL_1, mBitmaps, mOriginalImageSizes);86 // Second download.87 doReturn(REQUEST_ID_2)88 .when(mWebContents)89 .downloadImage(anyString(), anyBoolean(), anyInt(), anyBoolean(),90 any(MediaImageManager.class));91 mMediaImageManager.downloadImage(mImages, mCallback);92 mMediaImageManager.onFinishDownloadImage(93 REQUEST_ID_2, 200, IMAGE_URL_1, mBitmaps, mOriginalImageSizes);94 verify(mWebContents, times(1))95 .downloadImage(eq(IMAGE_URL_1), eq(false),96 eq(MediaImageManager.MAX_BITMAP_SIZE_FOR_DOWNLOAD), eq(false),97 eq(mMediaImageManager));98 verify(mCallback, times(1)).onImageDownloaded((Bitmap) isNotNull());99 verify(mCallback, times(0)).onImageDownloaded((Bitmap) isNull());100 }101 @Test102 public void testDownloadSameImageTwiceButFailed() {103 // First download.104 mBitmaps.clear();105 mOriginalImageSizes.clear();106 mMediaImageManager.downloadImage(mImages, mCallback);107 mMediaImageManager.onFinishDownloadImage(108 REQUEST_ID_1, 404, IMAGE_URL_1, mBitmaps, mOriginalImageSizes);109 // Second download.110 mMediaImageManager.downloadImage(mImages, mCallback);111 // The second download request will never be initiated and the callback112 // will be ignored.113 mMediaImageManager.onFinishDownloadImage(114 REQUEST_ID_1, 200, IMAGE_URL_1, mBitmaps, mOriginalImageSizes);115 verify(mWebContents, times(1))116 .downloadImage(eq(IMAGE_URL_1), eq(false),117 eq(MediaImageManager.MAX_BITMAP_SIZE_FOR_DOWNLOAD), eq(false),118 eq(mMediaImageManager));119 verify(mCallback, times(1)).onImageDownloaded((Bitmap) isNull());120 }121 @Test122 public void testDownloadDifferentImagesTwice() {123 // First download.124 mMediaImageManager.downloadImage(mImages, mCallback);125 mMediaImageManager.onFinishDownloadImage(126 REQUEST_ID_1, 200, IMAGE_URL_1, mBitmaps, mOriginalImageSizes);127 // Second download.128 doReturn(REQUEST_ID_2)129 .when(mWebContents)130 .downloadImage(anyString(), anyBoolean(), anyInt(), anyBoolean(),131 any(MediaImageManager.class));132 mImages.clear();133 mImages.add(new MediaImage(IMAGE_URL_2, "", new ArrayList<Rect>()));134 mMediaImageManager.downloadImage(mImages, mCallback);135 mMediaImageManager.onFinishDownloadImage(136 REQUEST_ID_2, 200, IMAGE_URL_2, mBitmaps, mOriginalImageSizes);137 verify(mWebContents, times(1))138 .downloadImage(eq(IMAGE_URL_1), eq(false),139 eq(MediaImageManager.MAX_BITMAP_SIZE_FOR_DOWNLOAD), eq(false),140 eq(mMediaImageManager));141 verify(mWebContents, times(1))142 .downloadImage(eq(IMAGE_URL_2), eq(false),143 eq(MediaImageManager.MAX_BITMAP_SIZE_FOR_DOWNLOAD), eq(false),144 eq(mMediaImageManager));145 verify(mCallback, times(2)).onImageDownloaded((Bitmap) isNotNull());146 verify(mCallback, times(0)).onImageDownloaded((Bitmap) isNull());147 }148 @Test149 public void testDownloadAnotherImageBeforeResponse() {150 // First download.151 mMediaImageManager.downloadImage(mImages, mCallback);152 // Second download.153 doReturn(REQUEST_ID_2)154 .when(mWebContents)155 .downloadImage(anyString(), anyBoolean(), anyInt(), anyBoolean(),156 any(MediaImageManager.class));157 mImages.clear();158 mImages.add(new MediaImage(IMAGE_URL_2, "", new ArrayList<Rect>()));159 mMediaImageManager.downloadImage(mImages, mCallback);160 mMediaImageManager.onFinishDownloadImage(161 REQUEST_ID_2, 200, IMAGE_URL_2, mBitmaps, mOriginalImageSizes);162 // This reply should not be sent to the client.163 mMediaImageManager.onFinishDownloadImage(164 REQUEST_ID_1, 200, IMAGE_URL_1, mBitmaps, mOriginalImageSizes);165 verify(mWebContents, times(1))166 .downloadImage(eq(IMAGE_URL_1), eq(false),167 eq(MediaImageManager.MAX_BITMAP_SIZE_FOR_DOWNLOAD), eq(false),168 eq(mMediaImageManager));169 verify(mWebContents, times(1))170 .downloadImage(eq(IMAGE_URL_2), eq(false),171 eq(MediaImageManager.MAX_BITMAP_SIZE_FOR_DOWNLOAD), eq(false),172 eq(mMediaImageManager));173 verify(mCallback, times(1)).onImageDownloaded((Bitmap) isNotNull());174 verify(mCallback, times(0)).onImageDownloaded((Bitmap) isNull());175 }176 @Test177 public void testDuplicateResponce() {178 mMediaImageManager.downloadImage(mImages, mCallback);179 mMediaImageManager.onFinishDownloadImage(180 REQUEST_ID_1, 200, IMAGE_URL_1, mBitmaps, mOriginalImageSizes);181 mMediaImageManager.onFinishDownloadImage(182 REQUEST_ID_1, 200, IMAGE_URL_1, mBitmaps, mOriginalImageSizes);183 verify(mCallback, times(1)).onImageDownloaded((Bitmap) isNotNull());184 verify(mCallback, times(0)).onImageDownloaded((Bitmap) isNull());185 }186 @Test187 public void testWrongResponceId() {188 mMediaImageManager.downloadImage(mImages, mCallback);189 mMediaImageManager.onFinishDownloadImage(190 REQUEST_ID_2, 200, IMAGE_URL_1, mBitmaps, mOriginalImageSizes);191 verify(mCallback, times(0)).onImageDownloaded((Bitmap) isNotNull());192 verify(mCallback, times(0)).onImageDownloaded((Bitmap) isNull());193 }194 @Test195 public void testTinyImagesRemovedBeforeDownloading() {196 mImages.clear();197 ArrayList<Rect> sizes = new ArrayList<Rect>();198 sizes.add(new Rect(0, 0, TINY_IMAGE_SIZE_PX, TINY_IMAGE_SIZE_PX));199 mImages.add(new MediaImage(IMAGE_URL_1, "", sizes));200 mMediaImageManager.downloadImage(mImages, mCallback);201 verify(mWebContents, times(0))202 .downloadImage(anyString(), anyBoolean(), anyInt(), anyBoolean(),203 any(MediaImageManager.class));204 verify(mCallback).onImageDownloaded((Bitmap) isNull());205 verify(mCallback, times(0)).onImageDownloaded((Bitmap) isNotNull());206 }207 @Test208 public void testTinyImagesRemovedAfterDownloading() {209 mMediaImageManager.downloadImage(mImages, mCallback);210 // Reset the data for feeding.211 mBitmaps.clear();212 mBitmaps.add(Bitmap.createBitmap(213 TINY_IMAGE_SIZE_PX, TINY_IMAGE_SIZE_PX, Bitmap.Config.ARGB_8888));214 mOriginalImageSizes.clear();215 mOriginalImageSizes.add(new Rect(0, 0, TINY_IMAGE_SIZE_PX, TINY_IMAGE_SIZE_PX));216 mMediaImageManager.onFinishDownloadImage(217 REQUEST_ID_1, 200, IMAGE_URL_1, mBitmaps, mOriginalImageSizes);218 verify(mCallback).onImageDownloaded((Bitmap) isNull());219 verify(mCallback, times(0)).onImageDownloaded((Bitmap) isNotNull());220 }221 @Test222 public void testDownloadImageFails() {223 mMediaImageManager.downloadImage(mImages, mCallback);224 mMediaImageManager.onFinishDownloadImage(225 REQUEST_ID_1, 404, IMAGE_URL_1, new ArrayList<Bitmap>(), new ArrayList<Rect>());226 verify(mCallback).onImageDownloaded((Bitmap) isNull());227 verify(mCallback, times(0)).onImageDownloaded((Bitmap) isNotNull());228 }229 @Test230 public void testEmptyImageList() {231 mImages.clear();232 mMediaImageManager.downloadImage(mImages, mCallback);233 verify(mWebContents, times(0))234 .downloadImage(anyString(), anyBoolean(), anyInt(), anyBoolean(),235 any(MediaImageManager.class));236 verify(mCallback).onImageDownloaded((Bitmap) isNull());237 verify(mCallback, times(0)).onImageDownloaded((Bitmap) isNotNull());238 }239 @Test240 public void testNullImageList() {241 mMediaImageManager.downloadImage(null, mCallback);242 verify(mWebContents, times(0))243 .downloadImage(anyString(), anyBoolean(), anyInt(), anyBoolean(),244 any(MediaImageManager.class));245 verify(mCallback).onImageDownloaded((Bitmap) isNull());246 verify(mCallback, times(0)).onImageDownloaded((Bitmap) isNotNull());247 }248}...

Full Screen

Full Screen

Source:ImagePushSWTBotTests.java Github

copy

Full Screen

...128 // wait for the push job to complete129 // then the 'push()' method on the client should have been called130 SWTUtils.wait(1, TimeUnit.SECONDS);131 Mockito.verify(client, Mockito.never()).tag(ArgumentMatchers.anyString(), ArgumentMatchers.anyString(),132 ArgumentMatchers.anyBoolean());133 Mockito.verify(client, Mockito.times(1)).push(ArgumentMatchers.eq("foo/bar:latest"),134 ArgumentMatchers.any(ProgressHandler.class));135 Mockito.verify(client, Mockito.never()).removeImage(ArgumentMatchers.anyString(), ArgumentMatchers.anyBoolean(),136 ArgumentMatchers.anyBoolean());137 }138 @Test139 public void shouldPushImageToLocalRegistry() throws DockerException, InterruptedException {140 // when141 MockRegistryAccountManagerFactory142 .registryAccount(new RegistryAccountInfo("http://localhost:5000", null, null, null, false)).build();143 openPushWizard();144 // when selecting other registry145 bot.comboBox(0).setSelection(1);146 // when click on Finish147 bot.button("Finish").click();148 // wait for the push job to complete149 // then the 'push()' method on the client should have been called150 SWTUtils.wait(1, TimeUnit.SECONDS);151 Mockito.verify(client, Mockito.times(1)).tag("foo/bar:latest", "localhost:5000/foo/bar:latest", false);152 Mockito.verify(client, Mockito.times(1)).push(ArgumentMatchers.eq("localhost:5000/foo/bar:latest"),153 ArgumentMatchers.any(ProgressHandler.class));154 Mockito.verify(client, Mockito.times(1)).removeImage("localhost:5000/foo/bar:latest", false, false);155 }156 @Test157 public void shouldPushImageWithForceTagging() throws DockerException, InterruptedException {158 // given159 MockRegistryAccountManagerFactory160 .registryAccount(new RegistryAccountInfo("http://foo.com", "foo", null, "secret".toCharArray(), false))161 .build();162 // when163 openPushWizard();164 // when tagging images with '--force'165 bot.checkBox(0).select();166 // when selecting other registry167 bot.comboBox(0).setSelection(1);168 // when click on Finish169 bot.button("Finish").click();170 // wait for the push job to complete171 // then the 'push()' method on the client should have been called172 SWTUtils.wait(1, TimeUnit.SECONDS);173 Mockito.verify(client, Mockito.times(1)).tag("foo/bar:latest", "foo.com/foo/bar:latest", true);174 Mockito.verify(client, Mockito.times(1)).push(ArgumentMatchers.any(),175 ArgumentMatchers.any(ProgressHandler.class));176 Mockito.verify(client, Mockito.times(1)).removeImage("foo.com/foo/bar:latest", false, false);177 }178 @Test179 public void shouldPushImageAndKeepTaggedImage() throws DockerException, InterruptedException {180 // given181 MockRegistryAccountManagerFactory182 .registryAccount(new RegistryAccountInfo("http://foo.com", "foo", null, "secret".toCharArray(), false))183 .build();184 openPushWizard();185 // when selecting other registry186 bot.comboBox(0).setSelection(1);187 // when keeping tagged images188 bot.checkBox(1).select();189 // when click on Finish190 bot.button("Finish").click();191 // wait for the push job to complete192 // then the 'push()' method on the client should have been called193 SWTUtils.wait(1, TimeUnit.SECONDS);194 Mockito.verify(client, Mockito.times(1)).tag("foo/bar:latest", "foo.com/foo/bar:latest", false);195 Mockito.verify(client, Mockito.times(1)).push(ArgumentMatchers.any(),196 ArgumentMatchers.any(ProgressHandler.class));197 Mockito.verify(client, Mockito.never()).removeImage(ArgumentMatchers.anyString(), ArgumentMatchers.anyBoolean(),198 ArgumentMatchers.anyBoolean());199 }200 @Test201 public void shouldPushImageWithNewTagToDockerHub() throws DockerException, InterruptedException {202 // given203 openPushWizard();204 // when providing a new name to the images205 bot.comboBox(1).setText("another/name");206 // when click on Finish207 bot.button("Finish").click();208 // wait for the push job to complete209 // then the 'push()' method on the client should have been called210 SWTUtils.wait(1, TimeUnit.SECONDS);211 Mockito.verify(client, Mockito.times(1)).tag("foo/bar:latest", "another/name:latest", false);212 Mockito.verify(client, Mockito.times(1)).push(ArgumentMatchers.any(),213 ArgumentMatchers.any(ProgressHandler.class));214 Mockito.verify(client, Mockito.times(1)).removeImage(ArgumentMatchers.anyString(),215 ArgumentMatchers.anyBoolean(), ArgumentMatchers.anyBoolean());216 }217 @Test218 public void shouldPushImageWithNewTagToAnotherRepo() throws DockerException, InterruptedException {219 // given220 MockRegistryAccountManagerFactory221 .registryAccount(new RegistryAccountInfo("http://foo.com", "foo", null, "secret".toCharArray(), false))222 .build();223 openPushWizard();224 // when selecting other registry225 bot.comboBox(0).setSelection(1);226 // when providing a new name to the images227 bot.comboBox(1).setText("another/name");228 // when click on Finish229 bot.button("Finish").click();230 // wait for the push job to complete231 // then the 'push()' method on the client should have been called232 SWTUtils.wait(1, TimeUnit.SECONDS);233 Mockito.verify(client, Mockito.times(1)).tag("foo/bar:latest", "foo.com/another/name:latest", false);234 Mockito.verify(client, Mockito.times(1)).push(ArgumentMatchers.any(),235 ArgumentMatchers.any(ProgressHandler.class));236 Mockito.verify(client, Mockito.times(1)).removeImage(ArgumentMatchers.anyString(),237 ArgumentMatchers.anyBoolean(), ArgumentMatchers.anyBoolean());238 }239 @Test240 public void shouldAddRegistry() {241 // given242 final String registryAddress = "https://foo.com";243 openPushWizard();244 // when click on the "Add..." link245 bot.link(0).click(WizardMessages.getString("ImagePullPushPage.add.label"));246 // fill the registry settings247 bot.text(0).setText(registryAddress);248 // finish249 bot.button("OK").click();250 // wait for the model updates to complete251 SWTUtils.wait(1, TimeUnit.SECONDS);...

Full Screen

Full Screen

Source:WorkflowResourceTest.java Github

copy

Full Screen

...23import java.util.List;24import java.util.Map;25import static org.junit.Assert.assertEquals;26import static org.mockito.ArgumentMatchers.any;27import static org.mockito.ArgumentMatchers.anyBoolean;28import static org.mockito.ArgumentMatchers.anyInt;29import static org.mockito.ArgumentMatchers.anyList;30import static org.mockito.ArgumentMatchers.anyLong;31import static org.mockito.ArgumentMatchers.anyMap;32import static org.mockito.ArgumentMatchers.anyString;33import static org.mockito.ArgumentMatchers.isNull;34import static org.mockito.Mockito.mock;35import static org.mockito.Mockito.times;36import static org.mockito.Mockito.verify;37import static org.mockito.Mockito.when;38public class WorkflowResourceTest {39 @Mock40 private WorkflowService mockWorkflowService;41 private WorkflowResource workflowResource;42 @Before43 public void before() {44 this.mockWorkflowService = mock(WorkflowService.class);45 this.workflowResource = new WorkflowResource(this.mockWorkflowService);46 }47 @Test48 public void testStartWorkflow() {49 StartWorkflowRequest startWorkflowRequest = new StartWorkflowRequest();50 startWorkflowRequest.setName("w123");51 Map<String, Object> input = new HashMap<>();52 input.put("1", "abc");53 startWorkflowRequest.setInput(input);54 String workflowID = "w112";55 when(mockWorkflowService.startWorkflow(any(StartWorkflowRequest.class))).thenReturn(workflowID);56 assertEquals("w112", workflowResource.startWorkflow(startWorkflowRequest));57 }58 @Test59 public void testStartWorkflowParam() {60 Map<String, Object> input = new HashMap<>();61 input.put("1", "abc");62 String workflowID = "w112";63 when(mockWorkflowService.startWorkflow(anyString(), anyInt(), anyString(), anyInt(), anyMap()))64 .thenReturn(workflowID);65 assertEquals("w112", workflowResource.startWorkflow("test1", 1, "c123", 0, input));66 }67 @Test68 public void getWorkflows() {69 Workflow workflow = new Workflow();70 workflow.setCorrelationId("123");71 ArrayList<Workflow> listOfWorkflows = new ArrayList<>() {{72 add(workflow);73 }};74 when(mockWorkflowService.getWorkflows(anyString(), anyString(), anyBoolean(), anyBoolean()))75 .thenReturn(listOfWorkflows);76 assertEquals(listOfWorkflows, workflowResource.getWorkflows("test1", "123", true, true));77 }78 @Test79 public void testGetWorklfowsMultipleCorrelationId() {80 Workflow workflow = new Workflow();81 workflow.setCorrelationId("c123");82 List<Workflow> workflowArrayList = new ArrayList<>() {{83 add(workflow);84 }};85 List<String> correlationIdList = new ArrayList<>() {{86 add("c123");87 }};88 Map<String, List<Workflow>> workflowMap = new HashMap<>();89 workflowMap.put("c123", workflowArrayList);90 when(mockWorkflowService.getWorkflows(anyString(), anyBoolean(), anyBoolean(), anyList()))91 .thenReturn(workflowMap);92 assertEquals(workflowMap, workflowResource.getWorkflows("test", true,93 true, correlationIdList));94 }95 @Test96 public void testGetExecutionStatus() {97 Workflow workflow = new Workflow();98 workflow.setCorrelationId("c123");99 when(mockWorkflowService.getExecutionStatus(anyString(), anyBoolean())).thenReturn(workflow);100 assertEquals(workflow, workflowResource.getExecutionStatus("w123", true));101 }102 @Test103 public void testDelete() {104 workflowResource.delete("w123", true);105 verify(mockWorkflowService, times(1)).deleteWorkflow(anyString(), anyBoolean());106 }107 @Test108 public void testGetRunningWorkflow() {109 List<String> listOfWorklfows = new ArrayList<>() {{110 add("w123");111 }};112 when(mockWorkflowService.getRunningWorkflows(anyString(), anyInt(), anyLong(), anyLong()))113 .thenReturn(listOfWorklfows);114 assertEquals(listOfWorklfows, workflowResource.getRunningWorkflow("w123", 1, 12L, 13L));115 }116 @Test117 public void testDecide() {118 workflowResource.decide("w123");119 verify(mockWorkflowService, times(1)).decideWorkflow(anyString());120 }121 @Test122 public void testPauseWorkflow() {123 workflowResource.pauseWorkflow("w123");124 verify(mockWorkflowService, times(1)).pauseWorkflow(anyString());125 }126 @Test127 public void testResumeWorkflow() {128 workflowResource.resumeWorkflow("test");129 verify(mockWorkflowService, times(1)).resumeWorkflow(anyString());130 }131 @Test132 public void testSkipTaskFromWorkflow() {133 workflowResource.skipTaskFromWorkflow("test", "testTask", null);134 verify(mockWorkflowService, times(1)).skipTaskFromWorkflow(anyString(), anyString(), isNull());135 }136 @Test137 public void testRerun() {138 RerunWorkflowRequest request = new RerunWorkflowRequest();139 workflowResource.rerun("test", request);140 verify(mockWorkflowService, times(1)).rerunWorkflow(anyString(), any(RerunWorkflowRequest.class));141 }142 @Test143 public void restart() {144 workflowResource.restart("w123", false);145 verify(mockWorkflowService, times(1)).restartWorkflow(anyString(), anyBoolean());146 }147 @Test148 public void testRetry() {149 workflowResource.retry("w123", false);150 verify(mockWorkflowService, times(1)).retryWorkflow(anyString(), anyBoolean());151 }152 @Test153 public void testResetWorkflow() {154 workflowResource.resetWorkflow("w123");155 verify(mockWorkflowService, times(1)).resetWorkflow(anyString());156 }157 @Test158 public void testTerminate() {159 workflowResource.terminate("w123", "test");160 verify(mockWorkflowService, times(1)).terminateWorkflow(anyString(), anyString());161 }162 @Test163 public void testSearch() {164 workflowResource.search(0, 100, "asc", "*", "*");...

Full Screen

Full Screen

Source:InstalledWebappGeolocationBridgeTest.java Github

copy

Full Screen

...4package org.chromium.chrome.browser.browserservices.permissiondelegation;5import static org.junit.Assert.assertFalse;6import static org.junit.Assert.assertTrue;7import static org.mockito.ArgumentMatchers.any;8import static org.mockito.ArgumentMatchers.anyBoolean;9import static org.mockito.ArgumentMatchers.anyDouble;10import static org.mockito.ArgumentMatchers.anyInt;11import static org.mockito.ArgumentMatchers.anyString;12import static org.mockito.ArgumentMatchers.eq;13import static org.mockito.Mockito.doAnswer;14import static org.mockito.Mockito.never;15import static org.mockito.Mockito.verify;16import android.os.Bundle;17import androidx.browser.trusted.TrustedWebActivityCallback;18import org.junit.Before;19import org.junit.Rule;20import org.junit.Test;21import org.junit.runner.RunWith;22import org.mockito.Mock;23import org.mockito.MockitoAnnotations;24import org.robolectric.annotation.Config;25import org.chromium.base.test.BaseRobolectricTestRunner;26import org.chromium.base.test.util.Feature;27import org.chromium.base.test.util.JniMocker;28import org.chromium.chrome.browser.browserservices.TrustedWebActivityClient;29import org.chromium.chrome.browser.flags.ChromeFeatureList;30import org.chromium.chrome.test.util.browser.Features.EnableFeatures;31import org.chromium.components.embedder_support.util.Origin;32/**33 * Tests for {@link InstalledWebappGeolocationBridge}.34 */35@RunWith(BaseRobolectricTestRunner.class)36@Config(manifest = Config.NONE)37@EnableFeatures(ChromeFeatureList.TRUSTED_WEB_ACTIVITY_LOCATION_DELEGATION)38public class InstalledWebappGeolocationBridgeTest {39 private static final Origin ORIGIN = Origin.create("https://www.website.com");40 private static final Origin OTHER_ORIGIN = Origin.create("https://www.other.website.com");41 private static final String EXTRA_CALLBACK = "extraCallback";42 private static final long NATIVE_POINTER = 12;43 @Rule44 public JniMocker mocker = new JniMocker();45 @Mock46 private TrustedWebActivityClient mTrustedWebActivityClient;47 @Mock48 private InstalledWebappGeolocationBridge.Natives mNativeMock;49 private InstalledWebappGeolocationBridge mGeolocation;50 private boolean mIsHighAccuracy = false;51 @Before52 public void setUp() {53 MockitoAnnotations.initMocks(this);54 mocker.mock(InstalledWebappGeolocationBridgeJni.TEST_HOOKS, mNativeMock);55 mGeolocation = new InstalledWebappGeolocationBridge(56 NATIVE_POINTER, ORIGIN, mTrustedWebActivityClient);57 }58 @Test59 @Feature("TrustedWebActivities")60 public void getLocationError_whenClientDoesntHaveService() {61 uninstallTrustedWebActivityService(ORIGIN);62 mGeolocation.start(false /* HighAccuracy */);63 verifyGetLocationError();64 }65 @Test66 @Feature("TrustedWebActivities")67 public void getLocationUpdate_afterStartListening() {68 installTrustedWebActivityService(ORIGIN);69 mGeolocation.start(false /* HighAccuracy */);70 verifyGetLocationUpdate();71 }72 @Test73 @Feature("TrustedWebActivities")74 public void noLocationUpdate_stopBeforeStart() {75 installTrustedWebActivityService(ORIGIN);76 mGeolocation.stopAndDestroy();77 mGeolocation.start(false /* HighAccuracy */);78 verifyNoLocationUpdate();79 }80 @Test81 @Feature("TrustedWebActivities")82 public void getLocationError_whenOnlytherClientHasService() {83 installTrustedWebActivityService(OTHER_ORIGIN);84 uninstallTrustedWebActivityService(ORIGIN);85 mGeolocation.start(false /* HighAccuracy */);86 verifyGetLocationError();87 verifyNoLocationUpdate();88 }89 @Test90 @Feature("TrustedWebActivities")91 public void changeHighAccuracyAfterStart() {92 installTrustedWebActivityService(ORIGIN);93 mGeolocation.start(false /* HighAccuracy */);94 assertFalse(mIsHighAccuracy);95 mGeolocation.start(true /* HighAccuracy */);96 assertTrue(mIsHighAccuracy);97 }98 /** "Installs" a Trusted Web Activity Service for the origin. */99 @SuppressWarnings("unchecked")100 private void installTrustedWebActivityService(Origin origin) {101 doAnswer(invocation -> {102 TrustedWebActivityCallback callback = invocation.getArgument(2);103 mIsHighAccuracy = invocation.getArgument(1);104 Bundle result = new Bundle();105 // Put arbitrary value to test the result bundle is converted correctly.106 // These value may not be valid geolocation data.107 result.putDouble("latitude", 1.0d);108 result.putDouble("longitude", -2.1d);109 result.putLong("timeStamp", 30);110 result.putDouble("altitude", 4.0d);111 result.putDouble("accuracy", 5.3d);112 result.putDouble("bearing", -6.4d);113 result.putDouble("speed", 7.5d);114 callback.onExtraCallback(115 InstalledWebappGeolocationBridge.EXTRA_NEW_LOCATION_AVAILABLE_CALLBACK, result);116 return true;117 })118 .when(mTrustedWebActivityClient)119 .startListeningLocationUpdates(eq(origin), anyBoolean(), any());120 }121 private void uninstallTrustedWebActivityService(Origin origin) {122 doAnswer(invocation -> {123 TrustedWebActivityCallback callback = invocation.getArgument(2);124 Bundle error = new Bundle();125 error.putString("message", "any errro message");126 callback.onExtraCallback(127 InstalledWebappGeolocationBridge.EXTRA_NEW_LOCATION_ERROR_CALLBACK, error);128 return true;129 })130 .when(mTrustedWebActivityClient)131 .startListeningLocationUpdates(eq(origin), anyBoolean(), any());132 }133 // Verify native gets location update with correct value.134 private void verifyGetLocationUpdate() {135 verify(mNativeMock)136 .onNewLocationAvailable(eq(NATIVE_POINTER), eq(1.0d), eq(-2.1d), eq(0.03d),137 eq(true), eq(4.0d), eq(true), eq(5.3d), eq(true), eq(-6.4d), eq(true),138 eq(7.5d));139 }140 private void verifyGetLocationError() {141 verify(mNativeMock).onNewErrorAvailable(eq(NATIVE_POINTER), anyString());142 }143 private void verifyNoLocationUpdate() {144 verify(mNativeMock, never())145 .onNewLocationAvailable(anyInt(), anyDouble(), anyDouble(), anyDouble(),146 anyBoolean(), anyDouble(), anyBoolean(), anyDouble(), anyBoolean(),147 anyDouble(), anyBoolean(), anyDouble());148 }149}...

Full Screen

Full Screen

Source:ActionProxyReceiverTest.java Github

copy

Full Screen

...18import static com.android.systemui.screenshot.GlobalScreenshot.EXTRA_ID;19import static com.android.systemui.screenshot.GlobalScreenshot.EXTRA_SMART_ACTIONS_ENABLED;20import static com.android.systemui.statusbar.phone.StatusBar.SYSTEM_DIALOG_REASON_SCREENSHOT;21import static org.mockito.ArgumentMatchers.any;22import static org.mockito.ArgumentMatchers.anyBoolean;23import static org.mockito.ArgumentMatchers.anyInt;24import static org.mockito.ArgumentMatchers.anyLong;25import static org.mockito.ArgumentMatchers.anyString;26import static org.mockito.ArgumentMatchers.eq;27import static org.mockito.ArgumentMatchers.isNull;28import static org.mockito.Mockito.doAnswer;29import static org.mockito.Mockito.never;30import static org.mockito.Mockito.verify;31import static org.mockito.Mockito.when;32import android.app.PendingIntent;33import android.content.Context;34import android.content.Intent;35import android.os.Bundle;36import android.testing.AndroidTestingRunner;37import androidx.test.filters.SmallTest;38import com.android.systemui.SysuiTestCase;39import com.android.systemui.shared.system.ActivityManagerWrapper;40import com.android.systemui.statusbar.phone.StatusBar;41import org.junit.Before;42import org.junit.Test;43import org.junit.runner.RunWith;44import org.mockito.Mock;45import org.mockito.MockitoAnnotations;46import org.mockito.stubbing.Answer;47import java.util.Optional;48import java.util.concurrent.ExecutionException;49import java.util.concurrent.Future;50import java.util.concurrent.TimeUnit;51import java.util.concurrent.TimeoutException;52@RunWith(AndroidTestingRunner.class)53@SmallTest54public class ActionProxyReceiverTest extends SysuiTestCase {55 @Mock56 private StatusBar mMockStatusBar;57 @Mock58 private ActivityManagerWrapper mMockActivityManagerWrapper;59 @Mock60 private Future mMockFuture;61 @Mock62 private ScreenshotSmartActions mMockScreenshotSmartActions;63 @Mock64 private PendingIntent mMockPendingIntent;65 private Intent mIntent;66 @Before67 public void setup() throws InterruptedException, ExecutionException, TimeoutException {68 MockitoAnnotations.initMocks(this);69 mIntent = new Intent(mContext, ActionProxyReceiver.class)70 .putExtra(GlobalScreenshot.EXTRA_ACTION_INTENT, mMockPendingIntent);71 when(mMockActivityManagerWrapper.closeSystemWindows(anyString())).thenReturn(mMockFuture);72 when(mMockFuture.get(anyLong(), any(TimeUnit.class))).thenReturn(null);73 }74 @Test75 public void testPendingIntentSentWithoutStatusBar() throws PendingIntent.CanceledException {76 ActionProxyReceiver actionProxyReceiver = constructActionProxyReceiver(false);77 actionProxyReceiver.onReceive(mContext, mIntent);78 verify(mMockActivityManagerWrapper).closeSystemWindows(SYSTEM_DIALOG_REASON_SCREENSHOT);79 verify(mMockStatusBar, never()).executeRunnableDismissingKeyguard(80 any(Runnable.class), any(Runnable.class), anyBoolean(), anyBoolean(), anyBoolean());81 verify(mMockPendingIntent).send(82 eq(mContext), anyInt(), isNull(), isNull(), isNull(), isNull(), any(Bundle.class));83 }84 @Test85 public void testPendingIntentSentWithStatusBar() throws PendingIntent.CanceledException {86 ActionProxyReceiver actionProxyReceiver = constructActionProxyReceiver(true);87 // ensure that the pending intent call is passed through88 doAnswer((Answer<Object>) invocation -> {89 ((Runnable) invocation.getArgument(0)).run();90 return null;91 }).when(mMockStatusBar).executeRunnableDismissingKeyguard(92 any(Runnable.class), isNull(), anyBoolean(), anyBoolean(), anyBoolean());93 actionProxyReceiver.onReceive(mContext, mIntent);94 verify(mMockActivityManagerWrapper).closeSystemWindows(SYSTEM_DIALOG_REASON_SCREENSHOT);95 verify(mMockStatusBar).executeRunnableDismissingKeyguard(96 any(Runnable.class), isNull(), eq(true), eq(true), eq(true));97 verify(mMockPendingIntent).send(98 eq(mContext), anyInt(), isNull(), isNull(), isNull(), isNull(), any(Bundle.class));99 }100 @Test101 public void testSmartActionsNotNotifiedByDefault() {102 ActionProxyReceiver actionProxyReceiver = constructActionProxyReceiver(true);103 actionProxyReceiver.onReceive(mContext, mIntent);104 verify(mMockScreenshotSmartActions, never())105 .notifyScreenshotAction(any(Context.class), anyString(), anyString(), anyBoolean());106 }107 @Test108 public void testSmartActionsNotifiedIfEnabled() {109 ActionProxyReceiver actionProxyReceiver = constructActionProxyReceiver(true);110 mIntent.putExtra(EXTRA_SMART_ACTIONS_ENABLED, true);111 String testId = "testID";112 mIntent.putExtra(EXTRA_ID, testId);113 actionProxyReceiver.onReceive(mContext, mIntent);114 verify(mMockScreenshotSmartActions).notifyScreenshotAction(115 mContext, testId, ACTION_TYPE_SHARE, false);116 }117 private ActionProxyReceiver constructActionProxyReceiver(boolean withStatusBar) {118 if (withStatusBar) {119 return new ActionProxyReceiver(...

Full Screen

Full Screen

Source:PizzaServiceUnitTest.java Github

copy

Full Screen

1package com.baeldung.mockito.fluentapi;2import static org.junit.Assert.assertEquals;3import static org.mockito.ArgumentMatchers.any;4import static org.mockito.ArgumentMatchers.anyBoolean;5import static org.mockito.ArgumentMatchers.anyInt;6import static org.mockito.ArgumentMatchers.anyString;7import static org.mockito.Mockito.verify;8import static org.mockito.Mockito.when;9import org.junit.Before;10import org.junit.Test;11import org.mockito.Answers;12import org.mockito.ArgumentCaptor;13import org.mockito.Captor;14import org.mockito.Mock;15import org.mockito.Mockito;16import org.mockito.MockitoAnnotations;17import com.baeldung.mockito.fluentapi.Pizza.PizzaBuilder;18import com.baeldung.mockito.fluentapi.Pizza.PizzaSize;19public class PizzaServiceUnitTest {20 @Mock21 private Pizza expectedPizza;22 @Mock(answer = Answers.RETURNS_DEEP_STUBS)23 private PizzaBuilder anotherbuilder;24 @Captor25 private ArgumentCaptor<String> stringCaptor;26 @Captor27 private ArgumentCaptor<Pizza.PizzaSize> sizeCaptor;28 @Before29 public void setup() {30 MockitoAnnotations.initMocks(this);31 }32 @Test33 public void givenTraditonalMocking_whenServiceInvoked_thenPizzaIsBuilt() {34 PizzaBuilder nameBuilder = Mockito.mock(Pizza.PizzaBuilder.class);35 PizzaBuilder sizeBuilder = Mockito.mock(Pizza.PizzaBuilder.class);36 PizzaBuilder firstToppingBuilder = Mockito.mock(Pizza.PizzaBuilder.class);37 PizzaBuilder secondToppingBuilder = Mockito.mock(Pizza.PizzaBuilder.class);38 PizzaBuilder stuffedBuilder = Mockito.mock(Pizza.PizzaBuilder.class);39 PizzaBuilder willCollectBuilder = Mockito.mock(Pizza.PizzaBuilder.class);40 PizzaBuilder discountBuilder = Mockito.mock(Pizza.PizzaBuilder.class);41 PizzaBuilder builder = Mockito.mock(Pizza.PizzaBuilder.class);42 when(builder.name(anyString())).thenReturn(nameBuilder);43 when(nameBuilder.size(any(Pizza.PizzaSize.class))).thenReturn(sizeBuilder);44 when(sizeBuilder.withExtraTopping(anyString())).thenReturn(firstToppingBuilder);45 when(firstToppingBuilder.withStuffedCrust(anyBoolean())).thenReturn(stuffedBuilder);46 when(stuffedBuilder.withExtraTopping(anyString())).thenReturn(secondToppingBuilder);47 when(secondToppingBuilder.willCollect(anyBoolean())).thenReturn(willCollectBuilder);48 when(willCollectBuilder.applyDiscount(anyInt())).thenReturn(discountBuilder);49 when(discountBuilder.build()).thenReturn(expectedPizza);50 PizzaService service = new PizzaService(builder);51 assertEquals("Expected Pizza", expectedPizza, service.orderHouseSpecial());52 verify(builder).name(stringCaptor.capture());53 assertEquals("Pizza name: ", "Special", stringCaptor.getValue());54 verify(nameBuilder).size(sizeCaptor.capture());55 assertEquals("Pizza size: ", PizzaSize.LARGE, sizeCaptor.getValue());56 }57 @Test58 public void givenDeepStubs_whenServiceInvoked_thenPizzaIsBuilt() {59 Mockito.when(anotherbuilder.name(anyString())60 .size(any(Pizza.PizzaSize.class))61 .withExtraTopping(anyString())62 .withStuffedCrust(anyBoolean())63 .withExtraTopping(anyString())64 .willCollect(anyBoolean())65 .applyDiscount(anyInt())66 .build())67 .thenReturn(expectedPizza);68 PizzaService service = new PizzaService(anotherbuilder);69 assertEquals("Expected Pizza", expectedPizza, service.orderHouseSpecial());70 }71}...

Full Screen

Full Screen

Source:ByteArrayFineIoWriterTest.java Github

copy

Full Screen

...11import org.powermock.api.mockito.PowerMockito;12import org.powermock.core.classloader.annotations.PrepareForTest;13import org.powermock.modules.junit4.PowerMockRunner;14import java.net.URI;15import static org.mockito.ArgumentMatchers.anyBoolean;16import static org.mockito.Mockito.atLeastOnce;17import static org.mockito.Mockito.times;18import static org.mockito.Mockito.verify;19import static org.mockito.Mockito.verifyNoMoreInteractions;20import static org.powermock.api.mockito.PowerMockito.mock;21import static org.powermock.api.mockito.PowerMockito.mockStatic;22import static org.powermock.api.mockito.PowerMockito.when;23/**24 * @author anchore25 * @date 2019/1/426 */27@RunWith(PowerMockRunner.class)28@PrepareForTest({ByteFineIoWriter.class, IntFineIoWriter.class, LongFineIoWriter.class, LongFineIoReader.class})29public class ByteArrayFineIoWriterTest {30 private final URI location = URI.create("/cubes/table/seg0/column/detail");31 private ByteWriter byteWriter = mock(ByteWriter.class);32 private IntWriter intWriter = mock(IntWriter.class);33 private LongWriter longWriter = mock(LongWriter.class);34 @Before35 public void setUp() throws Exception {36 mockStatic(ByteFineIoWriter.class);37 when(ByteFineIoWriter.build(ArgumentMatchers.<URI>any(), anyBoolean())).thenReturn(byteWriter);38 mockStatic(IntFineIoWriter.class);39 when(IntFineIoWriter.build(ArgumentMatchers.<URI>any(), anyBoolean())).thenReturn(intWriter);40 mockStatic(LongFineIoWriter.class);41 when(LongFineIoWriter.build(ArgumentMatchers.<URI>any(), anyBoolean())).thenReturn(longWriter);42 mockStatic(LongFineIoReader.class);43 LongReader longReader = mock(LongReader.class);44 when(LongFineIoReader.build(ArgumentMatchers.<URI>any())).thenReturn(longReader);45 PowerMockito.when(longReader.isReadable()).thenReturn(true);46 when(longReader.get(0)).thenReturn(1L);47 }48 @Test49 public void build() {50 ByteArrayFineIoWriter.build(location, true);51 ByteArrayFineIoWriter.build(location, false);52 }53 @Test54 public void put() {55 ByteArrayFineIoWriter.build(location, true).put(0, new byte[]{1, 2, 3});...

Full Screen

Full Screen

anyBoolean

Using AI Code Generation

copy

Full Screen

1import org.junit.Test;2import org.junit.runner.RunWith;3import org.mockito.Mock;4import org.mockito.junit.MockitoJUnitRunner;5import static org.mockito.Mockito.*;6@RunWith(MockitoJUnitRunner.class)7public class AnyBooleanTest {8 private AnyBoolean anyBoolean;9 public void testAnyBoolean() {10 when(anyBoolean.anyBooleanMethod(anyBoolean())).thenReturn("anyBoolean");11 String actual = anyBoolean.anyBooleanMethod(true);12 System.out.println(actual);13 }14}15import org.junit.Test;16import org.junit.runner.RunWith;17import org.mockito.Mock;18import org.mockito.junit.MockitoJUnitRunner;19import static org.mockito.Mockito.*;20@RunWith(MockitoJUnitRunner.class)21public class AnyBooleanTest {22 private AnyBoolean anyBoolean;23 public void testAnyBoolean() {24 when(anyBoolean.anyBooleanMethod(anyBoolean())).thenReturn("anyBoolean");25 String actual = anyBoolean.anyBooleanMethod(true);26 System.out.println(actual);27 }28}29import org.junit.Test;30import org.junit.runner.RunWith;31import org.mockito.Mock;32import org.mockito.junit.MockitoJUnitRunner;33import static org.mockito.Mockito.*;34@RunWith(MockitoJUnitRunner.class)35public class AnyBooleanTest {36 private AnyBoolean anyBoolean;37 public void testAnyBoolean() {38 when(anyBoolean.anyBooleanMethod(anyBoolean())).thenReturn("anyBoolean");39 String actual = anyBoolean.anyBooleanMethod(true);40 System.out.println(actual);41 }42}43 when(anyBoolean.anyBooleanMethod(anyBoolean())).thenReturn("anyBoolean");44 symbol: method anyBooleanMethod(boolean)45 when(anyBoolean.anyBooleanMethod(anyBoolean())).thenReturn("anyBoolean");46 symbol: method anyBoolean()

Full Screen

Full Screen

anyBoolean

Using AI Code Generation

copy

Full Screen

1package org.kodejava.example.mockito;2import org.junit.Test;3import org.mockito.ArgumentMatchers;4import static org.mockito.Mockito.mock;5import static org.mockito.Mockito.when;6public class AnyBooleanDemo {7 public void anyBoolean() {8 SomeService service = mock(SomeService.class);9 when(service.get(anyBoolean())).thenReturn("true");10 System.out.println(service.get(true));11 }12 class SomeService {13 public String get(boolean value) {14 return "false";15 }16 }17}18package org.kodejava.example.mockito;19import org.junit.Test;20import org.mockito.ArgumentMatchers;21import static org.mockito.Mockito.mock;22import static org.mockito.Mockito.when;23public class AnyBooleanDemo {24 public void anyBoolean() {25 SomeService service = mock(SomeService.class);26 when(service.get(anyBoolean())).thenReturn("true");27 System.out.println(service.get(true));28 }29 class SomeService {30 public String get(boolean value) {31 return "false";32 }33 }34}

Full Screen

Full Screen

anyBoolean

Using AI Code Generation

copy

Full Screen

1import static org.mockito.ArgumentMatchers.anyBoolean;2import static org.mockito.Mockito.mock;3import static org.mockito.Mockito.when;4public class MockitoExample {5 public static void main(String[] args) {6 Person person = mock(Person.class);7 when(person.getName(anyBoolean())).thenReturn("John Doe");8 System.out.println(person.getName(true));9 }10}11Related Posts: Mockito anyInt() Method Example12Mockito anyString() Method Example13Mockito anyDouble() Method Example14Mockito anyFloat() Method Example15Mockito anyLong() Method Example16Mockito anyByte() Method Example17Mockito anyChar() Method Example18Mockito anyObject() Method Example19Mockito any() Method Example20Mockito anyVararg() Method Example21Mockito anySet() Method Example22Mockito anyList() Method Example23Mockito anyMap() Method Example24Mockito anyCollection() Method Example25Mockito anyIterable() Method Example26Mockito anyArray() Method Example27Mockito anyClass() Method Example28Mockito anyEnum() Method Example29Mockito anyVararg() Method Example30Mockito anySet() Method Example

Full Screen

Full Screen

anyBoolean

Using AI Code Generation

copy

Full Screen

1import static org.mockito.ArgumentMatchers.anyBoolean;2import static org.mockito.Mockito.mock;3import static org.mockito.Mockito.when;4public class MockitoAnyBooleanExample {5 public static void main(String[] args) {6 MyClass test = mock(MyClass.class);7 when(test.getBoolean(anyBoolean())).thenReturn(true);8 System.out.println(test.getBoolean(true));9 }10}11class MyClass {12 public boolean getBoolean(boolean b) {13 return b;14 }15}16Related Posts: Mockito anyBoolean() method example17Mockito anyInt() method example18Mockito anyString() method example19Mockito any() method example20Mockito anyList() method example21Mockito anySet() method example22Mockito anyMap() method example23Mockito anyCollection() method example24Mockito anyIterable() method example25Mockito anyDouble() method example26Mockito anyFloat() method example27Mockito anyLong() method example28Mockito anyByte() method example29Mockito anyChar() method example30Mockito anyShort() method example31Mockito anyVararg() metho

Full Screen

Full Screen

anyBoolean

Using AI Code Generation

copy

Full Screen

1import org.mockito.ArgumentMatchers;2import static org.mockito.Mockito.mock;3import static org.mockito.Mockito.verify;4public class MockitoAnyBoolean {5 public static void main(String[] args) {6 Interface1 obj = mock(Interface1.class);7 obj.method1(true);8 verify(obj).method1(ArgumentMatchers.anyBoolean());9 }10}11interface Interface1 {12 void method1(boolean b);13}

Full Screen

Full Screen

anyBoolean

Using AI Code Generation

copy

Full Screen

1import org.mockito.ArgumentMatchers;2import static org.mockito.Mockito.*;3import org.mockito.Mockito;4import org.mockito.exceptions.verification.NoInteractionsWanted;5import org.mockito.internal.verification.TooLittleActualInvocations;6import org.mockito.internal.verification.TooManyActualInvocations;7import org.mockito.invocation.InvocationOnMock;8import org.mockito.stubbing.Answer;9public class AnyBooleanMethod {10 public static void main(String[] args) {11 MyInterface mock = mock(MyInterface.class);12 when(mock.myMethod(ArgumentMatchers.anyBoolean())).thenReturn("Hello World");13 System.out.println(mock.myMethod(true));14 }15}16import org.mockito.Matchers;17import static org.mockito.Mockito.*;18import org.mockito.Mockito;19import org.mockito.exceptions.verification.NoInteractionsWanted;20import org.mockito.internal.verification.TooLittleActualInvocations;21import org.mockito.internal.verification.TooManyActualInvocations;22import org.mockito.invocation.InvocationOnMock;23import org.mockito.stubbing.Answer;24public class AnyBooleanMethod {25 public static void main(String[] args) {26 MyInterface mock = mock(MyInterface.class);27 when(mock.myMethod(Matchers.anyBoolean())).thenReturn("Hello World");28 System.out.println(mock.myMethod(true));29 }30}31import static org.mockito.Mockito.*;32import org.mockito.Mockito;33import org.mockito.exceptions.verification.NoInteractionsWanted;34import org.mockito.internal.verification.TooLittleActualInvocations;35import org.mockito.internal.verification.TooManyActualInvocations;36import org.mockito.invocation.InvocationOnMock;37import org.mockito.stubbing.Answer;38public class AnyBooleanMethod {39 public static void main(String[] args) {40 MyInterface mock = mock(MyInterface.class);41 when(mock.myMethod(anyBoolean())).thenReturn("Hello World");42 System.out.println(mock.myMethod(true));43 }44}45import static org.mockito.Mockito.*;46import

Full Screen

Full Screen

anyBoolean

Using AI Code Generation

copy

Full Screen

1package com.automationtesting.mockitotesting;2import static org.mockito.ArgumentMatchers.anyBoolean;3import static org.mockito.Mockito.mock;4import static org.mockito.Mockito.when;5import java.util.List;6import org.junit.Test;7public class MockTest2 {8 public void test() {9 List mockList = mock(List.class);10 when(mockList.get(anyBoolean())).thenReturn("Mockito");11 System.out.println(mockList.get(1));12 }13}14AnyByte() method15package com.automationtesting.mockitotesting;16import static org.mockito.ArgumentMatchers.anyByte;17import static org.mockito.Mockito.mock;18import static org.mockito.Mockito.when;19import java.util.List;20import org.junit.Test;21public class MockTest3 {22 public void test() {23 List mockList = mock(List.class);24 when(mockList.get(anyByte())).thenReturn("Mockito");25 System.out.println(mockList.get(1));26 }27}28AnyChar() method29package com.automationtesting.mockitotesting;30import static org.mockito.ArgumentMatchers.anyChar;31import static org.mockito.Mockito.mock;32import static org.mockito.Mockito.when;33import java.util.List;34import org.junit.Test;35public class MockTest4 {36 public void test() {37 List mockList = mock(List.class);38 when(mockList.get(anyChar())).thenReturn("Mockito");39 System.out.println(mockList.get(1));40 }41}42In the above code, we are using anyChar() method of org.mockito.ArgumentMatchers class. This method will return a char value when the get()

Full Screen

Full Screen

anyBoolean

Using AI Code Generation

copy

Full Screen

1import org.mockito.ArgumentMatchers;2import org.mockito.Mockito;3import org.mockito.stubbing.Answer;4public class MockitoAnyBooleanMethodExample {5 public static void main(String[] args) {6 MyService service = Mockito.mock(MyService.class);7 Answer<Boolean> answer = invocation -> {8 Boolean arg = invocation.getArgument(0);9 System.out.println("Argument passed to method: " + arg);10 return arg;11 };12 Mockito.when(service.doIt(ArgumentMatchers.anyBoolean())).thenAnswer(answer);13 System.out.println("Result: " + service.doIt(true));14 }15}16import org.mockito.ArgumentMatchers;17import org.mockito.Mockito;18import org.mockito.stubbing.Answer;19public class MockitoAnyByteMethodExample {20 public static void main(String[] args) {21 MyService service = Mockito.mock(MyService.class);22 Answer<Byte> answer = invocation -> {23 Byte arg = invocation.getArgument(0);24 System.out.println("Argument passed to method: " + arg);25 return arg;26 };27 Mockito.when(service.doIt(ArgumentMatchers.anyByte())).thenAnswer(answer);28 System.out.println("Result: " + service.doIt((byte) 1));29 }30}31import org.mockito.ArgumentMatchers;32import org.mockito.Mockito;33import org.mockito.stubbing.Answer;34public class MockitoAnyCharMethodExample {35 public static void main(String[] args) {36 MyService service = Mockito.mock(MyService.class);37 Answer<Character> answer = invocation -> {38 Character arg = invocation.getArgument(0);39 System.out.println("Argument passed to method: " + arg);40 return arg;41 };42 Mockito.when(service.doIt(ArgumentMatchers.anyChar())).thenAnswer(answer);43 System.out.println("Result: " + service.doIt('a'));44 }45}46import org.mockito47Mockito anyCollection() Method Example48Mockito anyIterable() Method Example49Mockito anyArray() Method Example50Mockito anyClass() Method Example51Mockito anyEnum() Method Example52Mockito anyVararg() Method Example53Mockito anySet() Method Example

Full Screen

Full Screen

anyBoolean

Using AI Code Generation

copy

Full Screen

1import static org.mockito.ArgumentMatchers.anyBoolean;2import static org.mockito.Mockito.mock;3import static org.mockito.Mockito.when;4public class MockitoAnyBooleanExample {5 public static void main(String[] args) {6 MyClass test = mock(MyClass.class);7 when(test.getBoolean(anyBoolean())).thenReturn(true);8 System.out.println(test.getBoolean(true));9 }10}11class MyClass {12 public boolean getBoolean(boolean b) {13 return b;14 }15}16Related Posts: Mockito anyBoolean() method example17Mockito anyInt() method example18Mockito anyString() method example19Mockito any() method example20Mockito anyList() method example21Mockito anySet() method example22Mockito anyMap() method example23Mockito anyCollection() method example24Mockito anyIterable() method example25Mockito anyDouble() method example26Mockito anyFloat() method example27Mockito anyLong() method example28Mockito anyByte() method example29Mockito anyChar() method example30Mockito anyShort() method example31Mockito anyVararg() metho

Full Screen

Full Screen

anyBoolean

Using AI Code Generation

copy

Full Screen

1import org.mockito.ArgumentMatchers;2import static org.mockito.Mockito.mock;3import static org.mockito.Mockito.verify;4public class MockitoAnyBoolean {5 public static void main(String[] args) {6 Interface1 obj = mock(Interface1.class);7 obj.method1(true);8 verify(obj).method1(ArgumentMatchers.anyBoolean());9 }10}11interface Interface1 {12 void method1(boolean b);13}

Full Screen

Full Screen

anyBoolean

Using AI Code Generation

copy

Full Screen

1import org.mockito.ArgumentMatchers;2import org.mockito.Mockito;3import org.mockito.stubbing.Answer;4public class MockitoAnyBooleanMethodExample {5 public static void main(String[] args) {6 MyService service = Mockito.mock(MyService.class);7 Answer<Boolean> answer = invocation -> {8 Boolean arg = invocation.getArgument(0);9 System.out.println("Argument passed to method: " + arg);10 return arg;11 };12 Mockito.when(service.doIt(ArgumentMatchers.anyBoolean())).thenAnswer(answer);13 System.out.println("Result: " + service.doIt(true));14 }15}16import org.mockito.ArgumentMatchers;17import org.mockito.Mockito;18import org.mockito.stubbing.Answer;19public class MockitoAnyByteMethodExample {20 public static void main(String[] args) {21 MyService service = Mockito.mock(MyService.class);22 Answer<Byte> answer = invocation -> {23 Byte arg = invocation.getArgument(0);24 System.out.println("Argument passed to method: " + arg);25 return arg;26 };27 Mockito.when(service.doIt(ArgumentMatchers.anyByte())).thenAnswer(answer);28 System.out.println("Result: " + service.doIt((byte) 1));29 }30}31import org.mockito.ArgumentMatchers;32import org.mockito.Mockito;33import org.mockito.stubbing.Answer;34public class MockitoAnyCharMethodExample {35 public static void main(String[] args) {36 MyService service = Mockito.mock(MyService.class);37 Answer<Character> answer = invocation -> {38 Character arg = invocation.getArgument(0);39 System.out.println("Argument passed to method: " + arg);40 return arg;41 };42 Mockito.when(service.doIt(ArgumentMatchers.anyChar())).thenAnswer(answer);43 System.out.println("Result: " + service.doIt('a'));44 }45}46import org.mockito

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful