我正在编写一个Maven插件,想编写一些JUnit测试。我遵循了Maven Plugin Testing中的说明。不幸的是,在我可以配置或调用任何东西之前,我一直在测试设置期间收到异常。
这是我的JUnit测试代码:
public class ResetMojoTest {
private static final String POM_FILE_NAME = "/path/to/pom.xml";
@Rule
public MojoRule rule = new MojoRule();
@Test
public void testSomething()
throws Exception
{
File pom = new File(POM_FILE_NAME);
Assert.assertNotNull( pom );
Assert.assertTrue( pom.exists() );
ResetMojo resetMojo = (ResetMojo) rule.lookupMojo( "touch", pom );
Assert.assertNotNull( resetMojo );
resetMojo.execute();
}
}
以下是异常的堆栈跟踪:
java.io.IOException: Stream closed
at java.io.BufferedInputStream.getInIfOpen(BufferedInputStream.java:134)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read(BufferedInputStream.java:237)
at org.apache.commons.io.input.BOMInputStream.getBOM(BOMInputStream.java:175)
at org.apache.commons.io.input.BOMInputStream.getBOMCharsetName(BOMInputStream.java:201)
at org.apache.commons.io.input.XmlStreamReader.doRawStream(XmlStreamReader.java:412)
at org.apache.commons.io.input.XmlStreamReader.<init>(XmlStreamReader.java:206)
at org.apache.commons.io.input.XmlStreamReader.<init>(XmlStreamReader.java:171)
at org.apache.commons.io.input.XmlStreamReader.<init>(XmlStreamReader.java:140)
at org.apache.maven.plugin.testing.AbstractMojoTestCase.setUp(AbstractMojoTestCase.java:119)
at org.apache.maven.plugin.testing.MojoRule$2.evaluate(MojoRule.java:299)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
有关如何使其正常工作的任何想法吗?