Skip to content

Commit

Permalink
Merge pull request #1 from loefflefarn/master
Browse files Browse the repository at this point in the history
fixed supports handling with abstract version of returnType class
  • Loading branch information
julian-eggers authored May 23, 2017
2 parents af9bb74 + 234ff3e commit d5865bc
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Spring XML Unmarshalling with [XOM](http://www.xom.nu/)
<dependency>
<groupId>com.itelg.spring</groupId>
<artifactId>spring-xom-unmarshaller</artifactId>
<version>0.1.0-RELEASE</version>
<version>0.1.1-RELEASE</version>
</dependency>
</dependencies>
```
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<name>spring-xom-unmarshaller</name>
<description>Spring XML Unmarshalling with XOM</description>
<url>https://github.com/julian-eggers/spring-xom-unmarshaller</url>
<version>0.1.0-RELEASE</version>
<version>0.1.1-RELEASE</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ public boolean supports(Class<?> clazz)
{
for (ParserHolder parser : parsers)
{
if (clazz.equals(parser.getReturnType()))
if (parser.getReturnType().isAssignableFrom(clazz))
{
return true;
}
}

return false;
}

@Override
public Object unmarshal(Source source) throws IOException, XmlMappingException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import com.itelg.spring.xom.unmarshaller.parser.RootTagMatcherParser;
import com.itelg.spring.xom.unmarshaller.parser.RootTagTypeMatchingDisableParser;

import nu.xom.Element;

public class XomUnmarshallerTest
{
private Unmarshaller unmarshaller;
Expand All @@ -28,6 +30,7 @@ public void init()
List<Parser<?>> parsers = new ArrayList<>();
parsers.add(new RootTagMatcherParser());
parsers.add(new RootTagTypeMatchingDisableParser());
parsers.add(new TestObjectParser());
unmarshaller = new XomUnmarshaller(parsers);
}

Expand All @@ -36,6 +39,7 @@ public void testSupports()
{
Assert.assertTrue(unmarshaller.supports(String.class));
Assert.assertTrue(unmarshaller.supports(Integer.class));
Assert.assertTrue(unmarshaller.supports(TestObject.class));
Assert.assertFalse(unmarshaller.supports(Double.class));
}

Expand All @@ -48,7 +52,7 @@ public void testUnmarshallString() throws IOException
Assert.assertEquals("test", value);
}
}

@Test
public void testUnmarshallNumber() throws IOException
{
Expand All @@ -58,7 +62,7 @@ public void testUnmarshallNumber() throws IOException
Assert.assertEquals(Integer.valueOf(12), value);
}
}

@Test(expected = UnmarshallingFailureException.class)
public void testUnmarshallLong() throws IOException
{
Expand All @@ -68,4 +72,23 @@ public void testUnmarshallLong() throws IOException
Assert.fail("unmarshaller should fail!");
}
}

private class TestObject extends AbstractTestObject
{
// empty class for type check
}

private abstract class AbstractTestObject
{
// empty abstract class for type check
}

private class TestObjectParser implements Parser<AbstractTestObject>
{
@Override
public AbstractTestObject parse(Element rootElement)
{
return null;
}
}
}

0 comments on commit d5865bc

Please sign in to comment.