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:io.seldon.recommendation.VariationTestingClientStrategyTest.java

@Test
public void testSampling() {
    List<Variation> variations = new ArrayList<Variation>();
    int max = 4;//from   www.  j a  v a2  s.  c  o m
    double ratio = 1 / (max * 1.0);
    for (int i = 1; i <= max; i++) {
        ClientStrategy s = new TestStrategy("" + i);
        Variation v = new Variation(s, new BigDecimal(ratio));
        variations.add(v);
    }
    VariationTestingClientStrategy v = VariationTestingClientStrategy.build(variations);
    Random r = new Random();
    int[] sTot = new int[max];
    int sampleSize = 10000000;
    for (int i = 0; i < sampleSize; i++) {
        String userId = "u" + r.nextLong();
        ClientStrategy s = v.sample(userId);
        Assert.assertNotNull(s);
        int index = Integer.parseInt(s.getName(null, null)) - 1;
        sTot[index] += 1;
    }
    Assert.assertEquals(1 / (max * 1.0), sTot[0] / (sampleSize * 1.0), 0.001);
}

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

@Test
public void deleteForm_shouldDeleteGivenForm() throws Exception {

    final String formName = "Form Name";

    List<FormDef> forms = studyManagerService.getForms();
    int numberOfForms = forms.size();

    FormDef form = new FormDef();
    form.setName(formName);/*  w ww . ja v  a2 s  . c om*/
    form.setCreator(userService.getUsers().get(0));
    form.setDateCreated(new Date());

    studyManagerService.saveForm(form);
    forms = studyManagerService.getForms();
    Assert.assertEquals("Added one form, so now there is one more", (numberOfForms + 1), forms.size());
    form = getForm(formName, forms);
    Assert.assertNotNull(form);

    studyManagerService.deleteForm(form);

    forms = studyManagerService.getForms();
    Assert.assertEquals("Deleted the form, so now there is the same", numberOfForms, forms.size());
    Assert.assertNull(getForm(formName, forms));
}

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

@Test
public void deleteSettingGroup_shouldDeleteSettingGroupWithGivenName() throws Exception {
    SettingGroup settingGroup = getSettingGroup("General");
    Assert.assertNotNull(settingGroup);

    settingService.deleteSettingGroup(settingGroup);

    Assert.assertNull(getSettingGroup("General"));
}

From source file:de.hybris.platform.commerceservices.security.impl.DefaultSecureTokenServiceTest.java

@Test(expected = IllegalArgumentException.class)
public void testBlocksize() {
    final SecureToken data = new SecureToken(TEST_DATA, TEST_TS);
    final String token = service.encryptData(data);
    Assert.assertNotNull(token);
    TestUtils.disableFileAnalyzer("ACC-864");
    try {/*  w  ww.  j  av a 2s .  c om*/
        // generates a warning IllegalBlockSizeException in the log
        service.decryptData(token.substring(0, 40));
    } finally {
        TestUtils.enableFileAnalyzer();
    }
}

From source file:com.alibaba.dubbo.examples.validation.ValidationTest.java

@Test
public void testValidation() {
    ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(
            ValidationTest.class.getPackage().getName().replace('.', '/') + "/validation-provider.xml");
    providerContext.start();//from  w w w. j  av a 2 s .c o  m
    try {
        ClassPathXmlApplicationContext consumerContext = new ClassPathXmlApplicationContext(
                ValidationTest.class.getPackage().getName().replace('.', '/') + "/validation-consumer.xml");
        consumerContext.start();
        try {
            ValidationService validationService = (ValidationService) consumerContext
                    .getBean("validationService");

            // Save OK
            ValidationParameter parameter = new ValidationParameter();
            parameter.setName("liangfei");
            parameter.setEmail("liangfei@liang.fei");
            parameter.setAge(50);
            parameter.setLoginDate(new Date(System.currentTimeMillis() - 1000000));
            parameter.setExpiryDate(new Date(System.currentTimeMillis() + 1000000));
            validationService.save(parameter);

            try {
                parameter = new ValidationParameter();
                parameter.setName("l");
                parameter.setEmail("liangfei@liang.fei");
                parameter.setAge(50);
                parameter.setLoginDate(new Date(System.currentTimeMillis() - 1000000));
                parameter.setExpiryDate(new Date(System.currentTimeMillis() + 1000000));
                validationService.save(parameter);
                Assert.fail();
            } catch (RpcException e) {
                ConstraintViolationException ve = (ConstraintViolationException) e.getCause();
                Set<ConstraintViolation<?>> violations = ve.getConstraintViolations();
                Assert.assertNotNull(violations);
            }

            // Save Error
            try {
                parameter = new ValidationParameter();
                validationService.save(parameter);
                Assert.fail();
            } catch (RpcException e) {
                ConstraintViolationException ve = (ConstraintViolationException) e.getCause();
                Set<ConstraintViolation<?>> violations = ve.getConstraintViolations();
                Assert.assertNotNull(violations);
            }

            // Delete OK
            validationService.delete(2, "abc");

            // Delete Error
            try {
                validationService.delete(2, "a");
                Assert.fail();
            } catch (RpcException e) {
                ConstraintViolationException ve = (ConstraintViolationException) e.getCause();
                Set<ConstraintViolation<?>> violations = ve.getConstraintViolations();
                Assert.assertNotNull(violations);
                Assert.assertEquals(1, violations.size());
            }

            // Delete Error
            try {
                validationService.delete(0, "abc");
                Assert.fail();
            } catch (RpcException e) {
                ConstraintViolationException ve = (ConstraintViolationException) e.getCause();
                Set<ConstraintViolation<?>> violations = ve.getConstraintViolations();
                Assert.assertNotNull(violations);
                Assert.assertEquals(1, violations.size());
            }
            try {
                validationService.delete(2, null);
                Assert.fail();
            } catch (RpcException e) {
                ConstraintViolationException ve = (ConstraintViolationException) e.getCause();
                Set<ConstraintViolation<?>> violations = ve.getConstraintViolations();
                Assert.assertNotNull(violations);
                Assert.assertEquals(1, violations.size());
            }
            try {
                validationService.delete(0, null);
                Assert.fail();
            } catch (RpcException e) {
                ConstraintViolationException ve = (ConstraintViolationException) e.getCause();
                Set<ConstraintViolation<?>> violations = ve.getConstraintViolations();
                Assert.assertNotNull(violations);
                Assert.assertEquals(2, violations.size());
            }
        } finally {
            consumerContext.stop();
            consumerContext.close();
        }
    } finally {
        providerContext.stop();
        providerContext.close();
    }
}

