org.mockito.internal.verification.VerificationModeFactory Java Examples

The following examples show how to use org.mockito.internal.verification.VerificationModeFactory. 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 File: AuthTest.java    From gdx-fireapp with 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 #2
Source File: AuthTest.java    From gdx-fireapp with 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 #3
Source File: AuthTest.java    From gdx-fireapp with 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 #4
Source File: UserTest.java    From gdx-fireapp with 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 #5
Source File: UserTest.java    From gdx-fireapp with 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 #6
Source File: StorageTest.java    From gdx-fireapp with 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 #7
Source File: ScriptLoadedCallbackTest.java    From gdx-fireapp with 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 #8
Source File: AuthTest.java    From gdx-fireapp with 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 #9
Source File: StorageTest.java    From gdx-fireapp with 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 #10
Source File: UserTest.java    From gdx-fireapp with 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 #11
Source File: GoogleAuthTest.java    From gdx-fireapp with 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 #12
Source File: AuthTest.java    From gdx-fireapp with 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 #13
Source File: UserTest.java    From gdx-fireapp with 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 #14
Source File: AuthTest.java    From gdx-fireapp with 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 #15
Source File: AuthTest.java    From gdx-fireapp with 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 File: QueryOnDataChangeTest.java    From gdx-fireapp with 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 #17
Source File: QuerySetValueTest.java    From gdx-fireapp with 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 #18
Source File: GwtDataListenersManagerTest.java    From gdx-fireapp with 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 #19
Source File: DatabaseTest.java    From gdx-fireapp with 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 #20
Source File: MapMitmConverterTest.java    From gdx-fireapp with 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 #21
Source File: DatabaseTest.java    From gdx-fireapp with 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 #22
Source File: JCredStashTest.java    From jcredstash with 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 #23
Source File: UrlDownloaderTest.java    From gdx-fireapp with 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 #24
Source File: DatabaseTest.java    From gdx-fireapp with 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(firebaseDatabase, VerificationModeFactory.times(1)).setPersistenceEnabled(Mockito.eq(true));
}
 
Example #25
Source File: DatabaseTest.java    From gdx-fireapp with Apache License 2.0 5 votes vote down vote up
@Test
public void keepSynced() {
    // Given
    Database database = new Database();

    // When
    database.inReference("/test").keepSynced(true);

    // Then
    Mockito.verify(databaseReference, VerificationModeFactory.times(1)).keepSynced(Mockito.eq(true));
}
 
Example #26
Source File: PipelineNodeImplTest.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Test
public void getRun_FirstFound() throws Exception {
    PowerMockito.mockStatic(QueueUtil.class);
    PowerMockito.when(QueueUtil.getRun(job, 1)).thenReturn(run);

    WorkflowRun workflowRun = PipelineNodeImpl.getRun(job, 1);
    assertEquals(workflowRun, run);

    PowerMockito.verifyStatic(QueueUtil.class, VerificationModeFactory.times(1));
    QueueUtil.getRun(job, 1); // need to call again to handle verify
}
 
Example #27
Source File: RNInstabugReactnativeModuleTest.java    From Instabug-React-Native with MIT License 5 votes vote down vote up
@Test
public void givenArgs$identifyUserWithEmail_whenQuery_thenShouldCallNativeApiWithArgs() {
    // given
    PowerMockito.mockStatic(Instabug.class);
    String email = "[email protected]";
    String userName = "salmaali";
    // when
    rnModule.identifyUserWithEmail(email, userName);
    // then
    PowerMockito.verifyStatic(VerificationModeFactory.times(1));
    Instabug.identifyUser(userName, email);
}
 
Example #28
Source File: DatabaseTest.java    From gdx-fireapp with Apache License 2.0 5 votes vote down vote up
@Test
public void push() {
    // Given
    Database database = new Database();
    when(databaseReference.push()).thenReturn(databaseReference);

    // When
    database.inReference("/test").push();

    // Then
    Mockito.verify(databaseReference, VerificationModeFactory.times(1)).push();
}
 
Example #29
Source File: ResolverQueryFilterTest.java    From gdx-fireapp with Apache License 2.0 5 votes vote down vote up
@Test
public void resolve_limitFirst() {
    // Given
    ResolverQueryFilter resolver = new ResolverQueryFilter();

    // When
    resolver.resolve(FilterType.LIMIT_FIRST, query, 2);

    // Then
    Mockito.verify(query, VerificationModeFactory.times(1)).limitToFirst(Mockito.anyInt());
}
 
Example #30
Source File: StorageTest.java    From gdx-fireapp with Apache License 2.0 5 votes vote down vote up
@Test
public void upload() {
    // Given
    NSData nsData = PowerMockito.mock(NSData.class);
    when(NSData.dataWithContentsOfFile(Mockito.anyString())).thenReturn(nsData);
    FileHandle fileHandle = Mockito.mock(FileHandle.class);
    when(fileHandle.file()).thenReturn(Mockito.mock(File.class));
    Storage storage = new Storage();
    final FIRStorageMetadata firStorageMetadata = Mockito.mock(FIRStorageMetadata.class);
    Mockito.doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock invocation) {
            ((FIRStorageReference.Block_putDataMetadataCompletion) invocation.getArgument(2)).call_putDataMetadataCompletion(firStorageMetadata, null);
            return null;
        }
    }).when(firStorageReference).putDataMetadataCompletion(Mockito.any(NSData.class), Mockito.any(FIRStorageMetadata.class), Mockito.any(FIRStorageReference.Block_putDataMetadataCompletion.class));
    when(FIRStorageMetadata.alloc()).thenReturn(firStorageMetadata);
    when(firStorageMetadata.init()).thenReturn(firStorageMetadata);
    when(firStorageMetadata.updated()).thenReturn(Mockito.mock(NSDate.class));
    when(firStorageMetadata.timeCreated()).thenReturn(Mockito.mock(NSDate.class));


    // When
    storage.upload("test", fileHandle).subscribe();

    // Then
    Mockito.verify(firStorageReference, VerificationModeFactory.times(1)).putDataMetadataCompletion(Mockito.nullable(NSData.class), Mockito.nullable(FIRStorageMetadata.class), Mockito.any(FIRStorageReference.Block_putDataMetadataCompletion.class));
}