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:org.openmrs.web.controller.provider.ProviderFormControllerTest.java

/**
 * @verifies should purge the provider//  w  ww.  j  av a  2  s. com
 * @see org.openmrs.web.controller.provider.ProviderFormController#onSubmit(javax.servlet.http.HttpServletRequest,
 *      String, String, String, String, org.openmrs.Provider,
 *      org.springframework.validation.BindingResult, org.springframework.ui.ModelMap)
 */
@Test(expected = ObjectNotFoundException.class)
public void onSubmit_shouldPurgeTheProvider() throws Exception {
    executeDataSet(PROVIDERS_ATTRIBUTES_XML);
    executeDataSet(PROVIDERS_XML);
    Provider provider = Context.getProviderService().getProvider(2);
    ProviderAttributeType providerAttributeType = Context.getProviderService().getProviderAttributeType(1);
    MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest();
    BindException errors = new BindException(provider, "provider");
    ProviderFormController providerFormController = (ProviderFormController) applicationContext
            .getBean("providerFormController");
    providerFormController.onSubmit(mockHttpServletRequest, null, null, null, "purge", provider, errors,
            createModelMap(providerAttributeType));
    Context.flushSession();
    Assert.assertNull(Context.getProviderService().getProvider(2));
}

From source file:com.dianping.dpsf.centralstat.test.CentralStatTestCase.java

@Test
public void testCallBackTimeout() throws Exception {
    log.info("$$$$$$$$$$testCallBackTimeout");
    String ret = null;/*from w w  w  . j  a  v  a 2  s . c o m*/
    try {
        CentralStatTestService service = (CentralStatTestService) context
                .getBean("centralStatTestServiceCallBack");
        service.invokeCallBackTimeOut("testCallBackTimeout");
    } catch (Exception e) {
        Assert.assertNull(ret);
    }

}

From source file:org.obiba.onyx.core.etl.participant.impl.XmlParticipantReaderTest.java

/**
 * Tests processing of an appointment list where a tag is missing for a mandatory attribute (Birth Date). XmlReader
 * should not return an error as it is a validation done in the ParticipantProcessor (Management is different here
 * from the default ParticipantReader class).
 * //from w  w  w .j  a  va2 s  .co m
 * @throws IOException if the appointment list could not be read
 */
