Java Code Examples for org.mockito.internal.verification.VerificationModeFactory

The following examples show how to use org.mockito.internal.verification.VerificationModeFactory. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: gdx-fireapp   Source File: ScriptLoadedCallbackTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void onSuccess() {
    // Given
    PowerMockito.mockStatic(FirebaseJS.class);
    PowerMockito.mockStatic(FirebaseScriptInformant.class);
    Mockito.when(FirebaseScriptInformant.isFirebaseScriptLoaded()).thenReturn(false);
    FirebaseConfigParser parser = Mockito.mock(FirebaseConfigParser.class);
    Mockito.when(parser.getInitializationScript()).thenReturn("");
    ScriptLoadedCallback callback = new ScriptLoadedCallback(parser);

    // When
    callback.onSuccess(null);

    // Then
    PowerMockito.verifyStatic(FirebaseJS.class, VerificationModeFactory.times(1));
    FirebaseJS.initializeFirebase(Mockito.anyString());
    PowerMockito.verifyStatic(FirebaseScriptInformant.class, VerificationModeFactory.times(1));
    FirebaseScriptInformant.isFirebaseScriptLoaded();
}
 
Example 2
Source Project: gdx-fireapp   Source File: AuthTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void createUserWithEmailAndPassword_fail() {
    // Given
    Mockito.doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock invocation) {
            ((FIRAuth.Block_createUserWithEmailPasswordCompletion) invocation.getArgument(2)).call_createUserWithEmailPasswordCompletion(null, Mockito.mock(NSError.class));
            return null;
        }
    }).when(firAuth).createUserWithEmailPasswordCompletion(Mockito.anyString(), Mockito.any(), Mockito.any());
    Auth auth = new Auth();

    // When
    auth.createUserWithEmailAndPassword("email", "password".toCharArray()).fail(biConsumer).subscribe();

    // Then
    Mockito.verify(firAuth, VerificationModeFactory.times(1)).createUserWithEmailPasswordCompletion(Mockito.eq("email"), Mockito.eq("password"), Mockito.any());
    Mockito.verify(biConsumer, VerificationModeFactory.times(1)).accept(Mockito.nullable(String.class), Mockito.nullable(Exception.class));
}
 
Example 3
Source Project: gdx-fireapp   Source File: UserTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void sendEmailVerification() {
    // Given
    User user = new User();
    FirebaseUser firebaseUser = Mockito.mock(FirebaseUser.class);
    Consumer consumer = Mockito.mock(Consumer.class);
    Mockito.when(firebaseAuth.getCurrentUser()).thenReturn(firebaseUser);
    Mockito.when(task.isSuccessful()).thenReturn(true);
    Mockito.when(firebaseUser.sendEmailVerification()).thenReturn(task);

    // When
    user.sendEmailVerification().then(consumer);

    // Then
    Mockito.verify(firebaseUser, VerificationModeFactory.times(1)).sendEmailVerification();
    Mockito.verify(consumer, VerificationModeFactory.times(1)).accept(Mockito.any());
}
 
Example 4
Source Project: gdx-fireapp   Source File: AuthTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void signInWithEmailAndPassword() {
    // Given
    Mockito.doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock invocation) {
            ((FIRAuth.Block_signInWithEmailPasswordCompletion) invocation.getArgument(2)).call_signInWithEmailPasswordCompletion(null, null);
            return null;
        }
    }).when(firAuth).signInWithEmailPasswordCompletion(Mockito.anyString(), Mockito.any(), Mockito.any());
    Auth auth = new Auth();

    // When
    auth.signInWithEmailAndPassword("email", "password".toCharArray()).subscribe(consumer);

    // Then
    Mockito.verify(firAuth, VerificationModeFactory.times(1)).signInWithEmailPasswordCompletion(Mockito.eq("email"), Mockito.eq("password"), Mockito.any());
    Mockito.verify(consumer, VerificationModeFactory.times(1)).accept(Mockito.nullable(GdxFirebaseUser.class));
}
 
