Example usage for junit.framework Assert assertNull

List of usage examples for junit.framework Assert assertNull

Introduction

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

Prototype

static public void assertNull(Object object) 

Source Link

Document

Asserts that an object is null.

Usage

From source file:com.couchbase.touchdb.testapp.tests.Attachments.java

@SuppressWarnings("unchecked")
public void testPutAttachment() {

    TDBlobStore attachments = database.getAttachments();

    // Put a revision that includes an _attachments dict:
    byte[] attach1 = "This is the body of attach1".getBytes();
    String base64 = Base64.encodeBytes(attach1);

    Map<String, Object> attachment = new HashMap<String, Object>();
    attachment.put("content_type", "text/plain");
    attachment.put("data", base64);
    Map<String, Object> attachmentDict = new HashMap<String, Object>();
    attachmentDict.put("attach", attachment);
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put("foo", 1);
    properties.put("bar", false);
    properties.put("_attachments", attachmentDict);

    TDStatus status = new TDStatus();
    TDRevision rev1 = database.putRevision(new TDRevision(properties), null, false, status);

    Assert.assertEquals(TDStatus.CREATED, status.getCode());
    // Examine the attachment store:
    Assert.assertEquals(1, attachments.count());

    // Get the revision:
    TDRevision gotRev1 = database.getDocumentWithIDAndRev(rev1.getDocId(), rev1.getRevId(),
            EnumSet.noneOf(TDDatabase.TDContentOptions.class));
    Map<String, Object> gotAttachmentDict = (Map<String, Object>) gotRev1.getProperties().get("_attachments");

    Map<String, Object> innerDict = new HashMap<String, Object>();
    innerDict.put("content_type", "text/plain");
    innerDict.put("digest", "sha1-gOHUOBmIMoDCrMuGyaLWzf1hQTE=");
    innerDict.put("length", 27);
    innerDict.put("stub", true);
    innerDict.put("revpos", 1);

    Map<String, Object> expectAttachmentDict = new HashMap<String, Object>();
    expectAttachmentDict.put("attach", innerDict);

    Assert.assertEquals(expectAttachmentDict, gotAttachmentDict);

    // Update the attachment directly:
    byte[] attachv2 = "Replaced body of attach".getBytes();
    database.updateAttachment("attach", new ByteArrayInputStream(attachv2), "application/foo", rev1.getDocId(),
            null, status);//  w w w. ja v  a2s .  c  o m
    Assert.assertEquals(TDStatus.CONFLICT, status.getCode());
    database.updateAttachment("attach", new ByteArrayInputStream(attachv2), "application/foo", rev1.getDocId(),
            "1-bogus", status);
    Assert.assertEquals(TDStatus.CONFLICT, status.getCode());
    TDRevision rev2 = database.updateAttachment("attach", new ByteArrayInputStream(attachv2), "application/foo",
            rev1.getDocId(), rev1.getRevId(), status);
    Assert.assertEquals(TDStatus.CREATED, status.getCode());
    Assert.assertEquals(rev1.getDocId(), rev2.getDocId());
    Assert.assertEquals(2, rev2.getGeneration());

    // Get the updated revision:
    TDRevision gotRev2 = database.getDocumentWithIDAndRev(rev2.getDocId(), rev2.getRevId(),
            EnumSet.noneOf(TDDatabase.TDContentOptions.class));
    attachmentDict = (Map<String, Object>) gotRev2.getProperties().get("_attachments");

    innerDict = new HashMap<String, Object>();
    innerDict.put("content_type", "application/foo");
    innerDict.put("digest", "sha1-mbT3208HI3PZgbG4zYWbDW2HsPk=");
    innerDict.put("length", 23);
    innerDict.put("stub", true);
    innerDict.put("revpos", 2);

    expectAttachmentDict.put("attach", innerDict);

    Assert.assertEquals(expectAttachmentDict, attachmentDict);

    // Delete the attachment:
    database.updateAttachment("nosuchattach", null, null, rev2.getDocId(), rev2.getRevId(), status);
    Assert.assertEquals(TDStatus.NOT_FOUND, status.getCode());

    database.updateAttachment("nosuchattach", null, null, "nosuchdoc", "nosuchrev", status);
    Assert.assertEquals(TDStatus.NOT_FOUND, status.getCode());

    TDRevision rev3 = database.updateAttachment("attach", null, null, rev2.getDocId(), rev2.getRevId(), status);
    Assert.assertEquals(TDStatus.OK, status.getCode());
    Assert.assertEquals(rev2.getDocId(), rev3.getDocId());
    Assert.assertEquals(3, rev3.getGeneration());

    // Get the updated revision:
    TDRevision gotRev3 = database.getDocumentWithIDAndRev(rev3.getDocId(), rev3.getRevId(),
            EnumSet.noneOf(TDDatabase.TDContentOptions.class));
    attachmentDict = (Map<String, Object>) gotRev3.getProperties().get("_attachments");
    Assert.assertNull(attachmentDict);

    database.close();
}

