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

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

Source:InstalledWebappGeolocationBridgeTest.java Github

copy

Full Screen

...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:BankenTest.java Github

copy

Full Screen

...45 long kontonummer1 = bank.mockEinfuegen(k1);46 bank.mockEinfuegen(gk1);47 Mockito.when(k1.abheben(100)).thenReturn(true);48 bank.geldAbheben(kontonummer1,100);49 Mockito.verify(k1,Mockito.times(1)).abheben(ArgumentMatchers.anyDouble());50 Mockito.verifyNoInteractions(gk1);51 }**/52 /**53 @Test54 public void geldAbhebenMehrfachTest() throws GesperrtException {55 long kontonummer1 = bank.mockEinfuegen(k1);56 long kontonummer2 = bank.mockEinfuegen(sb1);57 Mockito.when(k1.abheben(100)).thenReturn(true);58 Mockito.when(k2.abheben(100)).thenReturn(true);59 bank.geldAbheben(kontonummer1,100);60 bank.geldAbheben(kontonummer2,100);61 Mockito.verify(k1,Mockito.times(1)).abheben(ArgumentMatchers.anyDouble());62 Mockito.verify(sb1,Mockito.times(1)).abheben(ArgumentMatchers.anyDouble());63 }**/64 @Test65 public void geldEinzahlenEinzelTest() throws GesperrtException {66 long kontonummergk1 = bank.kontoErstellen(new MockKontoFabrik(gk1), kunde1);67 bank.kontoErstellen(new MockKontoFabrik(gk2), kunde1);68 bank.geldEinzahlen(kontonummergk1,100);69 Mockito.verify(gk1,Mockito.times(1)).einzahlen(ArgumentMatchers.anyDouble());70 Mockito.verifyNoInteractions(gk2);71 }72 @Test73 public void geldEinzahlenMehrfachTest() throws GesperrtException {74 long kontonummer1 = bank.kontoErstellen(new MockKontoFabrik(sb1), kunde1);75 long kontonummer2 = bank.kontoErstellen(new MockKontoFabrik(k2), kunde1);76 bank.geldEinzahlen(kontonummer1,100);77 bank.geldEinzahlen(kontonummer2,100);78 Mockito.verify(k2,Mockito.times(1)).einzahlen(ArgumentMatchers.anyDouble());79 Mockito.verify(sb1,Mockito.times(1)).einzahlen(ArgumentMatchers.anyDouble());80 }81 /**82 @Test83 public void KontoGesperrtTest() throws GesperrtException {84 long kontonummer1 = bank.kontoErstellen(new MockKontoFabrik(k1), kunde1);85 bank.kontoErstellen(new MockKontoFabrik(k2), kunde1);86 Mockito.when(k1.abheben(ArgumentMatchers.anyDouble())).thenThrow(GesperrtException.class);87 assertThrows(GesperrtException.class, () -> bank.geldAbheben(kontonummer1,100));88 Mockito.verifyNoInteractions(k2);89 }**/90 /**91 @Test92 public void DispoUberzogenTest() throws GesperrtException {93 long kontonummer1 = bank.kontoErstellen(new MockKontoFabrik(gk1), kunde1);94 bank.kontoErstellen(new MockKontoFabrik(gk2), kunde1);95 Mockito.when(gk1.abheben(ArgumentMatchers.anyDouble())).thenReturn(false);96 assertFalse(bank.geldAbheben(kontonummer1,100000));97 Mockito.verifyNoInteractions(gk2);98 }**/99 @Test100 public void KontoLoeschen(){101 long kontonummer1 = bank.kontoErstellen(new MockKontoFabrik(k1), kunde1);102 long kontonummer2 = bank.kontoErstellen(new MockKontoFabrik(k2), kunde1);103 assertTrue(bank.kontoLoeschen(kontonummer1));104 assertEquals(kontonummer2,bank.getAlleKontonummern().get(0));105 Mockito.verifyNoInteractions(k1);106 Mockito.verifyNoInteractions(k2);107 }108 @Test109 public void ueberweisenTest() throws GesperrtException {110 gk1.setInhaber(kunde1);111 gk2.setInhaber(kunde2);112 long kontonummer1 = bank.kontoErstellen(new MockKontoFabrik(gk1), kunde1);113 long kontonummer2 = bank.kontoErstellen(new MockKontoFabrik(gk2), kunde1);114 Mockito.when(kunde1.getName()).thenReturn("Kunde1");115 Mockito.when(kunde2.getName()).thenReturn("Kunde2");116 Mockito.when(gk1.ueberweisungAbsenden(ArgumentMatchers.anyDouble(),ArgumentMatchers.anyString(),ArgumentMatchers.anyLong(),ArgumentMatchers.anyLong(),ArgumentMatchers.anyString())).thenReturn(true);117 bank.geldUeberweisen(kontonummer1,kontonummer2,100,"Test");118 Mockito.verify(gk1).ueberweisungAbsenden(ArgumentMatchers.anyDouble(),ArgumentMatchers.anyString(),ArgumentMatchers.anyLong(),ArgumentMatchers.anyLong(),ArgumentMatchers.anyString());119 Mockito.verify(gk2).ueberweisungEmpfangen(ArgumentMatchers.anyDouble(),ArgumentMatchers.anyString(),ArgumentMatchers.anyLong(),ArgumentMatchers.anyLong(),ArgumentMatchers.anyString());120 }121 @Test122 void testClone() {123 Bank sparkasse = new Bank(111);124 Kunde bob = new Kunde();125 long bobnr = sparkasse.kontoErstellen(new GirokontoFabrik(),bob);126 Bank billigeKopie = sparkasse.clone();127 assertNotEquals(sparkasse,billigeKopie);128 assertEquals(sparkasse.getBankleitzahl(), billigeKopie.getBankleitzahl());129 assertEquals(sparkasse.getAlleKontonummern(),billigeKopie.getAlleKontonummern());130 assertEquals(sparkasse.getKontonummernLuecken(),billigeKopie.getKontonummernLuecken());131 //assertEquals(sparkasse.getAlleKonten(),billigeKopie.getAlleKonten());132 //assertEquals(sparkasse.getKundenGeburtstage(),billigeKopie.getKundenGeburtstage());133 sparkasse.geldEinzahlen(bobnr,100);...

Full Screen

Full Screen

Source:BankMockitoTest.java Github

copy

Full Screen

...28 public void init() throws Exception {29 bank = new Bank(17122000); //Bank die getestet wird30 kunde = new Kunde(); // Standardkunde31 giroMock1 = Mockito.mock(Girokonto.class);32 Mockito.when(giroMock1.abheben(ArgumentMatchers.anyDouble())).thenReturn(true);33 Mockito.when(giroMock1.getInhaber()).thenReturn(kunde);34 Mockito.when(giroMock1.getKontostand()).thenReturn(4761D);35 Mockito.when(giroMock1.getKontonummer()).thenReturn(1L);36 Mockito.when(giroMock1.isGesperrt()).thenReturn(false);37 Mockito.when(giroMock1.getDispo()).thenReturn(500D);38 Mockito.when(giroMock1.ueberweisungAbsenden(ArgumentMatchers.anyDouble(),ArgumentMatchers.anyString(),ArgumentMatchers.anyLong(), ArgumentMatchers.anyLong(),ArgumentMatchers.anyString())).thenReturn(true);39 giroMock2 = Mockito.mock(Girokonto.class);40 Mockito.when(giroMock2.abheben(ArgumentMatchers.anyDouble())).thenReturn(true);41 Mockito.when(giroMock2.getInhaber()).thenReturn(kunde);42 Mockito.when(giroMock2.getKontostand()).thenReturn(360D);43 Mockito.when(giroMock2.getKontonummer()).thenReturn(2L);44 Mockito.when(giroMock2.isGesperrt()).thenReturn(false);45 Mockito.when(giroMock2.getDispo()).thenReturn(1000D);46 Mockito.when(giroMock2.ueberweisungAbsenden(ArgumentMatchers.anyDouble(),ArgumentMatchers.anyString(),ArgumentMatchers.anyLong(), ArgumentMatchers.anyLong(),ArgumentMatchers.anyString())).thenReturn(true);47 sparMock1 = Mockito.mock(Sparbuch.class);48 Mockito.when(sparMock1.abheben(ArgumentMatchers.anyDouble())).thenReturn(true);49 Mockito.when(sparMock1.getInhaber()).thenReturn(kunde);50 Mockito.when(sparMock1.getKontostand()).thenReturn(100D);51 Mockito.when(sparMock1.getKontonummer()).thenReturn(3L);52 Mockito.when(sparMock1.isGesperrt()).thenReturn(false);53 sparMock2 = Mockito.mock(Sparbuch.class);54 Mockito.when(sparMock2.abheben(ArgumentMatchers.anyDouble())).thenReturn(true);55 Mockito.when(sparMock2.getInhaber()).thenReturn(kunde);56 Mockito.when(sparMock2.getKontostand()).thenReturn(300D);57 Mockito.when(sparMock2.getKontonummer()).thenReturn(4L);58 Mockito.when(sparMock2.isGesperrt()).thenReturn(false);59 }60 @Test61 public void testBank(){62 long blz = bank.getBankleitzahl();63 assertEquals(17122000, blz);64 String konten = bank.getAlleKonten();65 assertEquals("", konten);66 try {67 bank.geldEinzahlen(123456, 1);68 fail("Konto existiert nicht.");69 } catch (KontoDoesntExistException ignored){}70 }71 @Test72 public void testKontenEinfuegen(){73 fillBank();74 List<Long> kontenliste = bank.getAlleKontonummern();75 assertTrue(kontenliste.containsAll(Arrays.asList(1L,2L,3L,4L)));76 assertEquals(4, kontenliste.size());77 assertTrue(giroMock1 != giroMock2 && sparMock1 != sparMock2);78 }79 @Test80 public void testEinzahlen() throws KontoDoesntExistException {81 fillBank();82 bank.geldEinzahlen(1,1);83 bank.geldEinzahlen(2,2);84 bank.geldEinzahlen(3,3);85 bank.geldEinzahlen(4,4);86 Mockito.verify(giroMock1).einzahlen(1);87 Mockito.verify(giroMock2).einzahlen(2);88 Mockito.verify(sparMock1).einzahlen(3);89 Mockito.verify(sparMock2).einzahlen(4);90 }91 @Test92 public void testEinzahlenKeinKonto(){93 //kein fillBank();94 try {95 bank.geldEinzahlen(giro1,1);96 Assertions.fail();97 } catch (KontoDoesntExistException ignored) {98 }99 }100 @Test101 public void testEinzahlenMinus() throws KontoDoesntExistException {102 fillBank();103 Mockito.doThrow(new IllegalArgumentException("negativer Wert beim Einzahlen.")).when(giroMock1).einzahlen(ArgumentMatchers.anyDouble()); // Müsste eigtl <0 sein, aber hier egal104 try {105 bank.geldEinzahlen(giro1,-1);106 Assertions.fail();107 } catch (IllegalArgumentException ignored){108 }109 }110 @Test111 public void testAbheben() throws GesperrtException, KontoDoesntExistException {112 fillBank();113 assertTrue(bank.geldAbheben(giro1, 1));114 Mockito.verify(giroMock1).abheben(1);115 }116 @Test117 public void testAbhebenKeinKonto() throws GesperrtException {...

Full Screen

Full Screen

Source:NearByAttractionOperationTest.java Github

copy

Full Screen

1package com.tripmaster.tourguide.gpsService.unit;2import static org.junit.jupiter.api.Assertions.*;3import static org.mockito.ArgumentMatchers.any;4import static org.mockito.ArgumentMatchers.anyDouble;5import static org.mockito.ArgumentMatchers.anyList;6import static org.mockito.Mockito.doThrow;7import static org.mockito.Mockito.when;8import java.util.ArrayList;9import java.util.List;10import java.util.UUID;11import org.junit.jupiter.api.BeforeAll;12import org.junit.jupiter.api.Test;13import org.junit.jupiter.api.extension.ExtendWith;14import org.mockito.InjectMocks;15import org.mockito.Mock;16import org.mockito.junit.jupiter.MockitoExtension;17import com.tripmaster.tourguide.gpsService.clients.IRewardServiceClient;18import com.tripmaster.tourguide.gpsService.converters.IConverterLibAttraction;19import com.tripmaster.tourguide.gpsService.converters.IConverterLibLocation;20import com.tripmaster.tourguide.gpsService.exceptions.ConverterLibException;21import com.tripmaster.tourguide.gpsService.exceptions.HttpException;22import com.tripmaster.tourguide.gpsService.model.MAttraction;23import com.tripmaster.tourguide.gpsService.model.MLocation;24import com.tripmaster.tourguide.gpsService.util.IHelper;25import com.tripmaster.tourguide.gpsService.util.INearByAttractionOperation;26import com.tripmaster.tourguide.gpsService.util.NearByAttractionOperationImpl;27import gpsUtil.GpsUtil;28import gpsUtil.location.Attraction;29import gpsUtil.location.Location;30import gpsUtil.location.VisitedLocation;31@ExtendWith(MockitoExtension.class)32class NearByAttractionOperationTest {33 34 @Mock35 private GpsUtil gpsUtil;36 37 @Mock38 private IHelper helper;39 40 @Mock41 private IConverterLibAttraction attractionConverter;42 43 @Mock44 private IConverterLibLocation locationConverter;45 46 @Mock47 private IRewardServiceClient rewardService;48 49 @InjectMocks50 private INearByAttractionOperation nearByAttractionOperation = new NearByAttractionOperationImpl();51 52 private static List<Attraction> attractions;53 private static List<MAttraction> mAttractions;54 private static Location location;55 private static MLocation mLocation;56 private static VisitedLocation visitedLocation;57 58 @BeforeAll59 private static void setUp() {60 attractions = new ArrayList<>();61 mAttractions = new ArrayList<>();62 for(int i = 0; i < 10; i++) {63 Attraction attraction = new Attraction("name" + i, "city", "state", 10d, 20d);64 attractions.add(attraction);65 MAttraction mAttraction = new MAttraction("name" + i, "city", "state", 10d, 20d);66 mAttraction.setAttractionId(UUID.randomUUID());67 mAttractions.add(mAttraction);68 }69 location = new Location(10d, 20d);70 mLocation = new MLocation(10d, 20d);71 visitedLocation = new VisitedLocation(null, location, null);72 }73 @Test74 void getNearByAttractionsReturnsListWhenOk() throws ConverterLibException, HttpException {75 when(gpsUtil.getAttractions()).thenReturn(attractions);76 when(attractionConverter.convertLibAttractionsToMAttractions(anyList())).thenReturn(mAttractions);77 when(gpsUtil.getUserLocation(any(UUID.class))).thenReturn(visitedLocation);78 when(locationConverter.convertLibModelToModel(any(Location.class))).thenReturn(mLocation);79 when(helper.calculateDistance(anyDouble(), anyDouble(), anyDouble(), anyDouble()))80 .thenReturn(10d, 20d, 30d, 40d, 50d, 60d, 70d, 80d, 90d, 100d);81 when(rewardService.getAttractionRewardPoints(any(UUID.class), any(UUID.class))).thenReturn(100);82 assertEquals(5, nearByAttractionOperation.getNearByAttractions(UUID.randomUUID()).size());83 }84 @Test85 void getNearByAttractionsThrowsExceptionWhenServiceError() throws ConverterLibException, HttpException {86 when(gpsUtil.getAttractions()).thenReturn(attractions);87 when(attractionConverter.convertLibAttractionsToMAttractions(anyList())).thenReturn(mAttractions);88 when(gpsUtil.getUserLocation(any(UUID.class))).thenReturn(visitedLocation);89 when(locationConverter.convertLibModelToModel(any(Location.class))).thenReturn(mLocation);90 when(helper.calculateDistance(anyDouble(), anyDouble(), anyDouble(), anyDouble()))91 .thenReturn(10d, 20d, 30d, 40d, 50d, 60d, 70d, 80d, 90d, 100d);92 doThrow(HttpException.class).when(rewardService)93 .getAttractionRewardPoints(any(UUID.class), any(UUID.class));94 assertThrows(HttpException.class, 95 () -> nearByAttractionOperation.getNearByAttractions(UUID.randomUUID()));96 }97}...

Full Screen

Full Screen

Source:BridgeServiceTest.java Github

copy

Full Screen

...24 @Test25 public void testAddBridgeSuccess(){26 Bridge bridgeToAdd = new Bridge(1,2,3,4,56,"London Bridge");27 when(bridgeRepository.findBridgeByName(ArgumentMatchers.anyString())).thenReturn(null);28 when(bridgeRepository.findBridgeByLatitudeAndLongitude(ArgumentMatchers.anyDouble(),ArgumentMatchers.anyDouble())).thenReturn(null);29 when(bridgeRepository.save(ArgumentMatchers.any(Bridge.class))).thenReturn(bridgeToAdd);30 Assert.isInstanceOf(Bridge.class, bridgeService.addBridge(bridgeToAdd), "Should return a bridge");31 verify(bridgeRepository,times(1)).findBridgeByName(ArgumentMatchers.anyString());32 verify(bridgeRepository,times(1)).findBridgeByLatitudeAndLongitude(ArgumentMatchers.anyDouble(), ArgumentMatchers.anyDouble());33 verify(bridgeRepository,times(1)).save(ArgumentMatchers.any(Bridge.class));34 }35 @Test36 public void testAddBridgeFailedNameAlreadyExist(){37 Bridge bridgeToAdd = new Bridge(1,2,3,4,56,"London Bridge");38 when(bridgeRepository.findBridgeByName(ArgumentMatchers.anyString())).thenReturn(bridgeToAdd);39 try{40 bridgeService.addBridge(bridgeToAdd);41 }catch (Exception e){42 Assert.isInstanceOf(NameAlreadyExistException.class, e, "Should return exception when name already exist");43 }44 verify(bridgeRepository,times(1)).findBridgeByName(ArgumentMatchers.anyString());45 verify(bridgeRepository,times(0)).findBridgeByLatitudeAndLongitude(ArgumentMatchers.anyDouble(), ArgumentMatchers.anyDouble());46 verify(bridgeRepository,times(0)).save(ArgumentMatchers.any(Bridge.class));47 }48 @Test49 public void testAddBridgeFailedLocationOccupied(){50 Bridge bridgeToAdd = new Bridge(1,2,3,4,56,"London Bridge");51 Bridge bridgeDB = new Bridge(1,2,3,4,56,"Rio Bridge");52 when(bridgeRepository.findBridgeByName(ArgumentMatchers.anyString())).thenReturn(null);53 when(bridgeRepository.findBridgeByLatitudeAndLongitude(ArgumentMatchers.anyDouble(),ArgumentMatchers.anyDouble())).thenReturn(bridgeDB);54 try{55 bridgeService.addBridge(bridgeToAdd);56 }catch (Exception e){57 Assert.isInstanceOf(LatAndLongAlreadyExistException.class, e, "Should return exception when location already occupied");58 }59 verify(bridgeRepository,times(1)).findBridgeByName(ArgumentMatchers.anyString());60 verify(bridgeRepository,times(1)).findBridgeByLatitudeAndLongitude(ArgumentMatchers.anyDouble(), ArgumentMatchers.anyDouble());61 verify(bridgeRepository,times(0)).save(ArgumentMatchers.any(Bridge.class));62 }63 @Test64 public void testGetAllBridges() {65 Bridge bridgeDB1 = new Bridge(1,2,3,78,56,"Rio Bridge");66 Bridge bridgeDB2 = new Bridge(1,2,3,4,20,"Denver Bridge");67 List<Bridge> databaseResponse = new ArrayList<>();68 databaseResponse.add(bridgeDB1);69 databaseResponse.add(bridgeDB2);70 when(bridgeRepository.findAll()).thenReturn(databaseResponse);71 Assert.isInstanceOf(ArrayList.class, bridgeService.getAllBridges(), "Should return a list of bridges");72 }73}...

Full Screen

Full Screen

Source:RuleServiceTest.java Github

copy

Full Screen

...10import org.mockito.Mock;11import org.mockito.junit.jupiter.MockitoExtension;12import static org.junit.jupiter.api.Assertions.assertEquals;13import static org.junit.jupiter.api.Assertions.assertThrows;14import static org.mockito.ArgumentMatchers.anyDouble;15import static org.mockito.ArgumentMatchers.eq;16import static org.mockito.Mockito.when;17@ExtendWith(MockitoExtension.class)18public class RuleServiceTest {19 @Mock20 private RuleRepository repository;21 @InjectMocks22 private RuleService service;23 @Test24 void contextLoads() {25 assertEquals(0, repository.count(), "You should try to set spring.profiles.active to test in env variables");26 }27 @Test28 void sanity() {29 assertThrows(ApiException.class, () -> service.computeScore(null));30 }31 @Test32 void computeProduct() {33 Product product = new Product("7622210449283", new ProductJson(34 "Prince Chocolat",35 "BISCUITS FOURRÉS (35%) PARFUM CHOCOLAT",36 new Nutriment(37 1962.0,38 5.6,39 32.0,40 0.49,41 4.0,42 6.343 )44 ));45 when(repository.getComponentPoints(eq("energy_100g"), anyDouble())).thenReturn(5d);46 when(repository.getComponentPoints(eq("saturated-fat_100g"), anyDouble())).thenReturn(5d);47 when(repository.getComponentPoints(eq("sugars_100g"), anyDouble())).thenReturn(7d);48 when(repository.getComponentPoints(eq("salt_100g"), anyDouble())).thenReturn(0d);49 when(repository.getComponentPoints(eq("fiber_100g"), anyDouble())).thenReturn(5d);50 when(repository.getComponentPoints(eq("proteins_100g"), anyDouble())).thenReturn(3d);51 assertEquals(9, service.computeScore(product));52 }53}...

Full Screen

Full Screen

Source:OrderProductsServiceImplTest.java Github

copy

Full Screen

...10import reactor.core.publisher.Flux;11import java.util.Collections;12import java.util.List;13import java.util.UUID;14import static org.mockito.ArgumentMatchers.anyDouble;15import static org.mockito.ArgumentMatchers.anyString;16import static org.mockito.Mockito.times;17import static org.mockito.Mockito.verify;18@ExtendWith(MockitoExtension.class)19class OrderProductsServiceImplTest {20 @InjectMocks21 OrderProductsServiceImpl orderProductsService;22 @Mock23 OrderProductsRepository orderProductsRepository;24 @Test25 void testSaveProductsForOrder_GivenValidParameters_ShouldReturnNothing() {26 Product product = Product.builder()27 .id(123)28 .price("1.0")29 .name("testProduct")30 .amount(1.0)31 .discount("1.0")32 .skuId("skuId")33 .build();34 List<Product> products = Collections.singletonList(product);35 String orderId = UUID.randomUUID().toString();36 Flux<Integer> result = Flux.just(1);37 Mockito.when(this.orderProductsRepository.insertOrderProduct(anyString(), anyString(), anyString(), anyString(), anyDouble(), anyDouble(), anyDouble())).thenReturn(result);38 this.orderProductsService.saveProductsForOrder(products, orderId);39 verify(this.orderProductsRepository, times(1)).insertOrderProduct(anyString(), anyString(), anyString(), anyString(), anyDouble(), anyDouble(), anyDouble());40 }41}...

Full Screen

Full Screen

Source:OrderServiceImplTest.java Github

copy

Full Screen

...10import reactor.core.publisher.Flux;11import java.time.LocalDateTime;12import static org.junit.jupiter.api.Assertions.*;13import static org.mockito.ArgumentMatchers.any;14import static org.mockito.ArgumentMatchers.anyDouble;15import static org.mockito.ArgumentMatchers.anyString;16@ExtendWith(MockitoExtension.class)17class OrderServiceImplTest {18 @InjectMocks19 OrderServiceImpl orderService;20 @Mock21 OrderRepository orderRepository;22 @Test23 void testSave_GivenValidInputs_ShouldReturnNothing() {24 Order order = Order.builder()25 .userId("userId")26 .total(2.0)27 .subTotal(2.0)28 .id("id")29 .taxes(2.0)30 .discounts(2.0)31 .createdDate(LocalDateTime.now())32 .build();33 Flux<Integer> databaseResponse = Flux.just(1);34 Mockito.when(this.orderRepository.insertOrder(anyString(), anyString(), anyDouble(), anyDouble(), anyDouble(), anyDouble(), any(LocalDateTime.class))).thenReturn(databaseResponse);35 this.orderService.save(order);36 Mockito.verify(this.orderRepository, Mockito.times(1)).insertOrder(anyString(), anyString(), anyDouble(), anyDouble(), anyDouble(), anyDouble(), any(LocalDateTime.class));37 }38}...

Full Screen

Full Screen

anyDouble

Using AI Code Generation

copy

Full Screen

1import static org.mockito.ArgumentMatchers.anyDouble;2import static org.mockito.Mockito.mock;3import static org.mockito.Mockito.when;4import static org.mockito.Mockito.verify;5import org.junit.Assert;6import org.junit.Test;7import org.junit.runner.RunWith;8import org.mockito.junit.MockitoJUnitRunner;9import java.util.List;10@RunWith(MockitoJUnitRunner.class)11public class MockitoDemoTest {12 public void testAnyDouble() {13 List<String> mockedList = mock(List.class);14 when(mockedList.get(anyDouble())).thenReturn("Hello");15 System.out.println(mockedList.get(123));16 System.out.println(mockedList.get(999));17 System.out.println(mockedList.get(999));18 verify(mockedList).get(123);19 verify(mockedList).get(999);20 }21}22Mockito - anyInt() method23Mockito - anyList() method24Mockito - anySet() method25Mockito - anyMap() method26Mockito - anyCollection() method27Mockito - anyObject() method28Mockito - anyString() method

Full Screen

Full Screen

anyDouble

Using AI Code Generation

copy

Full Screen

1import org.mockito.ArgumentMatchers;2import java.util.List;3import static org.mockito.Mockito.mock;4import static org.mockito.Mockito.when;5public class MockitoAnyDoubleExample {6 public static void main(String[] args) {7 List mockedList = mock(List.class);8 when(mockedList.get(ArgumentMatchers.anyDouble())).thenReturn("Hello World");9 System.out.println(mockedList.get(1.0));10 System.out.println(mockedList.get(2.0));11 System.out.println(mockedList.get(3.0));12 }13}14Related Posts: Mockito anyInt() method example15Mockito anyLong() method example16Mockito anyString() method example17Mockito any() method example18Mockito anyBoolean() method example19Mockito anyByte() method example20Mockito anyChar() method example21Mockito anyFloat() method example22Mockito anyShort() method example23Mockito anyList() method example24Mockito anyCollection() method example25Mockito anySet() method example26Mockito anyMap() method example27Mockito anyIterable() met

Full Screen

Full Screen

anyDouble

Using AI Code Generation

copy

Full Screen

1import static org.mockito.ArgumentMatchers.anyDouble;2import static org.mockito.Mockito.mock;3import static org.mockito.Mockito.when;4public class MockitoAnyDoubleExample {5 public static void main(String[] args) {6 MathApplication mathApplication = mock(MathApplication.class);7 when(mathApplication.add(anyDouble(), anyDouble())).thenReturn(30.00);8 System.out.println(mathApplication.add(10.0, 20.0));9 System.out.println(mathApplication.add(10.0, 20.0));10 }11}12import static org.mockito.ArgumentMatchers.anyInt;13import static org.mockito.Mockito.mock;14import static org.mockito.Mockito.when;15public class MockitoAnyIntExample {16 public static void main(String[] args) {17 MathApplication mathApplication = mock(MathApplication.class);18 when(mathApplication.add(anyInt(), anyInt())).thenReturn(30);19 System.out.println(mathApplication.add(10, 20));20 System.out.println(mathApplication.add(10, 20));21 }22}23import static org.mockito.ArgumentMatchers.anyLong;24import static org.mockito.Mockito.mock;25import static org.mockito.Mockito.when;26public class MockitoAnyLongExample {27 public static void main(String[] args) {28 MathApplication mathApplication = mock(MathApplication.class);29 when(mathApplication.add(anyLong(), anyLong())).thenReturn(30L);30 System.out.println(mathApplication.add(10L, 20L));31 System.out.println(mathApplication.add(10L, 20L));32 }33}34import static org.mockito.ArgumentMatchers.anyObject;35import static org.mockito.Mockito.mock;36import static org.mockito.Mockito.when;37public class MockitoAnyObjectExample {38 public static void main(String[] args) {39 MathApplication mathApplication = mock(MathApplication

Full Screen

Full Screen

anyDouble

Using AI Code Generation

copy

Full Screen

1import static org.mockito.ArgumentMatchers.anyDouble;2import static org.mockito.Mockito.mock;3import static org.mockito.Mockito.when;4public class 1 {5 public static void main(String[] args) {6 MathApplication mathApplication = mock(MathApplication.class);7 when(mathApplication.add(anyDouble(), anyDouble())).thenReturn(10.0);8 System.out.println(mathApplication.add(10.0, 20.0));9 System.out.println(mathApplication.add(10.0, 20.0));10 }11}12import static org.mockito.ArgumentMatchers.anyInt;13import static org.mockito.Mockito.mock;14import static org.mockito.Mockito.when;15public class 2 {16 public static void main(String[] args) {17 MathApplication mathApplication = mock(MathApplication.class);18 when(mathApplication.add(anyInt(), anyInt())).thenReturn(30);19 System.out.println(mathApplication.add(10, 20));20 System.out.println(mathApplication.add(10, 20));21 }22}23import static org.mockito.ArgumentMatchers.any;24import static org.mockito.Mockito.mock;25import static org.mockito.Mockito.when;26public class 3 {27 public static void main(String[] args) {28 MathApplication mathApplication = mock(MathApplication.class);29 when(mathApplication.add(any(Integer.class), any(Integer.class))).thenReturn(30);30 System.out.println(mathApplication.add(10, 20));31 System.out.println(mathApplication.add(10, 20));32 }33}34import static org.mockito.ArgumentMatchers.any;35import static org.mockito.Mockito.mock;36import static org.mockito.Mockito.when;37public class 4 {38 public static void main(String[] args) {39 MathApplication mathApplication = mock(MathApplication.class);

Full Screen

Full Screen

anyDouble

Using AI Code Generation

copy

Full Screen

1import org.mockito.ArgumentMatchers;2public class 1 {3 public static void main(String[] args) {4 System.out.println(ArgumentMatchers.anyDouble());5 }6}7Recommended Posts: Mockito - anyInt() method8Mockito - anyBoolean() method9Mockito - anyByte() method10Mockito - anyChar() method11Mockito - anyShort() method12Mockito - anyLong() method13Mockito - anyFloat() method14Mockito - any() method15Mockito - anyString() method16Mockito - anyObject() method17Mockito - anyList() method18Mockito - anyCollection() method19Mockito - anySet() method20Mockito - anyMap() method21Mockito - anyIterable() method22Mockito - anyVararg() method23Mockito - anyClass() method

Full Screen

Full Screen

anyDouble

Using AI Code Generation

copy

Full Screen

1import org.mockito.ArgumentMatchers;2import static org.mockito.Mockito.*;3public class Test {4 public static void main(String[] args) {5 Calculator calculator = mock(Calculator.class);6 when(calculator.add(ArgumentMatchers.anyDouble(), ArgumentMatchers.anyDouble())).thenReturn(100.00);7 System.out.println(calculator.add(1, 2));8 System.out.println(calculator.add(3, 4));9 System.out.println(calculator.add(5, 6));10 }11}12Example 2: Using anyInt() method13import org.mockito.ArgumentMatchers;14import static org.mockito.Mockito.*;15public class Test {16 public static void main(String[] args) {17 Calculator calculator = mock(Calculator.class);18 when(calculator.add(ArgumentMatchers.anyInt(), ArgumentMatchers.anyInt())).thenReturn(100);19 System.out.println(calculator.add(1, 2));20 System.out.println(calculator.add(3, 4));21 System.out.println(calculator.add(5, 6));22 }23}24Example 3: Using anyString() method25import org.mockito.ArgumentMatchers;26import static org.mockito.Mockito.*;27public class Test {28 public static void main(String[] args) {29 Calculator calculator = mock(Calculator.class);30 when(calculator.add(ArgumentMatchers.anyString(), ArgumentMatchers.anyString())).thenReturn("100");31 System.out.println(calculator.add("1", "2"));32 System.out.println(calculator.add("3", "4"));33 System.out.println(calculator.add("5", "6"));34 }35}36Example 4: Using any() method37import org.mockito.ArgumentMatchers;38import static org.mockito.Mockito.*;39public class Test {40 public static void main(String[] args) {41 Calculator calculator = mock(Calculator.class);42 when(calculator.add(ArgumentMatchers.any(), ArgumentMatchers.any())).thenReturn(100);43 System.out.println(calculator.add("1", "2"));44 System.out.println(calculator.add(3, 4));

Full Screen

Full Screen

anyDouble

Using AI Code Generation

copy

Full Screen

1public class AnyDoubleExample {2 public static void main(String[] args) {3 List<String> list = mock(List.class);4 when(list.get(anyInt())).thenReturn("Hello World");5 System.out.println(list.get(1));6 System.out.println(list.get(2));7 System.out.println(list.get(3));8 System.out.println(list.get(4));9 }10}11Related Articles: Mockito Argument Matcher: anyInt() Method12Mockito Argument Matcher: anyBoolean() Method13Mockito Argument Matcher: anyString() Method14Mockito Argument Matcher: any() Method15Mockito Argument Matcher: anyList() Method16Mockito Argument Matcher: anyMap() Method17Mockito Argument Matcher: anySet() Method18Mockito Argument Matcher: anyCollection() Method19Mockito Argument Matcher: anyIterable() Method20Mockito Argument Matcher: anyVararg() Method

Full Screen

Full Screen

anyDouble

Using AI Code Generation

copy

Full Screen

1package com.automationrhapsody.mockito;2import org.junit.Test;3import org.junit.runner.RunWith;4import org.mockito.InjectMocks;5import org.mockito.Mock;6import org.mockito.junit.MockitoJUnitRunner;7import static org.mockito.Mockito.verify;8import static org.mockito.ArgumentMatchers.anyDouble;9import static org.mockito.Mockito.doNothing;10@RunWith(MockitoJUnitRunner.class)11public class MockitoArgumentMatchersAnyDoubleTest {12 private Calculator calculator;13 private CalculatorService calculatorService;14 public void testAdd() {15 doNothing().when(calculator).add(anyDouble(), anyDouble());16 calculatorService.add(1.0, 2.0);17 verify(calculator).add(anyDouble(), anyDouble());18 }19}20Mockito ArgumentMatchers anyFloat() Method21Mockito ArgumentMatchers anyInt() Method22Mockito ArgumentMatchers anyLong() Method23Mockito ArgumentMatchers anyShort() Method

Full Screen

Full Screen

anyDouble

Using AI Code Generation

copy

Full Screen

1import org.mockito.ArgumentMatchers;2public class anyDouble {3 public static void main(String[] args) {4 System.out.println(ArgumentMatchers.anyDouble());5 }6}7Recommended Posts: Difference between Mockito's anyInt() and any(Class) methods8Difference between Mockito's any() and any(Class) methods9Difference between Mockito's anyString() and any(Class) methods10Difference between Mockito's anyList() and any(Class) methods11Difference between Mockito's anyMap() and any(Class) methods12Difference between Mockito's anySet() and any(Class) methods13Difference between Mockito's anyCollection() and any(Class) methods14Difference between Mockito's anyLong() and any(Class) methods15Difference between Mockito's anyFloat() and any(Class) methods16Difference between Mockito's anyBoolean() and any(Class) methods17Difference between Mockito's anyByte() and any(Class) methods18Difference between Mockito's anyShort() and any(Class) methods19Difference between Mockito's anyChar() and any(Class) methods20Difference between Mockito's anyObject() and any(Class) methods21Difference between Mockito's any() and anyObject() methods

Full Screen

Full Screen

anyDouble

Using AI Code Generation

copy

Full Screen

1import org.mockito.ArgumentMatchers;2import org.mockito.Mockito;3import org.mockito.stubbing.Answer;4public class anyDouble {5 public static void main(String[] args) {6 MyClass mocker = Mockito.mock(MyClass.class);7 Mockito.when(mocker.myMethod(ArgumentMatchers.anyDouble())).thenAnswer((Answer<String>) invocation -> {8 Object[] args = invocation.getArguments();9 return "called with arguments: " + args[0];10 });11 System.out.println(mocker.myMethod(2.2));12 System.out.println(mocker.myMethod(2.2));13 System.out.println(mocker.myMethod(2.2));14 }15}16class MyClass {17 public String myMethod(double arg) {18 return "called with arguments: " + arg;19 }20}21import org.mockito.ArgumentMatchers;22import org.mockito.Mockito;23import org.mockito.stubbing.Answer;24public class anyFloat {25 public static void main(String[] args) {26 MyClass mocker = Mockito.mock(MyClass.class);27 Mockito.when(mocker.myMethod(ArgumentMatchers.anyFloat())).thenAnswer((Answer<String>) invocation -> {28 Object[] args = invocation.getArguments();29 return "called with arguments: " + args[0];30 });31 System.out.println(mocker.myMethod(2.2f));32 System.out.println(mocker.myMethod(2.2f));33 System.out.println(mocker.myMethod(2.2f));34 }35}36class MyClass {37 public String myMethod(float arg) {38 return "called with arguments: " + arg;39 }40}41import

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