Example 5
Source Project: gdx-fireapp   Source File: StorageTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void download_file_failure() {
    // Given
    Storage storage = new Storage();
    FileHandle file = Mockito.mock(FileHandle.class);
    when(file.file()).thenReturn(Mockito.mock(File.class));
    final FileDownloadTask task = Mockito.mock(FileDownloadTask.class);
    when(storageReference.getFile(Mockito.any(File.class))).thenReturn(task);
    when(task.addOnFailureListener(Mockito.any(OnFailureListener.class))).then(new Answer<Object>() {
        @Override
        public Object answer(InvocationOnMock invocation) {
            ((OnFailureListener) invocation.getArgument(0)).onFailure(new Exception());
            return task;
        }
    });

    // When
    storage.download("test", file).silentFail().subscribe();

    // Then
    Mockito.verify(storageReference, VerificationModeFactory.times(1)).getFile(Mockito.any(File.class));
    Mockito.verify(task, VerificationModeFactory.times(1)).addOnFailureListener(Mockito.any(OnFailureListener.class));
    Mockito.verify(task, VerificationModeFactory.times(1)).addOnSuccessListener(Mockito.any(OnSuccessListener.class));
}
 
Example 6
Source Project: gdx-fireapp   Source File: AuthTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void signInAnonymously_fail() {
    // Given
    Mockito.doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock invocation) {
            ((FIRAuth.Block_signInAnonymouslyWithCompletion) invocation.getArgument(0)).call_signInAnonymouslyWithCompletion(null, Mockito.mock(NSError.class));
            return null;
        }
    }).when(firAuth).signInAnonymouslyWithCompletion(Mockito.any());
    Auth auth = new Auth();

    // When
    auth.signInAnonymously().fail(biConsumer).subscribe();

    // Then
    Mockito.verify(firAuth, VerificationModeFactory.times(1)).signInAnonymouslyWithCompletion(Mockito.any());
    Mockito.verify(biConsumer, VerificationModeFactory.times(1)).accept(Mockito.nullable(String.class), Mockito.any(Exception.class));
}
 
Example 7
Source Project: gdx-fireapp   Source File: AuthTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void signInAnonymously_fail() {
    // Given
    Auth auth = new Auth();
    BiConsumer biConsumer = Mockito.mock(BiConsumer.class);
    Mockito.when(task.isSuccessful()).thenReturn(false);
    Mockito.when(task.getException()).thenReturn(new Exception());
    Mockito.doReturn(task).when(firebaseAuth).signInAnonymously();

    // When
    auth.signInAnonymously()
            .fail(biConsumer);

    // Then
    PowerMockito.verifyStatic(FirebaseAuth.class, VerificationModeFactory.times(1));
    FirebaseAuth.getInstance();
    Mockito.verify(firebaseAuth, VerificationModeFactory.times(1)).signInAnonymously();
    Mockito.verify(task, VerificationModeFactory.times(1)).addOnCompleteListener(Mockito.any(OnCompleteListener.class));
    Mockito.verify(biConsumer, VerificationModeFactory.times(1)).accept(Mockito.nullable(String.class), Mockito.any(Exception.class));
}
 
Example 8
Source Project: gdx-fireapp   Source File: GwtDataListenersManagerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void callListener() {
    // Given
    DataListenersManager<FuturePromise> listenersManager = Mockito.mock(DataListenersManager.class);
    Array<FuturePromise> promises = new Array<>();
    FuturePromise promise = Mockito.mock(FuturePromise.class);
    promises.add(promise);
    Mockito.when(listenersManager.hasListeners(Mockito.anyString())).thenReturn(true);
    Mockito.when(listenersManager.getListeners(Mockito.anyString())).thenReturn(promises);
    Whitebox.setInternalState(GwtDataPromisesManager.class, "listenersManager", listenersManager);

    // When
    GwtDataPromisesManager.callPromise("/exists", "test");

    // Then
    Mockito.verify(promise, VerificationModeFactory.times(1)).doComplete(Mockito.anyString());
}
 
