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.soybeanMilk.test.unit.core.TestDefaultExecutor.java

@Test
public void execute_executionNotCreatedIfExecutionKeyIsNull() throws Exception {
    executor.getConfiguration().getInterceptor().setExecutionKey(null);

    HashMapObjectSource os = new HashMapObjectSource();

    executor.execute(KEY_EXE_HELLO, os);

    Assert.assertNull(os.get(KEY_EXECUTION));
}

From source file:org.soybeanMilk.test.unit.core.TestDefaultExecutor.java

@Test
public void execute_beforeInterceptorIsNull() throws Exception {
    executor.getConfiguration().getInterceptor().setBefore(null);

    HashMapObjectSource os = new HashMapObjectSource();

    executor.execute(KEY_EXE_HELLO, os);

    Assert.assertNull(os.get(ResolverForTest.beforeResultKey));
}

From source file:org.soybeanMilk.test.unit.core.TestDefaultExecutor.java

@Test
public void execute_afterInterceptorIsNull() throws Exception {
    executor.getConfiguration().getInterceptor().setAfter(null);

    HashMapObjectSource os = new HashMapObjectSource();

    executor.execute(KEY_EXE_HELLO, os);

    Assert.assertNull(os.get(ResolverForTest.afterResultKey));
}

From source file:org.soybeanMilk.test.unit.core.TestDefaultExecutor.java

@Test
public void execute_exceptionInterceptorIsNull() throws Exception {
    executor.getConfiguration().getInterceptor().setException(null);

    HashMapObjectSource os = new HashMapObjectSource();

    try {//from   www  .j  a v  a 2s . co m
        executor.execute("helloThrow", os);
    } catch (InvocationExecuteException e) {
    }

    Assert.assertNull(os.get(ResolverForTest.exceptionResultKey));
}

From source file:org.soybeanMilk.test.unit.core.TestInvoke.java

@Test
public void execute_breakerValueIsTrue() throws Exception {
    //breakertrue
    {/*w w w. ja v  a2 s  . c o  m*/
        ObjectSource objSource = new HashMapObjectSource();
        objSource.set("breakerKey", true);
        executor.execute("testBreaker_1", objSource);

        Assert.assertNull(objSource.get(RESULT_KEY));
    }
}

From source file:org.soybeanMilk.test.unit.core.TestInvoke.java

@Test
public void execute_breakerIsLiteralTrue() throws Exception {
    ObjectSource objSource = new HashMapObjectSource();
    executor.execute("testBreaker_2", objSource);

    Assert.assertNull(objSource.get(RESULT_KEY));
}

From source file:org.xwiki.configuration.internal.CompositeConfigurationSourceTest.java

@Test
public void testGetProperty() {
    config1.setProperty("key1", "value1");
    config1.setProperty("key3", "value3");
    config2.setProperty("key2", "value2");
    config2.setProperty("key3", "value3");

    Assert.assertEquals("value1", composite.getProperty("key1"));
    Assert.assertEquals("value2", composite.getProperty("key2"));
    Assert.assertEquals("value3", composite.getProperty("key3"));
    Assert.assertNull(composite.getProperty("unknown"));
}

From source file:org.xwiki.configuration.internal.CompositeConfigurationSourceTest.java

@Test
public void testGetPropertyWithClass() {
    config1.setProperty("key1", "value1");
    config1.setProperty("key3", "value3");
    config2.setProperty("key2", "value2");
    config2.setProperty("key3", "value3");

    Assert.assertEquals("value1", composite.getProperty("key1", String.class));
    Assert.assertEquals("value2", composite.getProperty("key2", String.class));
    Assert.assertEquals("value3", composite.getProperty("key3", String.class));
    Assert.assertNull(composite.getProperty("unknown", String.class));
}

From source file:org.xwiki.extension.xar.XarExtensionHandlerTest.java

