Skip to content

Instantly share code, notes, and snippets.

@simonetripodi
Last active December 14, 2015 01:28
Show Gist options
  • Save simonetripodi/5006064 to your computer and use it in GitHub Desktop.
Save simonetripodi/5006064 to your computer and use it in GitHub Desktop.
package org.apache.commons.digester3;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.StringReader;
import org.junit.Before;
import org.junit.Test;
public class LiannaTestCase
{
private Digester d;
@Before
public void setUp()
{
d = new Digester();
d.addObjectCreate( "ptwebltl", Ptwebltl.class );
d.addObjectCreate( "*/true", TRUE.class );
d.addSetNext( "*/true", "addFormula" );
d.addObjectCreate( "*/not", NOT.class );
d.addSetNext( "*/not", "addFormula" );
}
public void tearDown()
{
d.clear();
d = null;
}
@Test
public void parseNegate()
throws Exception
{
String toBeParsed = "<ptwebltl><not><true/></not></ptwebltl>";
Bool bool = d.parse( new StringReader( toBeParsed ) );
assertFalse( bool.value() );
}
@Test
public void parseDirect()
throws Exception
{
String toBeParsed = "<ptwebltl><true/></ptwebltl>";
Bool bool = d.parse( new StringReader( toBeParsed ) );
assertTrue( bool.value() );
}
public static interface Bool
{
void addFormula( Bool bool );
boolean value();
}
public static class Ptwebltl
implements Bool
{
private Bool bool;
public void addFormula( Bool bool )
{
this.bool = bool;
}
public boolean value()
{
return bool.value();
}
}
public static class TRUE
implements Bool
{
public void addFormula( Bool bool )
{
// do nothing
}
public boolean value()
{
return true;
}
}
public static class NOT
implements Bool
{
private Bool bool;
public void addFormula( Bool bool )
{
this.bool = bool;
}
public boolean value()
{
return !bool.value();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment