Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import org.apache.tools.ant.PropertyHelper;
import org.hamcrest.core.Is;
import org.hamcrest.core.IsCollectionContaining;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import com.izforge.izpack.matcher.ZipMatcher;

Expand All @@ -22,7 +22,7 @@ public class IzPackTaskTest
{

@Test
@Ignore
@Disabled
public void testExecuteAntAction() throws IllegalAccessException, InterruptedException, IOException
{

Expand Down
11 changes: 3 additions & 8 deletions izpack-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,13 @@
<artifactId>izpack-tools</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@

package com.izforge.izpack.api.adaptator;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.izforge.izpack.api.adaptator.impl.XMLElementImpl;
import com.izforge.izpack.api.adaptator.impl.XMLParser;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.BeforeEach;

import java.io.FileNotFoundException;
import java.util.List;
Expand All @@ -44,7 +47,7 @@ public class XMLElementTest

private IXMLElement root;

@Before
@BeforeEach
public void setUp() throws FileNotFoundException
{
/* méthode DOM */
Expand All @@ -55,77 +58,74 @@ public void setUp() throws FileNotFoundException
@Test
public void testGetName()
{
Assert.assertEquals("izpack:installation", root.getName());
Assert.assertEquals(root.getChildAtIndex(0).getName(), "info");
assertEquals("izpack:installation", root.getName());
assertEquals(root.getChildAtIndex(0).getName(), "info");
}

@Test
public void testAddChild() throws NoSuchMethodException
{
public void testAddChild() {
IXMLElement element = new XMLElementImpl("child", root);
root.addChild(element);
element = root.getChildAtIndex(root.getChildrenCount() - 1);
Assert.assertEquals(element.getName(), "child");
assertEquals(element.getName(), "child");
}

@Test
public void testAddChildToDifferentDocument() throws NoSuchMethodException
{
public void testAddChildToDifferentDocument() {
IXMLElement element = new XMLElementImpl("child");
root.addChild(element);
element = root.getChildAtIndex(root.getChildrenCount() - 1);
Assert.assertEquals(element.getName(), "child");
assertEquals(element.getName(), "child");
}

@Test
public void testRemoveChild() throws NoSuchMethodException
{
public void testRemoveChild() {
IXMLElement element = new XMLElementImpl("child", root);
root.addChild(element);
element = root.getChildAtIndex(root.getChildrenCount() - 1);
root.removeChild(element);
Assert.assertEquals(root.getChildrenNamed("child").size(), 0);
assertEquals(root.getChildrenNamed("child").size(), 0);
}

@Test
public void testHasChildrenIfTrue()
{
Assert.assertTrue(root.hasChildren());
assertTrue(root.hasChildren());
}

@Test
public void testHasChildrenIfFalse()
{
IXMLElement element = new XMLElementImpl("test");
Assert.assertFalse(element.hasChildren());
assertFalse(element.hasChildren());
}

@Test
public void testGetChildrenCount()
{
IXMLElement element = root.getChildAtIndex(0);
Assert.assertEquals(element.getChildrenCount(), 9);
assertEquals(element.getChildrenCount(), 9);
}

@Test
public void testGetChildAtIndex()
{
IXMLElement element = root.getChildAtIndex(1);
Assert.assertEquals("variables", element.getName());
assertEquals("variables", element.getName());
}

@Test
public void testGetFirstChildNamed()
{
IXMLElement element = root.getFirstChildNamed("locale");
Assert.assertEquals(element.getName(), "locale");
assertEquals(element.getName(), "locale");
}

@Test
public void testGetChildrenNamed()
{
IXMLElement element = root.getChildAtIndex(2);
List<IXMLElement> list = element.getChildrenNamed("modifier");
Assert.assertEquals(7, list.size());
assertEquals(7, list.size());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

package com.izforge.izpack.api.adaptator;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.File;
import java.io.IOException;
Expand All @@ -33,8 +33,8 @@
import javax.xml.transform.TransformerException;

import org.apache.commons.io.FileUtils;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.xml.sax.SAXException;

import com.izforge.izpack.api.adaptator.impl.XMLParser;
Expand Down Expand Up @@ -65,7 +65,7 @@ public void testParseFile() throws Exception

IXMLParser parser = new XMLParser();
spec = parser.parse(input);
Assert.assertEquals("izpack:shortcuts", spec.getName());
Assertions.assertEquals("izpack:shortcuts", spec.getName());
}

@Test
Expand All @@ -76,7 +76,7 @@ public void testParseString() throws Exception
new File(XMLParserTest.class.getResource(filename).toURI()));
IXMLParser parser = new XMLParser(false);
spec = parser.parse(substitutedSpec);
Assert.assertEquals("izpack:shortcuts", spec.getName());
Assertions.assertEquals("izpack:shortcuts", spec.getName());
}

private void checkEltLN(IXMLElement elt)
Expand Down Expand Up @@ -112,34 +112,42 @@ public void testXincludeLineNumber()
checkEltLN(elt);
}

@Test(expected = XMLException.class)
@Test
public void testXMLExceptionThrown()
{
InputStream input = XMLParserTest.class.getResourceAsStream(parseErrorFilename);
IXMLParser parser = new XMLParser();
parser.parse(input, parseErrorFilename);
Assertions.assertThrows(XMLException.class, () -> {
InputStream input = XMLParserTest.class.getResourceAsStream(parseErrorFilename);
IXMLParser parser = new XMLParser();
parser.parse(input, parseErrorFilename);
});
}

@Test(expected = XMLException.class)
@Test
public void testXMLExceptionThrownXInclude()
{
InputStream input = XMLParserTest.class.getResourceAsStream(parseErrorXincludeFilename);
IXMLParser parser = new XMLParser();
parser.parse(input, parseErrorXincludeFilename);
Assertions.assertThrows(XMLException.class, () -> {
InputStream input = XMLParserTest.class.getResourceAsStream(parseErrorXincludeFilename);
IXMLParser parser = new XMLParser();
parser.parse(input, parseErrorXincludeFilename);
});
}

@Test(expected = NullPointerException.class)
@Test
public void testNPE()
{
IXMLParser parser = new XMLParser();
parser.parse((InputStream) null);
Assertions.assertThrows(NullPointerException.class, () -> {
IXMLParser parser = new XMLParser();
parser.parse((InputStream) null);
});
}

@Test(expected = NullPointerException.class)
@Test
public void testWithSystemIdNPE()
{
IXMLParser parser = new XMLParser();
parser.parse(null, "bla");
Assertions.assertThrows(NullPointerException.class, () -> {
IXMLParser parser = new XMLParser();
parser.parse(null, "bla");
});
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@

package com.izforge.izpack.api.adaptator;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import com.izforge.izpack.api.adaptator.impl.XMLElementImpl;
import com.izforge.izpack.api.adaptator.impl.XMLParser;
import com.izforge.izpack.api.adaptator.impl.XMLWriter;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import java.io.*;
import java.nio.file.Path;

/**
* Test the writer implementation
Expand All @@ -46,10 +48,11 @@ public class XMLWriterTest
private IXMLParser parser;
private IXMLElement root;

@Rule
public TemporaryFolder tempFolder = new TemporaryFolder();

@Before
@TempDir
static Path tempDir;

@BeforeEach
public void setUp() throws FileNotFoundException
{
parser = new XMLParser();
Expand All @@ -65,41 +68,43 @@ public void setUp() throws FileNotFoundException
public void testWriteFile() throws IOException
{
IXMLWriter writer = new XMLWriter();
File file = tempFolder.newFile(output);
File file = tempDir.resolve(output).toFile();
FileOutputStream out = new FileOutputStream(file);
writer.setOutput(out);
writer.write(root);
root = parser.parse(XMLWriterTest.class.getResourceAsStream(filename));
IXMLElement element = parser.parse(new FileInputStream(file));
Assert.assertEquals(root.getName(), element.getName());
assertEquals(root.getName(), element.getName());
}


/**
* Try to write a file with an Url to a resource
*
* @throws java.io.IOException
* @throws IOException
*/
@Test
public void testWriteURL() throws IOException
{
IXMLWriter writer = new XMLWriter();
File file = tempFolder.newFile(output);
File file = tempDir.resolve(output).toFile();
FileOutputStream out = new FileOutputStream(file);
writer.setOutput(out);
writer.write(root);
root = parser.parse(XMLWriterTest.class.getResourceAsStream(filename));
IXMLElement element = parser.parse(new FileInputStream(file));
Assert.assertEquals(root.getName(), element.getName());
assertEquals(root.getName(), element.getName());
}

@Test(expected = XMLException.class)
@Test
public void testFail()
{
// TODO : don't use XMLElementImpl !
IXMLElement elt = new XMLElementImpl("root");
IXMLWriter writer = new XMLWriter();
writer.setOutput(""); // will take the current directory, which is not a file !
writer.write(elt);
assertThrows(XMLException.class, () -> {
// TODO : don't use XMLElementImpl !
IXMLElement elt = new XMLElementImpl("root");
IXMLWriter writer = new XMLWriter();
writer.setOutput(""); // will take the current directory, which is not a file !
writer.write(elt);
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@

package com.izforge.izpack.api.adaptator.xinclude;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.fail;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.text.IsEqualIgnoringWhiteSpace.equalToIgnoringWhiteSpace;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

import java.net.URL;
import java.util.List;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import com.izforge.izpack.api.adaptator.IXMLElement;
import com.izforge.izpack.api.adaptator.IXMLParser;
Expand Down Expand Up @@ -77,15 +77,14 @@ public void ensureFailure(String fileBase) throws Exception
public void deepEqual(IXMLElement a, IXMLElement b)
{

assertEquals("element names ", a.getName(), b.getName());
assertEquals(a.getName(), b.getName(), "element names ");
// assertEquals("element attributes for " + a.getName(),
// a.getAttributes(), b.getAttributes());
if (null != b.getContent() && null != a.getContent())
{
assertThat(a.getContent(), equalToIgnoringWhiteSpace(b.getContent()));
}
assertEquals("equal number of children " + a.getName(),
a.getChildrenCount(), b.getChildrenCount());
assertEquals(a.getChildrenCount(), b.getChildrenCount(), "equal number of children " + a.getName());

List<IXMLElement> aChildren = a.getChildren();
List<IXMLElement> bChildren = b.getChildren();
Expand Down
Loading