@Test
public void testInstallOnWiki() throws Throwable {
    getMockery().checking(new Expectations() {
        {/*from w ww. j  a  va 2  s.  com*/
            oneOf(mockRightService).hasAccessLevel(with(equal("admin")),
                    with(equal("xwiki:XWiki.ExtensionUser")), with(equal("XWiki.XWikiPreferences")),
                    with(any(XWikiContext.class)));
            will(returnValue(true));
        }
    });

    XWikiDocument existingDocument = new XWikiDocument(new DocumentReference("wiki", "space", "page"));
    BaseObject object = new BaseObject();
    object.setXClassReference(new DocumentReference("wiki", "space", "class"));
    existingDocument.addXObject(object);
    existingDocument.setCreatorReference(new DocumentReference("wiki", "space", "existingcreator"));
    this.mockXWiki.saveDocument(existingDocument, "", true, getContext());

    // install

    install(this.localXarExtensiontId1, "wiki", this.contextUser);

    // validate

    // space.page
    XWikiDocument page = this.mockXWiki.getDocument(existingDocument.getDocumentReference(), getContext());

    Assert.assertFalse("Document wiki:space.page has not been saved in the database", page.isNew());

    Assert.assertNull(page.getXObject(object.getXClassReference()));

    Assert.assertEquals("Wrong content", "content", page.getContent());
    Assert.assertEquals("Wrong creator", new DocumentReference("wiki", "space", "existingcreator"),
            page.getCreatorReference());
    Assert.assertEquals("Wrong author", this.contextUser, page.getAuthorReference());
    Assert.assertEquals("Wrong content author", this.contextUser, page.getContentAuthorReference());
    Assert.assertEquals("Wrong version", "2.1", page.getVersion());
    Assert.assertFalse("Document is hidden", page.isHidden());

    BaseClass baseClass = page.getXClass();
    Assert.assertNotNull(baseClass.getField("property"));
    Assert.assertEquals("property", baseClass.getField("property").getName());
    Assert.assertSame(NumberClass.class, baseClass.getField("property").getClass());

    // space.pagewithattachment

    XWikiDocument pagewithattachment = this.mockXWiki
            .getDocument(new DocumentReference("wiki", "space", "pagewithattachment"), getContext());
    Assert.assertFalse(pagewithattachment.isNew());
    Assert.assertEquals("Wrong version", "2.1", pagewithattachment.getVersion());
    Assert.assertEquals("Wrong creator", this.contextUser, pagewithattachment.getCreatorReference());
    Assert.assertEquals("Wrong author", this.contextUser, pagewithattachment.getAuthorReference());
    Assert.assertEquals("Wrong content author", this.contextUser,
            pagewithattachment.getContentAuthorReference());

    XWikiAttachment attachment = pagewithattachment.getAttachment("attachment.txt");
    Assert.assertNotNull(attachment);
    Assert.assertEquals("attachment.txt", attachment.getFilename());
    Assert.assertEquals(18, attachment.getContentSize(getContext()));
    Assert.assertEquals("attachment content", IOUtils.toString(attachment.getContentInputStream(getContext())));
    Assert.assertEquals("xwiki:XWiki.ExtensionUser", attachment.getAuthor());

    // space1.page1

    XWikiDocument page1 = this.mockXWiki.getDocument(new DocumentReference("wiki", "space1", "page1"),
            getContext());

    Assert.assertFalse("Document wiki:space1.page1 has not been saved in the database", page1.isNew());

    // translated.translated
    DocumentReference translatedReference = new DocumentReference("wiki", "translated", "translated");
    XWikiDocument defaultTranslated = this.mockXWiki.getDocument(translatedReference, getContext());

    Assert.assertNotNull("Document wiki:translated.translated has not been saved in the database",
            defaultTranslated);
    Assert.assertFalse("Document wiki:translated.translated has not been saved in the database",
            defaultTranslated.isNew());

    Assert.assertEquals("Wrong content", "default content", defaultTranslated.getContent());
    Assert.assertEquals("Wrong creator", this.contextUser, defaultTranslated.getCreatorReference());
    Assert.assertEquals("Wrong author", this.contextUser, defaultTranslated.getAuthorReference());
    Assert.assertEquals("Wrong content author", this.contextUser,
            defaultTranslated.getContentAuthorReference());
    Assert.assertEquals("Wrong version", "1.1", defaultTranslated.getVersion());

    // translated.translated.tr
    XWikiDocument translated = this.documents.get(translatedReference).get("tr");

    Assert.assertNotNull(
            "Document wiki:translated.translated in langauge tr has not been saved in the database",
            translated);
    Assert.assertFalse("Document wiki:translated.translated in langauge tr has not been saved in the database",
            translated.isNew());

    Assert.assertEquals("Wrong content", "tr content", translated.getContent());
    Assert.assertEquals("Wrong creator", this.contextUser, translated.getCreatorReference());
    Assert.assertEquals("Wrong author", this.contextUser, translated.getAuthorReference());
    Assert.assertEquals("Wrong content author", this.contextUser, translated.getContentAuthorReference());
    Assert.assertEquals("Wrong version", "1.1", translated.getVersion());

    // translated.translated.fr
    XWikiDocument translated2 = this.documents.get(translatedReference).get("fr");

    Assert.assertNotNull(
            "Document wiki:translated.translated in language fr has not been saved in the database",
            translated2);
    Assert.assertFalse("Document wiki:translated.translated in langauge fr has not been saved in the database",
            translated2.isNew());

    Assert.assertEquals("Wrong content", "fr content", translated2.getContent());
    Assert.assertEquals("Wrong creator", this.contextUser, translated2.getCreatorReference());
    Assert.assertEquals("Wrong author", this.contextUser, translated2.getAuthorReference());
    Assert.assertEquals("Wrong content author", this.contextUser, translated2.getContentAuthorReference());
    Assert.assertEquals("Wrong version", "1.1", translated2.getVersion());

    // space.hiddenpage

    XWikiDocument hiddenpage = this.mockXWiki.getDocument(new DocumentReference("wiki", "space", "hiddenpage"),
            getContext());

    Assert.assertNotNull("Document wiki:space.hiddenpage has not been saved in the database", hiddenpage);
    Assert.assertFalse("Document wiki:space.hiddenpage has not been saved in the database", hiddenpage.isNew());

    Assert.assertTrue("Document is not hidden", hiddenpage.isHidden());
}

