Fixed unit tests.

This commit is contained in:
Christian P. MOMON 2016-09-08 03:33:31 +02:00
parent faabbe42be
commit c29b1df967
4 changed files with 81 additions and 90 deletions

View file

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2006-2014 Christian Pierre MOMON * Copyright (C) 2006-2016 Christian Pierre MOMON
* *
* This file is part of Xidyn. * This file is part of Xidyn.
* *
@ -22,7 +22,7 @@ import org.slf4j.LoggerFactory;
import fr.devinsy.xidyn.data.SimpleTagData; import fr.devinsy.xidyn.data.SimpleTagData;
import fr.devinsy.xidyn.data.TagDataManager; import fr.devinsy.xidyn.data.TagDataManager;
import fr.devinsy.xidyn.presenters.StringPresenter; import fr.devinsy.xidyn.presenters.PresenterUtils;
/** /**
* *
@ -45,7 +45,7 @@ class XidynTest
DECEMBRE DECEMBRE
} }
static private Logger logger = LoggerFactory.getLogger(XidynTest.class); private static Logger logger = LoggerFactory.getLogger(XidynTest.class);
static static
{ {
// Initialize logger. // Initialize logger.
@ -93,7 +93,7 @@ class XidynTest
datas.setContent("name", "Superman"); datas.setContent("name", "Superman");
try try
{ {
html = StringPresenter.dynamize("<div id='name'>a name</div >", datas); html = PresenterUtils.dynamize("<div id='name'>a name</div >", datas);
} }
catch (Exception exception) catch (Exception exception)
{ {
@ -113,7 +113,7 @@ class XidynTest
try try
{ {
html = StringPresenter.dynamize("<div id='lastname'>a last name</div >", datas); html = PresenterUtils.dynamize("<div id='lastname'>a last name</div >", datas);
} }
catch (Exception exception) catch (Exception exception)
{ {
@ -134,7 +134,7 @@ class XidynTest
try try
{ {
html = StringPresenter.dynamize("<ul>\n <li id='words'>a word</li>\n</ul>", datas); html = PresenterUtils.dynamize("<ul>\n <li id='words'>a word</li>\n</ul>", datas);
} }
catch (Exception exception) catch (Exception exception)
{ {
@ -166,7 +166,7 @@ class XidynTest
htmlSource = source.toString(); htmlSource = source.toString();
try try
{ {
html = StringPresenter.dynamize(htmlSource, datas); html = PresenterUtils.dynamize(htmlSource, datas);
} }
catch (Exception exception) catch (Exception exception)
{ {

View file

@ -0,0 +1,70 @@
/**
* Copyright (C) 2016 Christian Pierre MOMON
*
* This file is part of Xidyn.
*
* Xidyn is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Xidyn is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Xidyn. If not, see <http://www.gnu.org/licenses/>
*/
package fr.devinsy.xidyn.pages;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.fest.assertions.Assertions;
import org.junit.Before;
import org.junit.Test;
/**
*
*/
public class PageFactoryTest
{
/**
*
*/
@Before
public void before()
{
BasicConfigurator.configure();
Logger.getRootLogger().setLevel(Level.ERROR);
}
/**
* @throws Exception
*
*/
@Test(expected = IllegalArgumentException.class)
public void testPage01() throws Exception
{
String source = null;
String target = PageFactory.instance().get(source).dynamize().toString();
Assertions.assertThat(target).isEqualTo(source);
}
/**
* @throws Exception
*
*/
@Test
public void testPage02() throws Exception
{
String source = "aaaaa<div>hello</div>zzzzz";
String target = PageFactory.instance().get(source).dynamize().toString();
Assertions.assertThat(target).isEqualTo(source);
}
}

View file

@ -25,8 +25,6 @@ import org.fest.assertions.Assertions;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import fr.devinsy.xidyn.data.TagDataManager;
import fr.devinsy.xidyn.presenters.PresenterUtils;
import fr.devinsy.xidyn.presenters.StringPresenter; import fr.devinsy.xidyn.presenters.StringPresenter;
/** /**
@ -49,89 +47,12 @@ public class PageTest
* *
*/ */
@Test @Test
public void testDynamize01() throws Exception public void testPage01() throws Exception
{ {
String source = "aaaaa<body>hello</body>zzzzz"; String source = "aaaaa<div>hello</div>zzzzz";
String target = new Page(new StringPresenter(source)).dynamize().toString(); String target = new Page(new StringPresenter(source)).dynamize().toString();
Assertions.assertThat(target).isEqualTo(source); Assertions.assertThat(target).isEqualTo(source);
target = new Page(new StringPresenter(source)).lastVersion().toString();
Assertions.assertThat(target).isEqualTo(source);
} }
/**
* @throws Exception
*
*/
@Test
public void testDynamize02() throws Exception
{
String source = "aaaaa<body>hello</body>zzzzz";
String target = new StringPresenter(source).dynamize(null).toString();
Assertions.assertThat(target).isEqualTo(source);
}
/**
* @throws Exception
*
*/
@Test
public void testDynamize03() throws Exception
{
String source = "aaaaa<div>hello</div>zzzzz";
String target = new StringPresenter(source).dynamize(new TagDataManager()).toString();
Assertions.assertThat(target).isEqualTo(source);
}
/**
* @throws Exception
*
*/
@Test
public void testPage02() throws Exception
{
String source = "aaaaa<div>hello</div>zzzzz";
Page page = PageFactory.instance().get(source);
String target = page.dynamize().toString();
Assertions.assertThat(target).isEqualTo(source);
}
/**
* @throws Exception
*
*/
@Test
public void testStaticDynamize01() throws Exception
{
String source = "aaaaa<div>hello</div>zzzzz";
String target = PresenterUtils.dynamize(source, null).toString();
Assertions.assertThat(target).isEqualTo(source);
}
/**
* @throws Exception
*
*/
@Test
public void testStaticDynamize02() throws Exception
{
String source = "aaaaa<div>hello</div>zzzzz";
String target = PresenterUtils.dynamize(source, new TagDataManager()).toString();
Assertions.assertThat(target).isEqualTo(source);
}
} }

View file

@ -49,7 +49,7 @@ public class StringPresenterTest
@Test @Test
public void testDynamize01() throws Exception public void testDynamize01() throws Exception
{ {
String source = "aaaaa<body>hello</body>zzzzz"; String source = "aaaaa<div>hello</div>zzzzz";
String target = new StringPresenter(source).dynamize().toString(); String target = new StringPresenter(source).dynamize().toString();
@ -63,7 +63,7 @@ public class StringPresenterTest
@Test @Test
public void testDynamize02() throws Exception public void testDynamize02() throws Exception
{ {
String source = "aaaaa<body>hello</body>zzzzz"; String source = "aaaaa<div>hello</div>zzzzz";
String target = new StringPresenter(source).dynamize(null).toString(); String target = new StringPresenter(source).dynamize(null).toString();