Example 9
Source Project: gdx-fireapp   Source File: DatabaseTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void transaction() throws Exception {
    // Given
    Database database = new Database();
    Function transactionFunction = mock(Function.class);
    mockStatic(QueryRunTransaction.class);
    QueryRunTransaction query = PowerMockito.spy(new QueryRunTransaction(database, "/test"));
    whenNew(QueryRunTransaction.class).withAnyArguments().thenReturn(query);
    Class dataType = String.class;

    // When
    database.inReference("/test").transaction(dataType, transactionFunction).subscribe();

    // Then
    Mockito.verify(firDatabaseReference, VerificationModeFactory.times(1)).runTransactionBlockAndCompletionBlock(
            Mockito.any(FIRDatabaseReference.Block_runTransactionBlockAndCompletionBlock_0.class),
            Mockito.any(FIRDatabaseReference.Block_runTransactionBlockAndCompletionBlock_1.class)
    );
}
 
Example 10
Source Project: gdx-fireapp   Source File: AuthTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void signInWithToken() {
    // Given
    Auth auth = new Auth();
    Consumer consumer = Mockito.mock(Consumer.class);
    Mockito.when(task.isSuccessful()).thenReturn(true);
    Mockito.doReturn(task).when(firebaseAuth).signInWithCustomToken(Mockito.anyString());

    // When
    auth.signInWithToken("token")
            .then(consumer);

    // Then
    PowerMockito.verifyStatic(FirebaseAuth.class, VerificationModeFactory.times(2));
    FirebaseAuth.getInstance();
    Mockito.verify(firebaseAuth, VerificationModeFactory.times(1)).signInWithCustomToken(Mockito.eq("token"));
    Mockito.verify(firebaseAuth, VerificationModeFactory.times(1)).getCurrentUser();
    Mockito.verify(task, VerificationModeFactory.times(1)).addOnCompleteListener(Mockito.any(OnCompleteListener.class));
    Mockito.verify(consumer, VerificationModeFactory.times(1)).accept(Mockito.any(GdxFirebaseUser.class));
}
 
Example 11
Source Project: gdx-fireapp   Source File: QuerySetValueTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void run() throws Exception {
    // Given
    PowerMockito.mockStatic(Database.class);
    Database database = PowerMockito.mock(Database.class);
    PowerMockito.when(database, "dbReference").thenReturn(firDatabaseReference);
    Whitebox.setInternalState(database, "databasePath", "/test");
    QuerySetValue query = new QuerySetValue(database, "/test");
    String value = "test";

    // When
    query.withArgs(value).execute();

    // Then
    Mockito.verify(firDatabaseReference, VerificationModeFactory.times(1)).setValueWithCompletionBlock(Mockito.any(NSString.class), Mockito.any(FIRDatabaseReference.Block_setValueWithCompletionBlock.class));
}
 
Example 12
Source Project: gdx-fireapp   Source File: UrlDownloaderTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void onSuccess_fail() {
    // Given
    String downloadUrl = "http://url.with.token.com?token=abc";
    FuturePromise futurePromise = Mockito.spy(FuturePromise.class);
    futurePromise.silentFail();
    UrlDownloader urlDownloader = new UrlDownloader(futurePromise);
    Mockito.when(xmlHttpRequest.getReadyState()).thenReturn(XMLHttpRequest.DONE);
    Mockito.when(xmlHttpRequest.getStatus()).thenReturn(501);

    // When
    urlDownloader.onSuccess(downloadUrl);

    // Then
    Mockito.verify(futurePromise, VerificationModeFactory.times(1)).doFail(Mockito.any(Exception.class));
}
 
