Example usage for junit.framework Assert assertNotNull

List of usage examples for junit.framework Assert assertNotNull

Introduction

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

Prototype

static public void assertNotNull(Object object) 

Source Link

Document

Asserts that an object isn't null.

Usage

From source file:com.cubusmail.server.user.UserAccountDaoTest.java

@Test
public void testCreateUpdateUserAccount() {

    try {//from w ww.  j ava  2 s  .c o m
        UserAccount userAccount = this.userAccountDao.getUserAccountByUsername("testuser");
        Assert.assertNotNull(userAccount);

        userAccount.getPreferences().setTheme("Testtheme");
        this.userAccountDao.saveUserAccount(userAccount);

        UserAccount userAccount2 = this.userAccountDao.getUserAccountByUsername("testuser");
        Assert.assertEquals("Testtheme", userAccount2.getPreferences().getTheme());
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        Assert.fail(e.getMessage());
    }
}

From source file:ejportal.webapp.action.JournalActionTest.java

/**
 * Test remove.// w  w w .  ja  v a  2 s . c o  m
 * 
 * @throws Exception
 *             the exception
 */
public void testRemove() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    ServletActionContext.setRequest(request);
    this.action.setDelete("");
    final Journal journal = new Journal();
    journal.setId(2L);
    // action.setJournal(journal);
    this.action.setJournalId(2L);
    Assert.assertEquals("success", this.action.delete());
    Assert.assertNotNull(request.getSession().getAttribute("messages"));
}

From source file:amqp.spring.camel.component.SpringAMQPConsumerTest.java

@Test
public void sendAsyncMessage() throws Exception {
    MockEndpoint mockEndpoint = getMockEndpoint("mock:test.b");
    mockEndpoint.expectedMessageCount(1);
    context().createProducerTemplate().asyncRequestBodyAndHeader(
            "spring-amqp:directExchange:test.b?durable=false&autodelete=true&exclusive=false", "sendMessage",
            "HeaderKey", "HeaderValue");

    mockEndpoint.assertIsSatisfied();/* w  ww.j a v  a2 s. c  o m*/
    Message inMessage = mockEndpoint.getExchanges().get(0).getIn();
    Assert.assertEquals("sendMessage", inMessage.getBody(String.class));
    Assert.assertEquals("HeaderValue", inMessage.getHeader("HeaderKey"));
    Assert.assertNotNull(inMessage.getMessageId());
}

From source file:org.springsource.examples.expenses.TestDatabaseExpenseReportingService.java

@Test
public void testValidation() throws Throwable {
    // create a report
    Long erId = reportingService.createNewReport(this.purpose);
    Assert.assertNotNull(erId);
    // add expenses, one valid, one invalid
    List<Expense> expenses = reportingService.addExpenses(erId, this.charges);
    Assert.assertEquals(expenses.size(), this.charges.size());

    FilingResult filingResultStatus = reportingService.fileReport(erId);
    Expense found = null;//from   w  w w  .j a  va2  s .c o m
    for (Expense e : filingResultStatus.getExpenseReport().getExpenses()) {
        if (e.isFlagged()) {
            found = e;
        }
    }
    Assert.assertNotNull(found); // we know that ONE of them is invalid
    Assert.assertTrue(filingResultStatus.getStatus().equals(FilingResultStatus.VALIDATION_ERROR));
    Assert.assertTrue(found.isFlagged());
    Assert.assertFalse("the message returned should not be null", StringUtils.isEmpty(found.getFlag()));
}

From source file:com.netflix.curator.framework.recipes.locks.TestReaper.java

@Test
public void testSparseUseNoReap() throws Exception {
    final int THRESHOLD = 3000;

    Timing timing = new Timing();
    Reaper reaper = null;//w  w  w. j  a v  a  2  s  .  c  o  m
    Future<Void> watcher = null;
    CuratorFramework client = makeClient(timing, null);
    try {
        client.start();
        client.create().creatingParentsIfNeeded().forPath("/one/two/three");

        Assert.assertNotNull(client.checkExists().forPath("/one/two/three"));

        final Queue<Reaper.PathHolder> holders = new ConcurrentLinkedQueue<Reaper.PathHolder>();
        final ExecutorService pool = Executors.newCachedThreadPool();
        ScheduledExecutorService service = new ScheduledThreadPoolExecutor(1) {
            @Override
            public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) {
                final Reaper.PathHolder pathHolder = (Reaper.PathHolder) command;
                holders.add(pathHolder);
                final ScheduledFuture<?> f = super.schedule(command, delay, unit);
                pool.submit(new Callable<Void>() {
                    @Override
                    public Void call() throws Exception {
                        f.get();
                        holders.remove(pathHolder);
                        return null;
                    }
                });
                return f;
            }
        };

        reaper = new Reaper(client, service, THRESHOLD);
        reaper.start();
        reaper.addPath("/one/two/three");

        long start = System.currentTimeMillis();
        boolean emptyCountIsCorrect = false;
        while (((System.currentTimeMillis() - start) < timing.forWaiting().milliseconds())
                && !emptyCountIsCorrect) // need to loop as the Holder can go in/out of the Reaper's DelayQueue
        {
            for (Reaper.PathHolder holder : holders) {
                if (holder.path.endsWith("/one/two/three")) {
                    emptyCountIsCorrect = (holder.emptyCount > 0);
                    break;
                }
            }
            Thread.sleep(1);
        }
        Assert.assertTrue(emptyCountIsCorrect);

        client.create().forPath("/one/two/three/foo");

        Thread.sleep(2 * (THRESHOLD / Reaper.EMPTY_COUNT_THRESHOLD));
        Assert.assertNotNull(client.checkExists().forPath("/one/two/three"));
        client.delete().forPath("/one/two/three/foo");

        Thread.sleep(THRESHOLD);
        timing.sleepABit();

        Assert.assertNull(client.checkExists().forPath("/one/two/three"));
    } finally {
        if (watcher != null) {
            watcher.cancel(true);
        }
        IOUtils.closeQuietly(reaper);
        IOUtils.closeQuietly(client);
    }
}

