Example usage for junit.framework Assert assertFalse

List of usage examples for junit.framework Assert assertFalse

Introduction

In this page you can find the example usage for junit.framework Assert assertFalse.

Prototype

static public void assertFalse(boolean condition) 

Source Link

Document

Asserts that a condition is false.

Usage

From source file:com.test.onesignal.MainOneSignalClassRunner.java

@Test
@Config(shadows = { ShadowOneSignal.class })
public void testLocationTimeout() throws Exception {
    //ShadowApplication.getInstance().grantPermissions(new String[]{"android.permission.YOUR_PERMISSION"});

    OneSignalInit();/*from w ww  .j  a  v  a2 s.c o  m*/
    threadAndTaskWait();

    Class klass = Class.forName("com.onesignal.LocationGMS");
    klass.getDeclaredMethod("startFallBackThread").invoke(null);
    klass.getDeclaredMethod("fireFailedComplete").invoke(null);
    threadAndTaskWait();

    Assert.assertFalse(ShadowOneSignal.messages.contains("GoogleApiClient timedout"));
}

From source file:com.espertech.esper.support.util.ArrayAssertionUtil.java

public static void assertNotContains(String[] strings, String... values) {
    Set<String> set = new HashSet<String>(Arrays.asList(strings));
    for (String value : values) {
        Assert.assertFalse(set.contains(value));
    }//from   w  ww .j a v  a 2  s.  c o m
}

From source file:com.vmware.identity.idm.client.TenantManagementTest.java

@TestOrderAnnotation(order = 8)
@Test/*from  w  w w. ja va  2s.c om*/
public void testAuthenticatedUserAccountLockedExceptionVmdirProvider() throws Exception {
    Properties props = getTestProperties();

    String tenantName = props.getProperty(CFG_KEY_IDM_SYSTEM_TENANT_NAME);
    String domainName = props.getProperty(CFG_KEY_IDM_ACCTFLAGS_DOMAINNAME);
    String userName = props.getProperty(CFG_KEY_IDM_ACCTFLAGS_USERNAME);
    String firstName = props.getProperty(CFG_KEY_IDM_ACCTFLAGS_DETAILS_FIRSTNAME);
    String lastName = props.getProperty(CFG_KEY_IDM_ACCTFLAGS_DETAILS_LASTNAME);
    String emailAddr = props.getProperty(CFG_KEY_IDM_ACCTFLAGS_DETAILS_EMAILADDR);
    String description = props.getProperty(CFG_KEY_IDM_ACCTFLAGS_DETAILS_DESCRIPTION);
    String passWord = props.getProperty(CFG_KEY_IDM_ACCTFLAGS_PASSWORD);
    char[] pass = passWord.toCharArray();

    PersonDetail detail = new PersonDetail.Builder().firstName(firstName).lastName(lastName)
            .emailAddress(emailAddr).description(description).build();

    CasIdmClient client = getIdmClient();
    Assert.assertNotNull(IdmClientTestUtil.ensureTenantExists(client, tenantName));

    if (null != client.findPersonUser(tenantName, new PrincipalId(userName, domainName))) {
        client.deletePrincipal(tenantName, userName);
    }
    client.addPersonUser(tenantName, userName, detail, pass);

    boolean isInitDone = false;
    PrincipalId principalId = null;
    String principal = userName + "@" + domainName;
    while (!isInitDone) {
        try {
            principalId = client.authenticate(tenantName, principal, passWord);
            isInitDone = (null != principalId);
        } catch (UserAccountLockedException e) {// unlock if needed
            client.unlockUserAccount(tenantName, new PrincipalId(userName, domainName));
        } catch (Exception e) {
            Assert.fail("Unexpected exception: " + e.getMessage());
        }
    }

    Assert.assertNotNull(principalId);

    String wrongPass = "wrongPass" + pass.toString();

    int maxAttempts = client.getLockoutPolicy(tenantName).getMaxFailedAttempts();

    try {
        for (int i = 0; i < maxAttempts - 1; i++) {
            try {
                client.authenticate(tenantName, principal, wrongPass);
            } catch (UserAccountLockedException e) {
                Assert.fail(String.format("Unexpected exception before max attempts [%d] is reached: [%d] ",
                        maxAttempts, i, e.getMessage()));
            } catch (IDMLoginException e) { // bad password
                Assert.assertFalse(e.getMessage().contains("UserAccountLockedException: User account locked"));
                Assert.assertTrue(e.getMessage().contains("Login failed"));
                continue;
            }
        }
    } catch (Exception e) {
        Assert.fail(String.format("should not encounter exception within %d attempt", maxAttempts));
    }

    try {
        client.authenticate(tenantName, principal, wrongPass);
    } catch (UserAccountLockedException e) {// expected exception
        Assert.assertTrue(e.getMessage().contains("User account locked"));
        Assert.assertFalse(e.getMessage().contains("Login failed"));

        client.unlockUserAccount(tenantName, new PrincipalId(userName, domainName));
        client.deletePrincipal(tenantName, userName);
        return;
    } catch (Exception e) {
        Assert.fail(String.format("should have gotten an UserAccountLockedException after max attempts = %d",
                maxAttempts));
    }
    Assert.fail(String.format("should have gotten an UserAccountLockedException after max attempts = %d",
            maxAttempts));
}