From source file:org.jasig.schedassist.web.owner.schedule.ClearAvailableScheduleFormBackingObjectValidatorTest.java

/**
 * Test invalid weekOf value, assert 1 error.
 * //from w w w.j a  va  2  s  .c  om
 * @throws Exception
 */
@Test
@SuppressWarnings("rawtypes")
public void testInvalidWeekOf() throws Exception {
    ClearAvailableScheduleFormBackingObject fbo = new ClearAvailableScheduleFormBackingObject();
    fbo.setConfirmedCancelWeek(true);
    fbo.setWeekOfPhrase("abcdde");
    Errors errors = new BindException(fbo, "command");
    ClearAvailableScheduleFormBackingObjectValidator validator = new ClearAvailableScheduleFormBackingObjectValidator();
    validator.validate(fbo, errors);
    List fieldErrors = errors.getAllErrors();
    Assert.assertEquals(1, fieldErrors.size());
    FieldError weekOfError = errors.getFieldError("weekOfPhrase");
    Assert.assertNotNull(weekOfError);
    Assert.assertEquals("field.weekofphraseformat", weekOfError.getCode());
}

From source file:com.taobao.ad.jpa.test.RepeatAlarmTest.java

@Test
public void testInsertReapeatAlerm_update() {
    RepeatAlarmDO r = new RepeatAlarmDO();
    r.setJobGroup("11");
    r.setJobName("11");
    r.setRepeatAlarmNum(2);/*w ww.ja v  a 2 s .  c om*/
    r.setStatus(1);
    repeatAlarmBO.saveOrUpdateRepeatAlarm(r);
    System.out.println(r.getId());
    r = repeatAlarmBO.getRepeatAlarmById(r.getId());
    Assert.assertNotNull(r);
    Assert.assertEquals("11", r.getJobName());
    Assert.assertEquals("11", r.getJobGroup());
    Assert.assertEquals(1111, r.getSignTime());
    Assert.assertEquals(2, r.getRepeatAlarmNum());
    Assert.assertEquals(1, r.getStatus().intValue());
}

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

/**
 * Test save.//from  ww w .  j a v  a 2 s.c  o  m
 * 
 * @throws Exception
 *             the exception
 */
public void testSave() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    ServletActionContext.setRequest(request);
    this.action.setJournalkostenId(1L);
    this.action.setJournalId(1L);
    Assert.assertEquals("edit", this.action.edit());
    Assert.assertNotNull(this.action.getJournalkosten());

    // update Journalkosten and save
    this.action.getJournalkosten().setOPreisPO((long) 123.23);
    Assert.assertEquals("success", this.action.save());
    Assert.assertEquals((long) 123.23, (long) this.action.getJournalkosten().getOPreisPO());
    Assert.assertFalse(this.action.hasActionErrors());
    Assert.assertFalse(this.action.hasFieldErrors());
    Assert.assertNotNull(request.getSession().getAttribute("messages"));
}

From source file:de.akquinet.gomobile.androlog.test.PostReporterTest.java

public void testPost() {
    Log.init(getContext());/*from   w w w.ja v a 2  s.  c  o  m*/
    String message = "This is a INFO test";
    String tag = "my.log.info";
    Log.d(tag, message);
    Log.i(tag, message);
    Log.w(tag, message);
    List<String> list = Log.getReportedEntries();
    Assert.assertNotNull(list);
    Assert.assertFalse(list.isEmpty());
    Assert.assertEquals(2, list.size()); // i + w

    Log.report();
    Log.report("this is a user message", null);
    Exception error = new MalformedChallengeException("error message", new NumberFormatException());
    Log.report(null, error);
}

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

/**
 * Test save./* w  w w .ja v a2s . co  m*/
 * 
 * @throws Exception
 *             the exception
 */
public void testSave() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    ServletActionContext.setRequest(request);
    this.action.setInteresseId(1L);
    Assert.assertEquals("edit", this.action.edit());
    Assert.assertNotNull(this.action.getInteresseBaseTO());

    // update Name and save
    this.action.getInteresseBaseTO().setInteresse("Updated Interesse");
    Assert.assertEquals("success", this.action.save());
    Assert.assertEquals("Updated Interesse", this.action.getInteresseBaseTO().getInteresse());
    Assert.assertFalse(this.action.hasActionErrors());
    Assert.assertFalse(this.action.hasFieldErrors());
    Assert.assertNotNull(request.getSession().getAttribute("messages"));
}