From source file:com.couchbase.cblite.testapp.tests.Attachments.java

@SuppressWarnings("unchecked")
public void testPutAttachment() {

    CBLBlobStore attachments = database.getAttachments();

    // Put a revision that includes an _attachments dict:
    byte[] attach1 = "This is the body of attach1".getBytes();
    String base64 = Base64.encodeBytes(attach1);

    Map<String, Object> attachment = new HashMap<String, Object>();
    attachment.put("content_type", "text/plain");
    attachment.put("data", base64);
    Map<String, Object> attachmentDict = new HashMap<String, Object>();
    attachmentDict.put("attach", attachment);
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put("foo", 1);
    properties.put("bar", false);
    properties.put("_attachments", attachmentDict);

    CBLStatus status = new CBLStatus();
    CBLRevision rev1 = database.putRevision(new CBLRevision(properties), null, false, status);

    Assert.assertEquals(CBLStatus.CREATED, status.getCode());
    // Examine the attachment store:
    Assert.assertEquals(1, attachments.count());

    // Get the revision:
    CBLRevision gotRev1 = database.getDocumentWithIDAndRev(rev1.getDocId(), rev1.getRevId(),
            EnumSet.noneOf(CBLDatabase.TDContentOptions.class));
    Map<String, Object> gotAttachmentDict = (Map<String, Object>) gotRev1.getProperties().get("_attachments");

    Map<String, Object> innerDict = new HashMap<String, Object>();
    innerDict.put("content_type", "text/plain");
    innerDict.put("digest", "sha1-gOHUOBmIMoDCrMuGyaLWzf1hQTE=");
    innerDict.put("length", 27);
    innerDict.put("stub", true);
    innerDict.put("revpos", 1);

    Map<String, Object> expectAttachmentDict = new HashMap<String, Object>();
    expectAttachmentDict.put("attach", innerDict);

    Assert.assertEquals(expectAttachmentDict, gotAttachmentDict);

    // Update the attachment directly:
    byte[] attachv2 = "Replaced body of attach".getBytes();
    database.updateAttachment("attach", new ByteArrayInputStream(attachv2), "application/foo", rev1.getDocId(),
            null, status);/*from  w  w w .j a  v a  2 s .com*/
    Assert.assertEquals(CBLStatus.CONFLICT, status.getCode());
    database.updateAttachment("attach", new ByteArrayInputStream(attachv2), "application/foo", rev1.getDocId(),
            "1-bogus", status);
    Assert.assertEquals(CBLStatus.CONFLICT, status.getCode());
    CBLRevision rev2 = database.updateAttachment("attach", new ByteArrayInputStream(attachv2),
            "application/foo", rev1.getDocId(), rev1.getRevId(), status);
    Assert.assertEquals(CBLStatus.CREATED, status.getCode());
    Assert.assertEquals(rev1.getDocId(), rev2.getDocId());
    Assert.assertEquals(2, rev2.getGeneration());

    // Get the updated revision:
    CBLRevision gotRev2 = database.getDocumentWithIDAndRev(rev2.getDocId(), rev2.getRevId(),
            EnumSet.noneOf(CBLDatabase.TDContentOptions.class));
    attachmentDict = (Map<String, Object>) gotRev2.getProperties().get("_attachments");

    innerDict = new HashMap<String, Object>();
    innerDict.put("content_type", "application/foo");
    innerDict.put("digest", "sha1-mbT3208HI3PZgbG4zYWbDW2HsPk=");
    innerDict.put("length", 23);
    innerDict.put("stub", true);
    innerDict.put("revpos", 2);

    expectAttachmentDict.put("attach", innerDict);

    Assert.assertEquals(expectAttachmentDict, attachmentDict);

    // Delete the attachment:
    database.updateAttachment("nosuchattach", null, null, rev2.getDocId(), rev2.getRevId(), status);
    Assert.assertEquals(CBLStatus.NOT_FOUND, status.getCode());

    database.updateAttachment("nosuchattach", null, null, "nosuchdoc", "nosuchrev", status);
    Assert.assertEquals(CBLStatus.NOT_FOUND, status.getCode());

    CBLRevision rev3 = database.updateAttachment("attach", null, null, rev2.getDocId(), rev2.getRevId(),
            status);
    Assert.assertEquals(CBLStatus.OK, status.getCode());
    Assert.assertEquals(rev2.getDocId(), rev3.getDocId());
    Assert.assertEquals(3, rev3.getGeneration());

    // Get the updated revision:
    CBLRevision gotRev3 = database.getDocumentWithIDAndRev(rev3.getDocId(), rev3.getRevId(),
            EnumSet.noneOf(CBLDatabase.TDContentOptions.class));
    attachmentDict = (Map<String, Object>) gotRev3.getProperties().get("_attachments");
    Assert.assertNull(attachmentDict);

    database.close();
}