From source file:com.linkedin.pinot.core.data.manager.realtime.LLRealtimeSegmentDataManagerTest.java

@Test
public void testFileRemovedDuringOnlineTransition() throws Exception {
    FakeLLRealtimeSegmentDataManager segmentDataManager = createFakeSegmentManager();

    SegmentCompletionProtocol.Response.Params params = new SegmentCompletionProtocol.Response.Params();
    params.withStatus(SegmentCompletionProtocol.ControllerResponseStatus.FAILED);
    SegmentCompletionProtocol.Response commitFailed = new SegmentCompletionProtocol.Response(params);

    // Set up the responses so that we get a failed respnse first and then a success response.
    segmentDataManager._responses.add(commitFailed);
    final long leaseTime = 50000L;
    final long finalOffset = _startOffset + 600;
    segmentDataManager.setCurrentOffset(finalOffset);

    // We have set up commit to fail, so we should carry over the segment file.
    String segTarFileName = segmentDataManager.invokeBuildForCommit(leaseTime);
    Assert.assertTrue(segmentDataManager._buildSegmentCalled);
    Assert.assertFalse(segmentDataManager.invokeCommit(segTarFileName));
    Assert.assertTrue(new File(segTarFileName).exists());

    // Now let the segment go ONLINE from CONSUMING, and ensure that the file is removed.
    LLCRealtimeSegmentZKMetadata metadata = new LLCRealtimeSegmentZKMetadata();
    metadata.setEndOffset(finalOffset);/*w w w  . j a va2  s. c o m*/
    segmentDataManager._stopWaitTimeMs = 0;
    segmentDataManager._state.set(segmentDataManager, LLRealtimeSegmentDataManager.State.HOLDING);
    segmentDataManager.goOnlineFromConsuming(metadata);
    Assert.assertFalse(new File(segTarFileName).exists());
}

From source file:com.ebay.cloud.cms.query.service.QueryPaginationByIdTest.java