Example 13
Source Project: gdx-fireapp   Source File: GoogleAuthTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
    public void revokeAccess_ok() {
        // Given
        GoogleAuth googleAuth = new GoogleAuth();
        Task task = Mockito.mock(Task.class);
        final Task task2 = Mockito.mock(Task.class);
        Mockito.when(task2.isSuccessful()).thenReturn(true);
        Mockito.when(googleSignInClient.revokeAccess()).thenReturn(task);
        Mockito.when(task.addOnCompleteListener(Mockito.any(OnCompleteListener.class))).thenAnswer(new Answer<Object>() {
            @Override
            public Object answer(InvocationOnMock invocation) {
                ((OnCompleteListener) invocation.getArgument(0)).onComplete(task2);
                return null;
            }
        });

        // When
        FuturePromise promise = (FuturePromise) spy(googleAuth.revokeAccess().subscribe());

        // Then
        PowerMockito.verifyStatic(GoogleSignIn.class, VerificationModeFactory.times(1));
        GoogleSignIn.getClient((Activity) Mockito.refEq(Gdx.app), Mockito.any(GoogleSignInOptions.class));
        Mockito.verify(googleSignInClient, VerificationModeFactory.times(1)).revokeAccess();
//        Mockito.verify(promise, VerificationModeFactory.times(1)).doComplete(Mockito.isNull());
    }
 
Example 14
Source Project: gdx-fireapp   Source File: UserTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void delete() {
    // Given
    User user = new User();
    FirebaseUser firebaseUser = Mockito.mock(FirebaseUser.class);
    Consumer consumer = Mockito.mock(Consumer.class);
    Mockito.when(firebaseAuth.getCurrentUser()).thenReturn(firebaseUser);
    Mockito.when(task.isSuccessful()).thenReturn(true);
    Mockito.when(firebaseUser.delete()).thenReturn(task);

    // When
    user.delete().then(consumer);

    // Then
    Mockito.verify(firebaseUser, VerificationModeFactory.times(1)).delete();
    Mockito.verify(consumer, VerificationModeFactory.times(1)).accept(Mockito.any());
}
 
Example 15
Source Project: gdx-fireapp   Source File: AuthTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void sendPasswordResetEmail_fail() {
    // Given
    Auth auth = new Auth();
    BiConsumer biConsumer = Mockito.mock(BiConsumer.class);
    Mockito.when(task.isSuccessful()).thenReturn(false);
    Mockito.when(task.getException()).thenReturn(new Exception());
    Mockito.doReturn(task).when(firebaseAuth).sendPasswordResetEmail(Mockito.anyString());
    String arg1 = "email";

    // When
    auth.sendPasswordResetEmail(arg1).fail(biConsumer);

    // Then
    PowerMockito.verifyStatic(FirebaseAuth.class, VerificationModeFactory.times(1));
    FirebaseAuth.getInstance();
    Mockito.verify(firebaseAuth, VerificationModeFactory.times(1)).sendPasswordResetEmail(Mockito.eq(arg1));
    Mockito.verify(biConsumer, VerificationModeFactory.times(1)).accept(Mockito.nullable(String.class), Mockito.any(Exception.class));
}
 
Example 16
Source Project: jcredstash   Source File: JCredStashTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGetSecretWithVersion() {
    final GetItemRequest[] getItemRequest = new GetItemRequest[1];
    Mockito.when(dynamoDBClient.getItem(Mockito.any(GetItemRequest.class))).thenAnswer(invocationOnMock -> {
        Object[] args = invocationOnMock.getArguments();
        getItemRequest[0] = (GetItemRequest) args[0];
        return new GetItemResult();
    });

    JCredStash credStash = Mockito.spy(new JCredStash(dynamoDBClient, awskmsClient));
    Mockito.doReturn("foo").when(credStash).getSecret(Mockito.any(JCredStash.StoredSecret.class), Mockito.any(Map.class));

    credStash.getSecret("table", "mysecret", new HashMap<>(), padVersion(1));

    Mockito.verify(dynamoDBClient, VerificationModeFactory.times(1)).getItem(Mockito.any(GetItemRequest.class));
    Assert.assertEquals(getItemRequest[0].getKey().get("version").getS(), padVersion(1));
}
 