From source file:org.openmrs.module.atomfeed.AtomFeedUtilTest.java

/**
 * @see AtomFeedUtil#dateToRFC3339(Date)
 * @verifies not fail given a null date//w  w w  .  ja va 2s .  com
 */
@Test
public void dateToRFC3339_shouldNotFailGivenANullDate() throws Exception {
    Date nDate = null;
    Assert.assertNull(AtomFeedUtil.dateToRFC3339(nDate));
}

From source file:ma.glasnost.orika.test.perf.MultiThreadedTestCase.java

/**
 * Since the contract for SoftReference states that all soft references will
 * be cleared by the garbage collector before OOME is thrown, we allocate
 * dummy bytes until we reach OOME.//from  w ww  . ja v  a2 s .  c  o  m
 */
private void forceClearSoftAndWeakReferences() {

    SoftReference<Object> checkReference = new SoftReference<Object>(new Object());
    Assert.assertNotNull(checkReference.get());
    try {
        List<byte[]> byteBucket = new ArrayList<byte[]>();
        for (int i = 0; i < Integer.MAX_VALUE; ++i) {
            int available = (int) Math.min((long) Integer.MAX_VALUE, Runtime.getRuntime().maxMemory());
            byteBucket.add(new byte[available]);
        }
    } catch (Throwable e) {
        // Ignore OME; soft references should now have been cleared
        Assert.assertNull(checkReference.get());
    }

}

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

@Test
public void testDisableOpeningLauncherActivityOnNotifiOpen() throws Exception {
    ShadowApplication.getInstance().getAppManifest().getApplicationMetaData()
            .put("com.onesignal.NotificationOpened.DEFAULT", "DISABLE");
    RuntimeEnvironment.getRobolectricPackageManager().addManifest(
            ShadowApplication.getInstance().getAppManifest(),
            ShadowApplication.getInstance().getResourceLoader());
    AddLauncherIntentFilter();// www  .j  a v  a 2 s.co  m

    // From app launching normally
    Assert.assertNotNull(Shadows.shadowOf(blankActivity).getNextStartedActivity());
    OneSignal.init(blankActivity, "123456789", ONESIGNAL_APP_ID, new OneSignal.NotificationOpenedHandler() {
        @Override
        public void notificationOpened(String message, JSONObject additionalData, boolean isActive) {
            notificationOpenedMessage = message;
        }
    });
    Assert.assertNull(notificationOpenedMessage);

    OneSignal.handleNotificationOpened(blankActivity,
            new JSONArray("[{ \"alert\": \"Test Msg\", \"custom\": { \"i\": \"UUID\" } }]"), false);

    Assert.assertNull(Shadows.shadowOf(blankActivity).getNextStartedActivity());
    Assert.assertEquals("Test Msg", notificationOpenedMessage);
}

From source file:org.openmrs.module.paperrecord.PaperRecordServiceComponentTest.java

@Test
public void testRequestPaperRecordWhenNoValidPatientIdentifierForPaperRecord() {

    // all these are from the standard test dataset
    Patient patient = patientService.getPatient(2);
    Location medicalRecordLocation = locationService.getLocation(2);
    Location requestLocation = locationService.getLocation(3);

    paperRecordService.requestPaperRecord(patient, medicalRecordLocation, requestLocation);

    // first, make sure that this record is not returned by the "to pull" service method
    Assert.assertEquals(0, paperRecordService.getOpenPaperRecordRequestsToPull(medicalRecordLocation).size());

    // make sure the record is in the database
    List<PaperRecordRequest> requests = paperRecordService
            .getOpenPaperRecordRequestsToCreate(medicalRecordLocation);
    Assert.assertEquals(1, requests.size());
    PaperRecordRequest request = requests.get(0);
    Assert.assertEquals(new Integer(2), request.getPaperRecord().getPatientIdentifier().getPatient().getId());
    Assert.assertEquals(new Integer(2), request.getPaperRecord().getRecordLocation().getId());
    Assert.assertEquals(new Integer(3), request.getRequestLocation().getId());
    Assert.assertEquals("A00001", request.getPaperRecord().getPatientIdentifier().getIdentifier());
    Assert.assertEquals(PaperRecordRequest.Status.OPEN, request.getStatus());
    Assert.assertEquals(PaperRecord.Status.PENDING_CREATION, request.getPaperRecord().getStatus());
    Assert.assertNull(request.getAssignee());

}