@Test
public void testQueryIter00() {
    raptorContext.removeSortOn();//ww  w .  j a  v a  2s .c o  m
    String room = "Room";
    MetaClass metaClass = raptorMetaService.getMetaClass(room);
    PersistenceContext persistenceContext = createRaptorPersistentContext();
    BsonEntity entity = new BsonEntity(metaClass);
    final int CREATE_COUNT = 101;
    for (int i = 0; i < CREATE_COUNT; i++) {
        entity.removeField(InternalFieldEnum.ID.getName());
        entity.getNode().remove("_id");
        persistenceService.create(entity, persistenceContext);
    }
    long TOTAL_COUNT = 0;
    {
        QueryContext context = newQueryContext(RAPTOR_REPO, RAPTOR_MAIN_BRANCH_ID);
        context.setPaginationMode(PaginationMode.ID_BASED);
        context.setCountOnly(true);
        IQueryResult result = queryService.query(room, context);
        TOTAL_COUNT = result.getCount();
    }

    String queryStr = "Room";
    // clear skip/limit
    raptorContext.getCursor().setHint(-1);
    raptorContext.getCursor().setSkips(null);
    raptorContext.getCursor().setJoinCursorValues(null);
    raptorContext.getCursor().setSingleCursorValue(null);
    raptorContext.getCursor().setLimits(new int[] { CREATE_COUNT / 2 });
    raptorContext.setPaginationMode(PaginationMode.ID_BASED);
    IQueryResult result = queryService.query(queryStr, raptorContext);
    Assert.assertNull(result.getNextCursor().getJoinCursorValues());
    IEntity cursorValue = result.getNextCursor().getSingleCursorValue();
    int[] nextLimits = result.getNextCursor().getLimits();
    Assert.assertEquals(CREATE_COUNT / 2, nextLimits[0]);
    int fetchCount = 0;
    int count = 1;
    fetchCount = fetchCount + result.getEntities().size();
    while (result.hasMoreResults()) {
        Assert.assertFalse(result.getNextCursor().isJoinCursor());
        cursorValue = result.getNextCursor().getSingleCursorValue();
        Assert.assertNotNull(cursorValue);
        nextLimits = result.getNextCursor().getLimits();
        Assert.assertEquals(CREATE_COUNT / 2, nextLimits[0]);
        raptorContext.setCursor(result.getNextCursor());
        result = queryService.query(queryStr, raptorContext);
        fetchCount = fetchCount + result.getEntities().size();
        count++;
    }
    Assert.assertEquals(3, count);
    Assert.assertEquals(TOTAL_COUNT, fetchCount);
}

From source file:com.connectsdk.service.FireTVServiceTest.java

@Test
public void testConnectWithNullRemoteMediaPlayer() {
    ServiceDescription serviceDescription = Mockito.mock(ServiceDescription.class);
    ServiceConfig serviceConfig = Mockito.mock(ServiceConfig.class);
    FireTVService service = new FireTVService(serviceDescription, serviceConfig);

    ConnectableDevice listener = Mockito.mock(ConnectableDevice.class);
    service.setListener(listener);/*w w  w  .j  ava 2 s.c om*/

    service.connect();

    Mockito.verify(listener, Mockito.times(0)).onConnectionSuccess(service);
    Assert.assertFalse(service.isConnected());
}

From source file:de.clusteval.data.dataset.TestDataSet.java

/**
 * Test method for {@link data.dataset.DataSet#loadIntoMemory()}.
 * //from w w w .ja  v  a 2s  .  c o  m
 * @throws UnknownDataSetFormatException
 * @throws NoRepositoryFoundException
 * @throws IOException
 * @throws FormatConversionException
 * @throws DataSetNotFoundException
 * @throws InvalidDataSetFormatVersionException
 * @throws DataSetConfigurationException
 * @throws RegisterException
 * @throws IllegalAccessException
 * @throws InstantiationException
 * @throws UnknownDistanceMeasureException
 * @throws RNotAvailableException
 * @throws UnknownRunDataStatisticException
 * @throws UnknownRunStatisticException
 * @throws UnknownDataStatisticException
 * @throws NoOptimizableProgramParameterException
 * @throws UnknownParameterOptimizationMethodException
 * @throws IncompatibleParameterOptimizationMethodException
 * @throws IncompatibleDataSetConfigPreprocessorException
 * @throws UnknownDataPreprocessorException
 * @throws UnknownRProgramException
 * @throws UnknownProgramTypeException
 * @throws UnknownProgramParameterException
 * @throws InvalidOptimizationParameterException
 * @throws UnknownRunResultFormatException
 * @throws IncompatibleContextException
 * @throws RunException
 * @throws UnknownClusteringQualityMeasureException
 * @throws UnknownParameterType
 * @throws ConfigurationException
 * @throws NumberFormatException
 * @throws DataConfigNotFoundException
 * @throws DataConfigurationException
 * @throws GoldStandardConfigNotFoundException
 * @throws DataSetConfigNotFoundException
 * @throws GoldStandardConfigurationException
 * @throws GoldStandardNotFoundException
 * @throws UnknownContextException
 */
