Add some tests to the OsisParser

Testing state machines can be difficult if it's not black box...
This commit is contained in:
Bradlee Speice
2014-11-11 00:33:51 -05:00
parent 6a45d872f8
commit c57babd68a
3 changed files with 63 additions and 16 deletions

View File

@ -0,0 +1,51 @@
package org.bspeice.minimalbible.test.format.osisparser;
import android.annotation.SuppressLint;
import org.bspeice.minimalbible.MBTestCase;
import org.bspeice.minimalbible.service.format.osisparser.OsisParser;
import org.crosswire.jsword.book.OSISUtil;
import org.xml.sax.Attributes;
import static org.mockito.Mockito.mock;
/**
* State machine testing, oh boy!
*/
public class OsisParserTest extends MBTestCase {
OsisParser parser;
public void setUp() {
parser = new OsisParser(null);
}
@SuppressLint("NewApi")
public void testDoWriteEnabledVerse() {
Attributes attributes = mock(Attributes.class);
parser.startElement("", OSISUtil.OSIS_ELEMENT_VERSE, "", attributes);
assertTrue(parser.getDoWrite().peek());
}
@SuppressLint("NewApi")
private void parserAssert(OsisParser parser, String element) {
Attributes attributes = mock(Attributes.class);
parser.startElement("", element, "", attributes);
assertFalse(parser.getDoWrite().isEmpty());
parser.getDoWrite().pop();
}
public void testDoWriteAlwaysAdded() {
parserAssert(parser, OSISUtil.OSIS_ELEMENT_VERSE);
parserAssert(parser, "");
parserAssert(parser, "random string");
parserAssert(parser, OSISUtil.OSIS_ELEMENT_CELL);
}
@SuppressLint("NewApi")
public void testEndElementPopsQueue() {
parser.getDoWrite().add(true);
parser.endElement("", "", "");
assertTrue(parser.getDoWrite().isEmpty());
}
}