Example 17
Source Project: gdx-fireapp   Source File: DatabaseTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
    public void onConnect() throws Exception {
        // Given
        Database database = new Database();
        mockStatic(QueryConnectionStatus.class);
//        ConnectionStatusQuery query = PowerMockito.spy(new ConnectionStatusQuery(database));
        QueryConnectionStatus query = PowerMockito.mock(QueryConnectionStatus.class);
        when(query.with(Mockito.any(Array.class))).thenReturn(query);
        when(query.with(Mockito.any(OrderByClause.class))).thenReturn(query);
        when(query.withArgs()).thenReturn(query);
        whenNew(QueryConnectionStatus.class).withAnyArguments().thenReturn(query);

        // When
        database.onConnect().subscribe();

        // Then
        // Can't verify new because of PowerMockitoRunner and JaCoCo coverage. Rule does not work here because of MOE
//        PowerMockito.verifyNew(ConnectionStatusQuery.class).withArguments(Mockito.any());
//        Mockito.verify(connectionStatusQuery, VerificationModeFactory.times(1)).execute();
        Mockito.verify(firDatabaseReference, VerificationModeFactory.times(1)).observeEventTypeWithBlock(Mockito.anyLong(), (FIRDatabaseQuery.Block_observeEventTypeWithBlock) Mockito.any());
    }
 
Example 18
Source Project: gdx-fireapp   Source File: MapMitmConverterTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void doMitmConversion_map() {
    // Given
    FirebaseMapConverter mapConverter = Mockito.mock(FirebaseMapConverter.class);
    MapMitmConverter mapMitmConverter = new MapMitmConverter(mapConverter) {
    };
    Map map = Collections.singletonMap("field", "test");
    Class wantedType = MyClass.class;

    // When
    Object object1 = mapMitmConverter.doMitmConversion(wantedType, map);

    // Then
    Assert.assertNotNull(mapConverter);
    Mockito.verify(mapConverter, VerificationModeFactory.times(1)).convert(Mockito.refEq(map), Mockito.eq(wantedType));
}
 
Example 19
Source Project: gdx-fireapp   Source File: QueryOnDataChangeTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void run() {
    // Given
    final Database databaseDistribution = Mockito.spy(Database.class);
    final DatabaseReference databaseReference = Mockito.mock(DatabaseReference.class);
    Mockito.when(firebaseDatabase.getReference(Mockito.anyString())).thenReturn(databaseReference);
    Mockito.when(databaseDistribution.inReference(Mockito.anyString())).thenCallRealMethod();
    final QueryOnDataChange queryOnDataChange = new QueryOnDataChange(databaseDistribution, "/test");
    final ConverterPromise promise = Mockito.spy(ConverterPromise.class);

    // When
    databaseDistribution.inReference("/test");
    queryOnDataChange.with(promise).withArgs(Map.class).execute();

    // Then
    Mockito.verify(databaseReference, VerificationModeFactory.times(1)).addValueEventListener(Mockito.any(ValueEventListener.class));
}
 
Example 20
Source Project: gdx-fireapp   Source File: UserTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void updateEmail() {
    // Given
    User user = new User();
    Consumer consumer = Mockito.mock(Consumer.class);
    Mockito.when(firAuth.currentUser()).thenReturn(firUser);
    Mockito.doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock invocation) {
            ((FIRUser.Block_updateEmailCompletion) invocation.getArgument(1)).call_updateEmailCompletion(null);
            return null;
        }
    }).when(firUser).updateEmailCompletion(Mockito.anyString(), Mockito.any(FIRUser.Block_updateEmailCompletion.class));
    String arg1 = "email";

    // When
    user.updateEmail(arg1).subscribe(consumer);

    // Then
    Mockito.verify(firUser, VerificationModeFactory.times(1)).updateEmailCompletion(Mockito.eq(arg1), Mockito.any(FIRUser.Block_updateEmailCompletion.class));
    Mockito.verify(consumer, VerificationModeFactory.times(1)).accept(Mockito.nullable(GdxFirebaseUser.class));
}
 