@Test
public void testLoadIntoMemory() throws NoRepositoryFoundException, UnknownDataSetFormatException,
        FormatConversionException, IOException, DataSetNotFoundException, InvalidDataSetFormatVersionException,
        DataSetConfigurationException, RegisterException, UnknownDataSetTypeException, NoDataSetException,
        InstantiationException, IllegalAccessException, UnknownDistanceMeasureException, RNotAvailableException,
        GoldStandardNotFoundException, GoldStandardConfigurationException, DataSetConfigNotFoundException,
        GoldStandardConfigNotFoundException, DataConfigurationException, DataConfigNotFoundException,
        NumberFormatException, ConfigurationException, UnknownContextException, UnknownParameterType,
        UnknownClusteringQualityMeasureException, RunException, IncompatibleContextException,
        UnknownRunResultFormatException, InvalidOptimizationParameterException,
        UnknownProgramParameterException, UnknownProgramTypeException, UnknownRProgramException,
        UnknownDataPreprocessorException, IncompatibleDataSetConfigPreprocessorException,
        IncompatibleParameterOptimizationMethodException, UnknownParameterOptimizationMethodException,
        NoOptimizableProgramParameterException, UnknownDataStatisticException, UnknownRunStatisticException,
        UnknownRunDataStatisticException {
    this.repositoryObject = Parser.parseFromFile(DataSet.class,
            new File("testCaseRepository/data/datasets/DS1/Zachary_karate_club_similarities.txt")
                    .getAbsoluteFile());

    DataSet standard = ((DataSet) this.repositoryObject).preprocessAndConvertTo(context,
            DataSetFormat.parseFromString(getRepository(), "SimMatrixDataSetFormat"),
            new ConversionInputToStandardConfiguration(
                    DistanceMeasure.parseFromString(getRepository(), "EuclidianDistanceMeasure"),
                    NUMBER_PRECISION.DOUBLE, new ArrayList<DataPreprocessor>(),
                    new ArrayList<DataPreprocessor>()),
            new ConversionStandardToInputConfiguration());
    Assert.assertFalse(standard.isInMemory());
    standard.loadIntoMemory();
    Assert.assertTrue(standard.isInMemory());
}

From source file:com.ebay.cloud.cms.query.service.QueryPaginationByIdTest.java

private void iteratorWithSort(final List<String> sortOnFields, long TOTAL_COUNT, String query,
        QueryContext queryContext, Set<String> allIds, int step) throws Exception {
    IQueryResult result;//  w  w  w .  j  a  v  a  2 s .  c o m
    int fetchCount = 0;
    int queryIterationCount = 0;

    Set<String> fetchedIds = new HashSet<String>();
    queryContext.getCursor().setLimits(null);
    queryContext.getCursor().setSingleCursorValue(null);
    queryContext.getCursor().removeSortOn();
    queryContext.getCursor().setLimits(new int[] { step });
    for (String sortOnField : sortOnFields) {
        queryContext.getCursor().addSortOn(sortOnField);
    }
    result = queryService.query(query, queryContext);
    queryIterationCount++;
    List<String> repeatedIds = new ArrayList<String>();
    do {
        for (IEntity e : result.getEntities()) {
            if (fetchedIds.contains(e.getId())) {
                repeatedIds.add(e.getId());
            } else {
                fetchedIds.add(e.getId());
            }
            fetchCount++;
        }
        if (result.hasMoreResults()) {
            Assert.assertNotNull(result.getNextCursor());
            Assert.assertNotNull(result.getNextCursor().getSortOn());
            Assert.assertFalse(result.getNextCursor().isJoinCursor());
            Assert.assertNotNull(result.getNextCursor().getSingleCursorValue());
            for (String sortField : sortOnFields) {
                Assert.assertTrue(result.getNextCursor().getSortOn().contains(sortField));
            }
            result.getNextCursor().setLimits(new int[] { step });
            queryContext.setCursor(result.getNextCursor());
            result = queryService.query(query, queryContext);
            queryIterationCount++;
        } else {
            break;
        }
    } while (true);
    System.out.println(" iterate count : " + queryIterationCount);
    Set<String> missedIds = CollectionUtils.diffSet(allIds, fetchedIds);
    if (TOTAL_COUNT != fetchCount) {
        StringBuilder sb = new StringBuilder();
        sb.append(" Repeated entity ids: ").append(new ObjectMapper().writeValueAsString(repeatedIds));
        sb.append(" Missed entity ids: ").append(new ObjectMapper().writeValueAsString(missedIds));
        Assert.fail(sb.toString());
    }
    Assert.assertEquals(" Missed entity ids: " + new ObjectMapper().writeValueAsString(missedIds), 0,
            missedIds.size());
    Assert.assertEquals(TOTAL_COUNT, fetchCount);
    Assert.assertEquals(0, repeatedIds.size());
    Assert.assertEquals(0, missedIds.size());
    Assert.assertEquals(TOTAL_COUNT, fetchedIds.size());
    //        Assert.assertEquals(2, queryIterationCount);
    fetchedIds.clear();
    fetchCount = 0;
    queryIterationCount = 0;
}