From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.ConceptNameControllerTest.java

@Test
public void shouldEditAConceptName() throws Exception {
    SimpleObject results = controller.getAll(conceptUuid, request, response);
    List<Object> resultsList = (List<Object>) PropertyUtils.getProperty(results, "results");
    Assert.assertEquals(1, resultsList.size());
    ConceptName conceptName = service.getConceptNameByUuid(nameUuid);
    Assert.assertNotNull(conceptName);
    Assert.assertEquals("COUGH SYRUP", conceptName.getName());

    String json = "{ \"name\":\"NEW TEST NAME\"}";
    SimpleObject post = new ObjectMapper().readValue(json, SimpleObject.class);
    controller.update(conceptUuid, nameUuid, post, request, response);

    ConceptName updateConceptName = service.getConceptNameByUuid(nameUuid);
    //should have voided the old edited name
    Assert.assertTrue(updateConceptName.isVoided());
    SimpleObject results2 = controller.getAll(conceptUuid, request, response);
    List<Object> results2List = (List<Object>) PropertyUtils.getProperty(results2, "results");
    Assert.assertEquals(1, results2List.size());
    //should have created a new one with the new name
    Assert.assertTrue(PropertyUtils.getProperty(results2List.get(0), "name").equals("NEW TEST NAME"));
}

From source file:org.sakaiproject.iclicker.dao.IClickerDaoImplTest.java

/**
 * Test method for/*from  w  w w.j a  v a2s .com*/
 * {@link org.sakaiproject.iclicker.dao.impl.GenericHibernateDao#save(java.lang.Object)}.
 */
public void testSave() {
    ClickerRegistration item1 = new ClickerRegistration("New item1", ITEM_OWNER);
    dao.save(item1);
    Long itemId = item1.getId();
    Assert.assertNotNull(itemId);
    Assert.assertTrue(dao.countAll(ClickerRegistration.class) > 8);
}

From source file:ejportal.webapp.action.KonsortiumActionTest.java

/**
 * Test remove./*from   w  w w .j  a va2s  . c o  m*/
 * 
 * @throws Exception
 *             the exception
 */
public void testRemove() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    ServletActionContext.setRequest(request);
    this.action.setDelete("");
    final Konsortium Konsortium = new Konsortium();
    Konsortium.setKonsortiumId(2L);
    // action.setKonsortium(Konsortium);
    this.action.setKonsortiumId(2L);
    Assert.assertEquals("success", this.action.delete());
    Assert.assertNotNull(request.getSession().getAttribute("messages"));
}

From source file:net.krautchan.data.KCThread.java

public void recalc() {
    try {/* ww  w.  j  a v  a  2  s  .  c om*/
        Iterator<Entry<Long, KCPosting>> iter = postings.entrySet().iterator();
        if (iter.hasNext()) {
            Entry<Long, KCPosting> entry = iter.next();
            KCPosting posting = entry.getValue();
            if (null == digest) {
                makeDigest(posting);
            }
            if (null == firstPostDate) {
                firstPostDate = posting.getCreated();
            }
        }
        Assert.assertNotNull(this.getDbId());
    } catch (Exception e) {
        String trace = "Exception in KCThread " + kcNummer + " " + e.getClass().getCanonicalName() + "\n";
        for (StackTraceElement elem : e.getStackTrace()) {
            trace += " " + elem.toString() + "\n";
        }
        System.err.println(trace);
    }
}

From source file:io.cloudslang.engine.node.services.WorkerNodeServiceTest.java

@Test
public void keepAlive() throws Exception {
    when(versionService.getCurrentVersion(anyString())).thenReturn(5L);

    WorkerNode worker = workerNodeService.readByUUID("H1");
    Date origDate = worker.getAckTime();
    Assert.assertNull(origDate);/*  ww w . j  av  a2s  . co m*/
    workerNodeService.keepAlive("H1");
    workerNodeRepository.flush();
    worker = workerNodeService.readByUUID("H1");
    Assert.assertNotNull(worker.getAckTime());
    Assert.assertEquals(5, worker.getAckVersion());

}