From source file:org.xwiki.extension.xar.XarExtensionHandlerTest.java

@Test
public void testInstallOnWikiWithoutAuthor() throws Throwable {
    XWikiDocument existingDocument = new XWikiDocument(new DocumentReference("wiki", "space", "page"));
    BaseObject object = new BaseObject();
    object.setXClassReference(new DocumentReference("wiki", "space", "class"));
    existingDocument.addXObject(object);
    existingDocument.setCreatorReference(new DocumentReference("wiki", "space", "existingcreator"));
    this.mockXWiki.saveDocument(existingDocument, "", true, getContext());

    // install/*  w  w w . ja  v a  2 s  .com*/

    install(this.localXarExtensiontId1, "wiki", null);

    // validate

    DocumentReference xarAuthorReference = new DocumentReference("wiki", "XWiki", "author");
    DocumentReference xarCreatorReference = new DocumentReference("wiki", "XWiki", "creator");
    DocumentReference xarContentAuthorReference = new DocumentReference("wiki", "XWiki", "contentAuthor");

    // space.page
    XWikiDocument page = this.mockXWiki.getDocument(existingDocument.getDocumentReference(), getContext());

    Assert.assertFalse("Document wiki:space.page has not been saved in the database", page.isNew());

    Assert.assertNull(page.getXObject(object.getXClassReference()));

    Assert.assertEquals("Wrong content", "content", page.getContent());
    Assert.assertEquals("Wrong creator", new DocumentReference("wiki", "space", "existingcreator"),
            page.getCreatorReference());
    Assert.assertEquals("Wrong author", xarAuthorReference, page.getAuthorReference());
    Assert.assertEquals("Wrong content author", xarContentAuthorReference, page.getContentAuthorReference());
    Assert.assertEquals("Wrong version", "2.1", page.getVersion());
    Assert.assertFalse("Document is hidden", page.isHidden());

    BaseClass baseClass = page.getXClass();
    Assert.assertNotNull(baseClass.getField("property"));
    Assert.assertEquals("property", baseClass.getField("property").getName());
    Assert.assertSame(NumberClass.class, baseClass.getField("property").getClass());

    // space.pagewithattachment

    XWikiDocument pagewithattachment = this.mockXWiki
            .getDocument(new DocumentReference("wiki", "space", "pagewithattachment"), getContext());
    Assert.assertFalse(pagewithattachment.isNew());
    Assert.assertEquals("Wrong version", "2.1", pagewithattachment.getVersion());
    Assert.assertEquals("Wrong creator", xarCreatorReference, pagewithattachment.getCreatorReference());
    Assert.assertEquals("Wrong author", xarAuthorReference, pagewithattachment.getAuthorReference());
    Assert.assertEquals("Wrong content author", xarContentAuthorReference,
            pagewithattachment.getContentAuthorReference());

    XWikiAttachment attachment = pagewithattachment.getAttachment("attachment.txt");
    Assert.assertNotNull(attachment);
    Assert.assertEquals("attachment.txt", attachment.getFilename());
    Assert.assertEquals(18, attachment.getContentSize(getContext()));
    Assert.assertEquals("attachment content", IOUtils.toString(attachment.getContentInputStream(getContext())));
    Assert.assertEquals("XWiki.attachmentauthor", attachment.getAuthor());

    // space1.page1

    XWikiDocument page1 = this.mockXWiki.getDocument(new DocumentReference("wiki", "space1", "page1"),
            getContext());

    Assert.assertFalse("Document wiki:space1.page1 has not been saved in the database", page1.isNew());

    // translated.translated
    DocumentReference translatedReference = new DocumentReference("wiki", "translated", "translated");
    XWikiDocument defaultTranslated = this.mockXWiki.getDocument(translatedReference, getContext());

    Assert.assertNotNull("Document wiki:translated.translated has not been saved in the database",
            defaultTranslated);
    Assert.assertFalse("Document wiki:translated.translated has not been saved in the database",
            defaultTranslated.isNew());

    Assert.assertEquals("Wrong content", "default content", defaultTranslated.getContent());
    Assert.assertEquals("Wrong creator", xarCreatorReference, defaultTranslated.getCreatorReference());
    Assert.assertEquals("Wrong author", xarAuthorReference, defaultTranslated.getAuthorReference());
    Assert.assertEquals("Wrong content author", xarContentAuthorReference,
            defaultTranslated.getContentAuthorReference());
    Assert.assertEquals("Wrong version", "1.1", defaultTranslated.getVersion());

    // translated.translated.tr
    XWikiDocument translated = this.documents.get(translatedReference).get("tr");

    Assert.assertNotNull(
            "Document wiki:translated.translated in langauge tr has not been saved in the database",
            translated);
    Assert.assertFalse("Document wiki:translated.translated in langauge tr has not been saved in the database",
            translated.isNew());

    Assert.assertEquals("Wrong content", "tr content", translated.getContent());
    Assert.assertEquals("Wrong creator", xarCreatorReference, translated.getCreatorReference());
    Assert.assertEquals("Wrong author", xarAuthorReference, translated.getAuthorReference());
    Assert.assertEquals("Wrong content author", xarContentAuthorReference,
            translated.getContentAuthorReference());
    Assert.assertEquals("Wrong version", "1.1", translated.getVersion());

    // translated.translated.fr
    XWikiDocument translated2 = this.documents.get(translatedReference).get("fr");

    Assert.assertNotNull(
            "Document wiki:translated.translated in language fr has not been saved in the database",
            translated2);
    Assert.assertFalse("Document wiki:translated.translated in langauge fr has not been saved in the database",
            translated2.isNew());

    Assert.assertEquals("Wrong content", "fr content", translated2.getContent());
    Assert.assertEquals("Wrong creator", xarCreatorReference, translated2.getCreatorReference());
    Assert.assertEquals("Wrong author", xarAuthorReference, translated2.getAuthorReference());
    Assert.assertEquals("Wrong content author", xarContentAuthorReference,
            translated2.getContentAuthorReference());
    Assert.assertEquals("Wrong version", "1.1", translated2.getVersion());

    // space.hiddenpage

    XWikiDocument hiddenpage = this.mockXWiki.getDocument(new DocumentReference("wiki", "space", "hiddenpage"),
            getContext());

    Assert.assertNotNull("Document wiki:space.hiddenpage has not been saved in the database", hiddenpage);
    Assert.assertFalse("Document wiki:space.hiddenpage has not been saved in the database", hiddenpage.isNew());

    Assert.assertTrue("Document is not hidden", hiddenpage.isHidden());
}