From source file:com.test.onesignal.GenerateNotificationRunner.java

@Test
@Config(shadows = { ShadowOneSignal.class })
public void shouldFireNotificationExtenderService() throws Exception {
    // Test that GCM receiver starts the NotificationExtenderServiceTest when it is in the AndroidManifest.xml
    Bundle bundle = getBaseNotifBundle();

    Intent serviceIntent = new Intent();
    serviceIntent.setPackage("com.onesignal.example");
    serviceIntent.setAction("com.onesignal.NotificationExtender");
    ResolveInfo resolveInfo = new ResolveInfo();
    resolveInfo.serviceInfo = new ServiceInfo();
    resolveInfo.serviceInfo.name = "com.onesignal.example.NotificationExtenderServiceTest";
    RuntimeEnvironment.getRobolectricPackageManager().addResolveInfoForIntent(serviceIntent, resolveInfo);

    boolean ret = OneSignalPackagePrivateHelper.GcmBroadcastReceiver_processBundle(blankActivity, bundle);
    Assert.assertTrue(ret);//from w  w w  . j  av a2  s . com

    Intent intent = Shadows.shadowOf(blankActivity).getNextStartedService();
    Assert.assertEquals("com.onesignal.NotificationExtender", intent.getAction());

    // Test that all options are set.
    NotificationExtenderServiceTest service = (NotificationExtenderServiceTest) startNotificationExtender(
            createInternalPayloadBundle(getBundleWithAllOptionsSet()), NotificationExtenderServiceTest.class);

    OSNotificationReceivedResult notificationReceived = service.notification;
    OSNotificationPayload notificationPayload = notificationReceived.payload;
    Assert.assertEquals("Test H", notificationPayload.title);
    Assert.assertEquals("Test B", notificationPayload.body);
    Assert.assertEquals("9764eaeb-10ce-45b1-a66d-8f95938aaa51", notificationPayload.notificationID);

    Assert.assertEquals(0, notificationPayload.lockScreenVisibility);
    Assert.assertEquals("FF0000FF", notificationPayload.smallIconAccentColor);
    Assert.assertEquals("703322744261", notificationPayload.fromProjectNumber);
    Assert.assertEquals("FFFFFF00", notificationPayload.ledColor);
    Assert.assertEquals("big_picture", notificationPayload.bigPicture);
    Assert.assertEquals("large_icon", notificationPayload.largeIcon);
    Assert.assertEquals("small_icon", notificationPayload.smallIcon);
    Assert.assertEquals("test_sound", notificationPayload.sound);
    Assert.assertEquals("You test $[notif_count] MSGs!", notificationPayload.groupMessage);
    Assert.assertEquals("http://google.com", notificationPayload.launchURL);
    Assert.assertEquals(10, notificationPayload.priority);
    Assert.assertEquals("a_key", notificationPayload.collapseId);

    Assert.assertEquals("id1", notificationPayload.actionButtons.get(0).id);
    Assert.assertEquals("button1", notificationPayload.actionButtons.get(0).text);
    Assert.assertEquals("ic_menu_share", notificationPayload.actionButtons.get(0).icon);
    Assert.assertEquals("id2", notificationPayload.actionButtons.get(1).id);
    Assert.assertEquals("button2", notificationPayload.actionButtons.get(1).text);
    Assert.assertEquals("ic_menu_send", notificationPayload.actionButtons.get(1).icon);

    Assert.assertEquals("test_image_url", notificationPayload.backgroundImageLayout.image);
    Assert.assertEquals("FF000000", notificationPayload.backgroundImageLayout.titleTextColor);
    Assert.assertEquals("FFFFFFFF", notificationPayload.backgroundImageLayout.bodyTextColor);

    JSONObject additionalData = notificationPayload.additionalData;
    Assert.assertEquals("myValue", additionalData.getString("myKey"));
    Assert.assertEquals("nValue", additionalData.getJSONObject("nested").getString("nKey"));

    Assert.assertNotSame(-1, service.notificationId);

    // Test a basic notification without anything special.
    startNotificationExtender(createInternalPayloadBundle(getBaseNotifBundle()),
            NotificationExtenderServiceTest.class);
    Assert.assertFalse(ShadowOneSignal.messages.contains("Error assigning"));

    // Test that a notification is still displayed if the developer's code in onNotificationProcessing throws an Exception.
    NotificationExtenderServiceTest.throwInAppCode = true;
    startNotificationExtender(createInternalPayloadBundle(getBaseNotifBundle("NewUUID1")),
            NotificationExtenderServiceTest.class);

    Assert.assertTrue(ShadowOneSignal.messages.contains("onNotificationProcessing throw an exception"));
    Map<Integer, PostedNotification> postedNotifs = ShadowRoboNotificationManager.notifications;
    Assert.assertEquals(3, postedNotifs.size());
}

