-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from lyncodev/master
Adding some test coverage
- Loading branch information
Showing
11 changed files
with
174 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 0 additions & 11 deletions
11
src/main/java/org/jtwig/xliff/exceptions/XliffException.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/test/java/org/jtwig/xliff/i18n/XliffMessageSourceFactoryBuilderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.jtwig.xliff.i18n; | ||
|
||
import org.jtwig.environment.EnvironmentConfigurationBuilder; | ||
import org.jtwig.environment.EnvironmentFactory; | ||
import org.jtwig.translate.message.source.MessageSource; | ||
import org.jtwig.translate.message.source.factory.MessageSourceFactory; | ||
import org.junit.Test; | ||
|
||
import static org.hamcrest.core.IsNull.notNullValue; | ||
import static org.junit.Assert.assertThat; | ||
|
||
public class XliffMessageSourceFactoryBuilderTest { | ||
@Test | ||
public void builder() throws Exception { | ||
MessageSourceFactory factory = new XliffMessageSourceFactoryBuilder(XmlFileFilter.xmlFileFilter()) | ||
.withLookupClasspath("test") | ||
.withLookupClasspathRecursively("test") | ||
.withLookupDirectory("test") | ||
.withLookupDirectoryRecursively("test") | ||
.build(); | ||
|
||
MessageSource result = factory.create(new EnvironmentFactory().create(EnvironmentConfigurationBuilder.configuration().build())); | ||
|
||
assertThat(result, notNullValue()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.jtwig.xliff.parser; | ||
|
||
import com.google.common.base.Optional; | ||
import org.jtwig.xliff.exceptions.XliffParsingException; | ||
import org.jtwig.xliff.parser.xml.XmlReader; | ||
import org.jtwig.xliff.parser.xml.XmlReaderFactory; | ||
import org.jtwig.xliff.parser.xml.XmlStartElement; | ||
import org.jtwig.xliff.parser.xml.exceptions.XmlReaderException; | ||
import org.junit.Test; | ||
|
||
import java.io.ByteArrayInputStream; | ||
|
||
import static org.mockito.BDDMockito.given; | ||
import static org.mockito.Mockito.mock; | ||
|
||
public class XliffParserTest { | ||
private final XmlReaderFactory xmlReaderFactory = mock(XmlReaderFactory.class); | ||
private final TranslationFileParser translationFileParser = mock(TranslationFileParser.class); | ||
private XliffParser underTest = new XliffParser(xmlReaderFactory, translationFileParser); | ||
|
||
@Test(expected = XliffParsingException.class) | ||
public void readerException() throws Exception { | ||
ByteArrayInputStream inputStream = new ByteArrayInputStream("test".getBytes()); | ||
|
||
given(xmlReaderFactory.create(inputStream)).willThrow(new XmlReaderException("test")); | ||
|
||
underTest.parse(inputStream); | ||
} | ||
|
||
@Test(expected = XliffParsingException.class) | ||
public void noStart() throws Exception { | ||
ByteArrayInputStream inputStream = new ByteArrayInputStream("test".getBytes()); | ||
XmlReader reader = mock(XmlReader.class); | ||
|
||
given(xmlReaderFactory.create(inputStream)).willReturn(reader); | ||
given(reader.nextStartElement("file")).willReturn(Optional.<XmlStartElement>absent()); | ||
|
||
underTest.parse(inputStream); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/test/java/org/jtwig/xliff/parser/xml/XmlReaderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.jtwig.xliff.parser.xml; | ||
|
||
import org.jtwig.xliff.parser.xml.exceptions.XmlReaderException; | ||
import org.junit.Test; | ||
|
||
import javax.xml.stream.XMLEventReader; | ||
import javax.xml.stream.XMLStreamException; | ||
|
||
import static org.mockito.BDDMockito.given; | ||
import static org.mockito.Mockito.mock; | ||
|
||
public class XmlReaderTest { | ||
private final XmlStartElementFactory xmlStartElementFactory = mock(XmlStartElementFactory.class); | ||
private final XmlReaderEventFactory xmlReaderEventFactory = mock(XmlReaderEventFactory.class); | ||
private final XMLEventReader xmlEventReader = mock(XMLEventReader.class); | ||
|
||
private XmlReader underTest = new XmlReader( | ||
xmlStartElementFactory, | ||
xmlReaderEventFactory, | ||
xmlEventReader | ||
); | ||
|
||
@Test(expected = XmlReaderException.class) | ||
public void next() throws Exception { | ||
given(xmlEventReader.hasNext()).willReturn(true); | ||
given(xmlEventReader.nextEvent()).willThrow(new XMLStreamException()); | ||
|
||
underTest.nextStartElement("test"); | ||
} | ||
|
||
@Test(expected = XmlReaderException.class) | ||
public void text() throws Exception { | ||
given(xmlEventReader.hasNext()).willReturn(true); | ||
given(xmlEventReader.nextEvent()).willThrow(new XMLStreamException()); | ||
|
||
underTest.textInsideCurrentElement(); | ||
} | ||
|
||
@Test(expected = XmlReaderException.class) | ||
public void current() throws Exception { | ||
XmlReaderEvent result = underTest.currentEvent(); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/test/java/org/jtwig/xliff/parser/xml/XmlStartElementTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.jtwig.xliff.parser.xml; | ||
|
||
import com.google.common.base.Optional; | ||
import org.junit.Test; | ||
|
||
import javax.xml.stream.events.Attribute; | ||
import javax.xml.stream.events.StartElement; | ||
|
||
import static java.util.Arrays.asList; | ||
import static org.hamcrest.core.Is.is; | ||
import static org.junit.Assert.assertThat; | ||
import static org.mockito.BDDMockito.given; | ||
import static org.mockito.Mockito.mock; | ||
|
||
public class XmlStartElementTest { | ||
XmlAttributeFactory xmlAttributeFactory = mock(XmlAttributeFactory.class); | ||
StartElement startElement = mock(StartElement.class); | ||
|
||
XmlStartElement underTest = new XmlStartElement(xmlAttributeFactory, startElement); | ||
|
||
@Test | ||
public void xmlStartNoAttributes() throws Exception { | ||
given(startElement.getAttributes()).willReturn(asList().iterator()); | ||
|
||
Optional<XmlAttribute> result = underTest.getAttribute("test"); | ||
|
||
assertThat(result.isPresent(), is(false)); | ||
} | ||
@Test | ||
public void xmlStartNullNameAttribute() throws Exception { | ||
Attribute attribute = mock(Attribute.class); | ||
given(startElement.getAttributes()).willReturn(asList(attribute).iterator()); | ||
given(attribute.getName()).willReturn(null); | ||
|
||
Optional<XmlAttribute> result = underTest.getAttribute("test"); | ||
|
||
assertThat(result.isPresent(), is(false)); | ||
} | ||
} |