@Test
public void testProcessWithMissingMandatoryAttributeTag() throws IOException {
    XmlParticipantReaderForTest reader = createXmlParticipantReaderForTest(false,
            TEST_RESOURCES_DIR + "/appointmentList_missingMandatoryAttributeTag.xml");
    reader.setColumnNameToAttributeNameMap(columnNameToAttributeNameMap);
    reader.setParticipantMetadata(participantMetadata);

    reader.open(context);
    List<Participant> participants = new ArrayList<Participant>();

    try {
        while (reader.getIterator().hasNext()) {
            Participant participant = reader.read();
            if (participant != null)
                participants.add(participant);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    Assert.assertEquals(3, participants.size());
    Assert.assertEquals("Tremblay", participants.get(0).getLastName());
    Assert.assertNull(participants.get(0).getBirthDate());
    Assert.assertEquals("Smith", participants.get(1).getLastName());
    Assert.assertNull(participants.get(1).getBirthDate());
    Assert.assertEquals("Casserly", participants.get(2).getLastName());
    Assert.assertNull(participants.get(2).getBirthDate());
}

From source file:eu.trentorise.smartcampus.ac.provider.repository.persistence.AcDaoPersistenceImplTest.java

public void testCreateAuthority() {
    Authority auth = new Authority();
    auth.setName("new_auth");
    auth.setRedirectUrl("new_url");

    Assert.assertNull(dao.readAuthorityByName("new_auth"));
    dao.create(auth);// w  w w .  j  a  v  a 2 s . co  m
    Assert.assertNotNull(dao.readAuthorityByName("new_auth"));

    auth = new Authority();
    auth.setName("new_auth1");
    auth.setRedirectUrl(AUTH_URL_PRESENT);
    try {
        dao.create(auth);
        Assert.fail("Exception not throw");
    } catch (IllegalArgumentException e) {
    }

    Assert.assertNull(dao.readAuthorityByName("new_auth1"));

    auth = new Authority();
    auth.setName(AUTH_NAME_PRESENT);
    auth.setRedirectUrl(AUTH_URL_NOT_PRESENT);
    try {
        dao.create(auth);
        Assert.fail("Exception not throw");
    } catch (IllegalArgumentException e) {
    }

    Assert.assertNull(dao.readAuthorityByName(AUTH_URL_NOT_PRESENT));

}

From source file:org.openxdata.server.service.impl.ReportServiceTest.java

@Test
public void deleteReportGroup_shouldDeleteGivenReportGroup() throws Exception {
    List<ReportGroup> reportGroups = reportsService.getReportGroups();

    ReportGroup reportGroup = getReportGroup("General", reportGroups);
    Assert.assertNotNull(reportGroup);//from ww w .j  av  a2s . co  m

    reportsService.deleteReportGroup(reportGroup);

    reportGroups = reportsService.getReportGroups();
    Assert.assertNull(getReportGroup("General", reportGroups));
}

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;/*from w ww.  j  ava2 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:com.netflix.curator.TestSessionFailRetryLoop.java

@Test
public void testBasic() throws Exception {
    Timing timing = new Timing();
    final CuratorZookeeperClient client = new CuratorZookeeperClient(server.getConnectString(),
            timing.session(), timing.connection(), null, new RetryOneTime(1));
    SessionFailRetryLoop retryLoop = client.newSessionFailRetryLoop(SessionFailRetryLoop.Mode.FAIL);
    retryLoop.start();/* w  ww . j a  v a2 s.c o  m*/
    try {
        client.start();
        try {
            while (retryLoop.shouldContinue()) {
                try {
                    RetryLoop.callWithRetry(client, new Callable<Void>() {
                        @Override
                        public Void call() throws Exception {
                            Assert.assertNull(client.getZooKeeper().exists("/foo/bar", false));
                            KillSession.kill(client.getZooKeeper(), server.getConnectString());

                            client.getZooKeeper();
                            client.blockUntilConnectedOrTimedOut();
                            Assert.assertNull(client.getZooKeeper().exists("/foo/bar", false));
                            return null;
                        }
                    });
                } catch (Exception e) {
                    retryLoop.takeException(e);
                }
            }

            Assert.fail();
        } catch (SessionFailRetryLoop.SessionFailedException dummy) {
            // correct
        }
    } finally {
        retryLoop.close();
        IOUtils.closeQuietly(client);
    }
}

From source file:de.hybris.platform.commercefacades.customer.DefaultCustomerFacadeIntegrationTest.java

@Test
public void testUpdatePassword() throws TokenInvalidatedException {
    final CustomerModel customerModel = userService.getUserForUID(TEST_USER_UID, CustomerModel.class);
    Assert.assertNull(customerModel.getToken());
    customerFacade.forgottenPassword("DeJol");
    modelService.refresh(customerModel);
    final String token = customerModel.getToken();
    Assert.assertNotNull(token);//w w  w  .  j  ava 2 s .c o  m
    customerFacade.updatePassword(token, NEW_PASSWORD);
    modelService.refresh(customerModel);
    Assert.assertNull(customerModel.getToken());
    final String expected = passwordEncoderService.encode(customerModel, NEW_PASSWORD, "md5");
    Assert.assertEquals(expected, customerModel.getEncodedPassword());
    try {
        customerFacade.updatePassword(token, NEW_PASSWORD_2);
        Assert.fail("TokenInvalidatedException expected");
    } catch (final TokenInvalidatedException e) {
        modelService.refresh(customerModel);
        Assert.assertEquals(expected, customerModel.getEncodedPassword());
    }
}

From source file:com.kmaismith.chunkclaim.Data.DataManagerTest.java

@Test
public void testDeleteChunkWillDeleteAChunkFromList() {
    Location location1 = helpers.newLocation("world", 123, 321);
    ChunkData chunk1 = helpers.newChunkData("player", new ArrayList<String>(), location1);
    chunk1 = systemUnderTest.addChunk(chunk1);
    systemUnderTest.writeChunkToStorage(chunk1);

    Assert.assertNotNull(systemUnderTest.getChunkAt(location1));
    systemUnderTest.deleteChunk(chunk1);
    Assert.assertNull(systemUnderTest.getChunkAt(location1));
}

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

@Test
public void testInitFromApplicationContext() throws Exception {
    // Application.onCreate
    OneSignal.init(RuntimeEnvironment.application, "123456789", ONESIGNAL_APP_ID);
    threadAndTaskWait();//from w w w .  j  a  va 2 s  . c o  m
    Assert.assertNotNull(ShadowOneSignalRestClient.lastPost);

    ShadowOneSignalRestClient.lastPost = null;
    StaticResetHelper.restSetStaticFields();

    // Restart app, should not send onSession automatically
    OneSignal.init(RuntimeEnvironment.application, "123456789", ONESIGNAL_APP_ID);
    threadAndTaskWait();
    Assert.assertNull(ShadowOneSignalRestClient.lastPost);

    // Starting of first Activity should trigger onSession
    blankActivityController.resume();
    threadAndTaskWait();
    Assert.assertNotNull(ShadowOneSignalRestClient.lastPost);
}