From source file:com.ebay.cloud.cms.query.service.QueryPaginationByIdTest.java

private void queryAndIterate(long TOTAL_COUNT, String query, QueryContext queryContext, Set<String> allIds,
        int step) throws Exception {
    queryContext.getCursor().setLimits(null);
    queryContext.getCursor().setSingleCursorValue(null);

    Set<String> fetchedIds = new HashSet<String>();
    IQueryResult result;/* ww w.  j  av  a  2 s  .  co m*/
    int fetchCount = 0;
    queryContext.getCursor().setLimits(new int[] { step });
    result = queryService.query(query, queryContext);
    List<String> repeatedIds = new ArrayList<String>();
    do {
        for (IEntity e : result.getEntities()) {
            if (fetchedIds.contains(e.getId())) {
                repeatedIds.add(e.getId());
            } else {
                fetchedIds.add(e.getId());
            }
            fetchCount++;
        }
        if (result.hasMoreResults()) {
            Assert.assertNotNull(result.getNextCursor());
            Assert.assertNull(result.getNextCursor().getSortOn());
            Assert.assertNull(result.getNextCursor().getJoinCursorValues());
            Assert.assertFalse(result.getNextCursor().isJoinCursor());
            queryContext.setCursor(result.getNextCursor());
            result = queryService.query(query, queryContext);
        } else {
            break;
        }
    } while (true);

    Set<String> missedIds = CollectionUtils.diffSet(allIds, fetchedIds);
    Assert.assertEquals("Missed Entity ids : " + missedIds, 0, missedIds.size());
    System.out.println(" repeated entity ids: " + new ObjectMapper().writeValueAsString(repeatedIds));
    if (TOTAL_COUNT != fetchCount) {
        Assert.fail(" repeated entity ids: " + new ObjectMapper().writeValueAsString(repeatedIds));
    }
    Assert.assertEquals(TOTAL_COUNT, fetchCount);
    Assert.assertEquals(0, repeatedIds.size());
    Assert.assertEquals(TOTAL_COUNT, fetchedIds.size());
    //        Assert.assertEquals(2, queryIterationCount);
    fetchedIds.clear();
    fetchCount = 0;
}