From source file:com.couchbase.lite.DatabaseAttachmentTest.java

/**
 * in DatabaseAttachment_Tests.m/*from  w  ww.  j a v a  2s. c o  m*/
 * - (void) test11_PutAttachment
 */
@SuppressWarnings("unchecked")
public void test11_PutAttachment() throws Exception {

    // Put a revision that includes an _attachments dict:
    RevisionInternal rev1 = putDocWithAttachment(null, "This is the body of attach1", false);
    Map<String, Object> itemDict = new HashMap<String, Object>();
    itemDict.put("content_type", "text/plain");
    itemDict.put("digest", "sha1-gOHUOBmIMoDCrMuGyaLWzf1hQTE=");
    itemDict.put("length", 27);
    itemDict.put("stub", true);
    itemDict.put("revpos", 1);
    Map<String, Object> attachmentDict = new HashMap<String, Object>();
    attachmentDict.put("attach", itemDict);
    Assert.assertEquals(attachmentDict, rev1.getAttachments());

    // Examine the attachment store:
    Assert.assertEquals(database.getAttachmentStore().count(), 1);

    // Get the revision:
    RevisionInternal gotRev1 = database.getDocument(rev1.getDocID(), rev1.getRevID(), true);
    Assert.assertEquals(attachmentDict, gotRev1.getAttachments());

    // Update the attachment directly:
    boolean gotExpectedErrorCode = false;
    byte[] attachv2 = "Replaced body of attach".getBytes();
    try {
        database.updateAttachment("attach", blobForData(database, attachv2), "application/foo",
                AttachmentInternal.AttachmentEncoding.AttachmentEncodingNone, rev1.getDocID(), null, null);
    } catch (CouchbaseLiteException e) {
        gotExpectedErrorCode = (e.getCBLStatus().getCode() == Status.CONFLICT);
    }
    Assert.assertTrue(gotExpectedErrorCode);

    gotExpectedErrorCode = false;
    try {
        database.updateAttachment("attach", blobForData(database, attachv2), "application/foo",
                AttachmentInternal.AttachmentEncoding.AttachmentEncodingNone, rev1.getDocID(), "1-deadbeef",
                null);
    } catch (CouchbaseLiteException e) {
        gotExpectedErrorCode = (e.getCBLStatus().getCode() == Status.CONFLICT);
    }
    Assert.assertTrue(gotExpectedErrorCode);

    RevisionInternal rev2 = database.updateAttachment("attach", blobForData(database, attachv2),
            "application/foo", AttachmentInternal.AttachmentEncoding.AttachmentEncodingNone, rev1.getDocID(),
            rev1.getRevID(), null);
    Assert.assertNotNull(rev2);
    Assert.assertEquals(rev1.getDocID(), rev2.getDocID());
    Assert.assertEquals(2, rev2.getGeneration());

    // Get the updated revision:
    RevisionInternal gotRev2 = database.getDocument(rev2.getDocID(), rev2.getRevID(), true);

    itemDict = new HashMap<String, Object>();
    itemDict.put("content_type", "application/foo");
    itemDict.put("digest", "sha1-mbT3208HI3PZgbG4zYWbDW2HsPk=");
    itemDict.put("length", 23);
    itemDict.put("stub", true);
    itemDict.put("revpos", 2);
    attachmentDict = new HashMap<String, Object>();
    attachmentDict.put("attach", itemDict);

    Assert.assertEquals(attachmentDict, gotRev2.getAttachments());

    // Delete the attachment:
    gotExpectedErrorCode = false;
    try {
        database.updateAttachment("nosuchattach", null, null,
                AttachmentInternal.AttachmentEncoding.AttachmentEncodingNone, rev2.getDocID(), rev2.getRevID(),
                null);
    } catch (CouchbaseLiteException e) {
        gotExpectedErrorCode = (e.getCBLStatus().getCode() == Status.NOT_FOUND);
    }
    Assert.assertTrue(gotExpectedErrorCode);

    gotExpectedErrorCode = false;
    try {
        database.updateAttachment("nosuchattach", null, null,
                AttachmentInternal.AttachmentEncoding.AttachmentEncodingNone, "nosuchdoc", "nosuchrev", null);
    } catch (CouchbaseLiteException e) {
        gotExpectedErrorCode = (e.getCBLStatus().getCode() == Status.NOT_FOUND);
    }
    Assert.assertTrue(gotExpectedErrorCode);

    RevisionInternal rev3 = database.updateAttachment("attach", null, null,
            AttachmentInternal.AttachmentEncoding.AttachmentEncodingNone, rev2.getDocID(), rev2.getRevID(),
            null);
    Assert.assertNotNull(rev2);
    Assert.assertEquals(rev2.getDocID(), rev3.getDocID());
    Assert.assertEquals(3, rev3.getGeneration());

    // Get the updated revision:
    RevisionInternal gotRev3 = database.getDocument(rev3.getDocID(), rev3.getRevID(), true);
    Assert.assertNull(gotRev3.getAttachments());
}

