[ 
https://issues.apache.org/jira/browse/OPENNLP-1020?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15968926#comment-15968926
 ] 

Koji Sekiguchi commented on OPENNLP-1020:
-----------------------------------------

I've already posted PR.

The test case I added in OPENNLP-1018 for reset() method of 
PlainTextByLineStream looks like this:

{code:java}
 @Test                                                                          
                                                                                
                  
 public void testReset() throws IOException {                                   
                                                                                
                  
   ObjectStream<String> stream =                                                
                                                                                
                  
           new PlainTextByLineStream(new MockInputStreamFactory(testString), 
StandardCharsets.UTF_8);                                                        
                     
                                                                                
                                                                                
                  
   Assert.assertEquals("line1", stream.read());                                 
                                                                                
                  
   Assert.assertEquals("line2", stream.read());                                 
                                                                                
                  
   Assert.assertEquals("line3", stream.read());                                 
                                                                                
                  
   stream.reset();                                                              
                                                                                
                  
                                                                                
                                                                                
                  
   Assert.assertEquals("line1", stream.read());                                 
                                                                                
                  
   Assert.assertEquals("line2", stream.read());                                 
                                                                                
                  
   Assert.assertEquals("line3", stream.read());                                 
                                                                                
                  
   Assert.assertEquals("line4", stream.read());                                 
                                                                                
                  
   Assert.assertNull(stream.read());                                            
                                                                                
                  
                                                                                
                                                                                
                  
   stream.close();                                                              
                                                                                
                  
 }                                                                              
                                                                                
                  
{code}

but it doesn't work because PlainTextByLineStream.reset() calls its 
inputStreamFactory's createInputStream, which is 
MockInputStreamFactory.createInputStream in this case, but 
MockInputStreamFactory.createInputStream() just returns InputStream which was 
given in its constructor, instead of creating a new InputStream. The PR fixes 
this problem.

What I've done in MockInputStreamFactory in the PR are:

* removed the constructor which takes InputStream but added a constructor which 
takes File for the InputStream instead. With this change, on the caller side, 
the callers pass a File, not creating InputStream
* create an InputStream in createInputStream(), not in the constructors or 
outside of MockInputStreamFactory
* removed FileNotFoundException from the constructors

> MockInputStreamFactory.createInputStream should create a new InputStream
> ------------------------------------------------------------------------
>
>                 Key: OPENNLP-1020
>                 URL: https://issues.apache.org/jira/browse/OPENNLP-1020
>             Project: OpenNLP
>          Issue Type: Bug
>          Components: Build, Packaging and Test
>            Reporter: Koji Sekiguchi
>            Priority: Minor
>              Labels: test
>
> Working on OPENNLP-1018, if I added a test for reset() of 
> PlainTextByLineStream to the existing PlainTextByLineStreamTest, it doesn't 
> work because it uses MockInputStreamFactory and call 
> MockInputStreamFactory.createInputStream() in reset() but 
> MockInputStreamFactory.createInputStream() doesn't create a new input stream 
> but just returns input stream which it holds instead.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to