Example 21
Source Project: gdx-fireapp   Source File: StorageTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void download_withNullTargetFile() {
    // Given
    NSURL nsData = Mockito.mock(NSURL.class);
    when(NSURL.fileURLWithPathIsDirectory(Mockito.nullable(String.class), Mockito.anyBoolean())).thenReturn(nsData);
    FileHandle file = null;
    Storage storage = new Storage();

    // When
    storage.download("/test", file).subscribe();

    // Then
    Mockito.verify(firStorageReference, VerificationModeFactory.times(1)).writeToFileCompletion(Mockito.nullable(NSURL.class), Mockito.any(FIRStorageReference.Block_writeToFileCompletion.class));
    PowerMockito.verifyStatic(Foundation.class, VerificationModeFactory.times(1));
    Foundation.NSTemporaryDirectory();
}
 
Example 22
Source Project: gdx-fireapp   Source File: AuthTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void signInAnonymously() {
    // Given
    Auth auth = new Auth();
    Consumer consumer = Mockito.mock(Consumer.class);
    Mockito.when(task.isSuccessful()).thenReturn(true);
    Mockito.doReturn(task).when(firebaseAuth).signInAnonymously();

    // When
    auth.signInAnonymously()
            .then(consumer);

    // Then
    PowerMockito.verifyStatic(FirebaseAuth.class, VerificationModeFactory.times(2));
    FirebaseAuth.getInstance();
    Mockito.verify(firebaseAuth, VerificationModeFactory.times(1)).signInAnonymously();
    Mockito.verify(task, VerificationModeFactory.times(1)).addOnCompleteListener(Mockito.any(OnCompleteListener.class));
    Mockito.verify(consumer, VerificationModeFactory.times(1)).accept(Mockito.any(GdxFirebaseUser.class));
    Mockito.verify(firebaseAuth, VerificationModeFactory.times(1)).getCurrentUser();
}
 
Example 23
Source Project: gdx-fireapp   Source File: UserTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void updatePassword_fail() {
    // Given
    User user = new User();
    BiConsumer consumer = Mockito.mock(BiConsumer.class);
    Mockito.when(firAuth.currentUser()).thenReturn(firUser);
    Mockito.doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock invocation) {
            ((FIRUser.Block_updatePasswordCompletion) invocation.getArgument(1))
                    .call_updatePasswordCompletion(Mockito.mock(NSError.class));
            return null;
        }
    }).when(firUser).updatePasswordCompletion(Mockito.anyString(), Mockito.any(FIRUser.Block_updatePasswordCompletion.class));
    char[] arg1 = {'p', 'a', 's', 's'};

    // When
    user.updatePassword(arg1).fail(consumer).subscribe();

    // Then
    Mockito.verify(firUser, VerificationModeFactory.times(1)).updatePasswordCompletion(Mockito.eq(new String(arg1)), Mockito.any(FIRUser.Block_updatePasswordCompletion.class));
    Mockito.verify(consumer, VerificationModeFactory.times(1)).accept(Mockito.nullable(String.class), Mockito.any(Exception.class));
}
 
Example 24
Source Project: gdx-fireapp   Source File: AuthTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void signOut() {
    // Given
    PowerMockito.mockStatic(PtrFactory.class);
    Mockito.when(PtrFactory.newObjectReference(NSError.class)).thenReturn(Mockito.mock(Ptr.class));
    Auth auth = new Auth();

    // When
    auth.signOut().subscribe(consumer);

    // Then
    Mockito.verify(firAuth, VerificationModeFactory.times(1)).signOut(Mockito.any());
    Mockito.verify(consumer, VerificationModeFactory.times(1)).accept(Mockito.any());
}
 