From source file:org.openmrs.logic.LogicServiceTest.java

/**
 * @see {@link LogicService#getRule(String)}
 */// w w w.j  ava  2s  .  co  m
@Test(expected = LogicException.class)
@Verifies(value = "should fail when no Rule is associated with the input token", method = "getRule(String)")
public void getRule_shouldFailWhenNoRuleIsAssociatedWithTheInputToken() throws Exception {
    Rule rule = Context.getLogicService().getRule("UNKNOWN RULE");
    Assert.assertNull(rule);
}

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

@Test
public void testNotificationReceivedWhenAppInFocus() throws Exception {
    OneSignal.init(blankActivity, "123456789", ONESIGNAL_APP_ID, new OneSignal.NotificationOpenedHandler() {
        @Override/*w  w w  . j a v  a  2s  . c om*/
        public void notificationOpened(String message, JSONObject additionalData, boolean isActive) {
            notificationOpenedMessage = message;
        }
    });
    threadAndTaskWait();
    Assert.assertNull(notificationOpenedMessage);

    NotificationBundleProcessor.Process(blankActivity, GenerateNotificationRunner.getBaseNotifBundle());
    threadAndTaskWait();
    Assert.assertEquals("Robo test message", notificationOpenedMessage);
}

From source file:de.hybris.platform.catalog.jalo.synchronization.ItemCopyCreatorTest.java

@Ignore("can not easily write test case for nested ItemCopyCreators ")
@Test/*  w  w  w.  ja  v  a2 s  . com*/
public void testExceptionDuringCreationPartOfAttributes() throws JaloPriceFactoryException {
    final Currency eur = getOrCreateCurrency("eur");
    final Unit unit = ProductManager.getInstance().createUnit("p", "piece");
    final Set<Language> languages = jaloSession.getC2LManager().getAllLanguages();
    //determine other attribute
    final CatalogVersionSyncCopyContext ctx = new CatalogVersionSyncCopyContext(syncJob, syncCronJob, worker) {
        @Override
        SynchronizationPersistenceAdapter getPersistenceAdapter() {
            return new LegacySynchronizationPersistenceAdapter(this) {
                @Override
                public void update(final Item entity, final Map.Entry<String, Object> attribute)
                        throws SynchronizationPersistenceException {
                    //if other attribute
                    if ("europe1Prices".equalsIgnoreCase(attribute.getKey())) {
                        throw new IllegalStateException(
                                "expected exception during setting partof attributes  ...");
                    }
                    super.update(entity, attribute);
                }
            };
        }

        @Override
        protected Set<Language> getTargetLanguages() {
            return languages;
        }

    };

    final Product source = ProductManager.getInstance().createProduct(PRODUCT_FAILING_ON_CREATE);

    Europe1PriceFactory.getInstance().createPriceRow(source, null, null, null, 0, eur, unit, 1, false, null,
            99.99);

    final Product target = null;

    final Collection<String> whiteList = Arrays.asList(Product.CODE, "europe1Prices"/*
                                                                                     * , Product.NAME, Product.TYPE,
                                                                                     * Product.PK
                                                                                     */);
    final Collection<String> blackList = Arrays.asList(Product.MODIFIED_TIME, Product.CREATION_TIME);

    final Map<String, Object> presets = Collections.EMPTY_MAP;
    final ItemCopyCreator copyCreator = new ItemCopyCreator(ctx, null, source, target, blackList, whiteList,
            presets);

    final Product result = copyCreator.copy();

    Assert.assertEquals(0,
            Europe1PriceFactory.getInstance()
                    .getProductPriceRows(jaloSession.getSessionContext(), result,
                            Europe1PriceFactory.getInstance().getPPG(jaloSession.getSessionContext(), result))
                    .size());
    Assert.assertNull(
            catalogManager.getProductByCatalogVersion(syncJob.getTargetVersion(), PRODUCT_FAILING_ON_CREATE));
}