Example 25
Source Project: gdx-fireapp   Source File: FirebaseConfigParserTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void getFirebaseScriptSrc_notValid() {
    // Given
    FirebaseConfigParser configParser = new FirebaseConfigParser(FIREBASE_HTML_WITHOUT_SCRIPT);

    // When
    String firebaseSrcScript = configParser.getFirebaseScriptSrc();

    // Then
    Assert.assertNull(firebaseSrcScript);
    Mockito.verify(Gdx.app, VerificationModeFactory.times(1)).error(Mockito.anyString(), Mockito.anyString());
}
 
Example 26
Source Project: gdx-fireapp   Source File: SortingFilteringProviderTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void applyFiltering() {
    // Given
    SortingFilteringProvider provider = new SortingFilteringProvider() {

        @Override
        public FilterResolver createFilterResolver() {
            return Mockito.mock(FilterResolver.class);
        }

        @Override
        public OrderByResolver createOrderByResolver() {
            return Mockito.mock(OrderByResolver.class);
        }
    };
    Array array = new Array();
    array.add(new Filter());
    provider.setOrderByClause(Mockito.mock(OrderByClause.class));
    provider.setFilters(array);
    provider.setQuery(Mockito.mock(GdxFireappQuery.class));

    // When
    provider.applyFiltering();

    // Then
    Mockito.verify(provider.filterResolver, VerificationModeFactory.times(1)).resolve(Mockito.nullable(FilterType.class), Mockito.nullable(Object.class), Mockito.nullable(Object[].class));
    Mockito.verify(provider.orderByResolver, VerificationModeFactory.times(1)).resolve(Mockito.nullable(OrderByClause.class), Mockito.any());
}
 
Example 27
Source Project: gdx-fireapp   Source File: FirebaseConfigurationTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void init_fail() {
    // Given
    FirebaseConfiguration firebaseConfiguration = Mockito.spy(new FirebaseConfiguration());

    // When
    firebaseConfiguration.init();

    // Then
    Assert.assertNull(Whitebox.getInternalState(firebaseConfiguration, "rawHtml"));
    Mockito.verify(Gdx.app, VerificationModeFactory.times(1)).error(Mockito.anyString(), Mockito.anyString());
}
 
Example 28
@Test
public void givenArg$removeUserAttribute_whenQuery_thenShouldCallNativeApi() {
    // given
    PowerMockito.mockStatic(Instabug.class);
    String key = "company";
    // when
    rnModule.removeUserAttribute(key);
    // then
    PowerMockito.verifyStatic(VerificationModeFactory.times(1));
    Instabug.removeUserAttribute(key);
}
 
Example 29
Source Project: gdx-fireapp   Source File: DatabaseTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void setPersistenceEnabled() {
    // Given
    Database database = new Database();

    // When
    database.setPersistenceEnabled(true);

    // Then
    Mockito.verify(firDatabase, VerificationModeFactory.times(1)).setPersistenceEnabled(Mockito.eq(true));
}
 
Example 30
Source Project: gdx-fireapp   Source File: GwtDataListenersManagerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void addDataListener_detach() {
    // Given
    DataListenersManager<Promise> listenersManager = Mockito.mock(DataListenersManager.class);
    Mockito.when(listenersManager.hasListeners(Mockito.anyString())).thenReturn(true);
    Whitebox.setInternalState(GwtDataPromisesManager.class, "listenersManager", listenersManager);
    String arg = "/test";

    // When
    GwtDataPromisesManager.removeDataPromise(arg);

    // Then
    Mockito.verify(listenersManager, VerificationModeFactory.times(1)).removeListenersForPath(Mockito.eq(arg));
}