You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by "Niall Pemberton (JIRA)" <ji...@apache.org> on 2006/10/08 10:42:19 UTC

[jira] Created: (IO-94) MockInputStream

MockInputStream
---------------

                 Key: IO-94
                 URL: http://issues.apache.org/jira/browse/IO-94
             Project: Commons IO
          Issue Type: New Feature
          Components: Streams/Writers
            Reporter: Niall Pemberton
         Assigned To: Niall Pemberton
            Priority: Minor
             Fix For: 1.3


I have created a MockInputStream which can be plugged in for testing parts of systems where the data doesn't matter - the main use I've had for it was testing large files - without actually having the InputStream process large amounts of bytes.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Commented: (IO-94) New Mock InputStream & Writer implementations

Posted by "Stephen Colebourne (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/IO-94?page=comments#action_12441493 ] 
            
Stephen Colebourne commented on IO-94:
--------------------------------------

This feels almost out of scope for [io], which I've always felt was for runtime io work.

Is there a use case that isn't as a mock object? Is so, then we can rename it, but adding a 'mock' class to a non-mock jar feels wrong.

If it stays, it needs to go in the release notes.

> New Mock InputStream & Writer implementations
> ---------------------------------------------
>
>                 Key: IO-94
>                 URL: http://issues.apache.org/jira/browse/IO-94
>             Project: Commons IO
>          Issue Type: New Feature
>          Components: Streams/Writers
>            Reporter: Niall Pemberton
>         Assigned To: Niall Pemberton
>            Priority: Minor
>             Fix For: 1.3
>
>         Attachments: MockInputStream.java, MockInputStreamTestCase.java
>
>
> I have created a MockInputStream which can be plugged in for testing parts of systems where the data doesn't matter - the main use I've had for it was testing large files - without actually having the InputStream process large amounts of bytes.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Commented: (IO-94) New Mock InputStream & Writer implementations

Posted by "Niall Pemberton (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/IO-94?page=comments#action_12441792 ] 
            
Niall Pemberton commented on IO-94:
-----------------------------------

>From what you describe this is what MockInputStream and MockReader do out of the box:

MockInputStream: http://tinyurl.com/yk26nc
MockReader:  http://tinyurl.com/yd72ct

For MockInputStream, the read() method returns 0 but can be overriden to return any value by implementing the processByte() method. The read(byte[]) methods return the bytes array passed unchanged - so if its initialized to zero values, thats what you get back - but you can override the processBytes(byte[], offset, length) method to fill the array with whatever you want.

So a custom implementation would look like the following:

    public class FooInputStream extends MockInputStream {
        public TestMockInputStream(int size) {
            super(size);
        }
        protected int processByte() {
            return ...  // return whatever value required here
        }
        protected void processBytes(byte[] bytes, int offset, int length) {
            int startPos = (int)getPosition() - length;
            for (int i = offset; i < length; i++) {
                bytes[i] =  ... // initialize whatever value here
            }
        }
        
    }

Maybe "mock" is an unfortunate choice of names and should be renamed - they are fully functional streams which as well as supporting the read methods also properly implement skip(), mark() and reset(). In my view they're the equivalent of the NullOutputStream/NullReader - but those implementations are far simpler since they just have to ignore everything rather than function as a proper InputStram / Reader. I'd be happy to call them NullInputStream and NullReader instead if that is preferable.

> New Mock InputStream & Writer implementations
> ---------------------------------------------
>
>                 Key: IO-94
>                 URL: http://issues.apache.org/jira/browse/IO-94
>             Project: Commons IO
>          Issue Type: New Feature
>          Components: Streams/Writers
>            Reporter: Niall Pemberton
>         Assigned To: Niall Pemberton
>            Priority: Minor
>             Fix For: 1.3
>
>         Attachments: MockInputStream.java, MockInputStreamTestCase.java
>
>
> I have created a MockInputStream which can be plugged in for testing parts of systems where the data doesn't matter - the main use I've had for it was testing large files - without actually having the InputStream process large amounts of bytes.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Commented: (IO-94) MockInputStream

Posted by "Niall Pemberton (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/IO-94?page=comments#action_12440784 ] 
            
Niall Pemberton commented on IO-94:
-----------------------------------

New class committed, leaving open for comments

> MockInputStream
> ---------------
>
>                 Key: IO-94
>                 URL: http://issues.apache.org/jira/browse/IO-94
>             Project: Commons IO
>          Issue Type: New Feature
>          Components: Streams/Writers
>            Reporter: Niall Pemberton
>         Assigned To: Niall Pemberton
>            Priority: Minor
>             Fix For: 1.3
>
>         Attachments: MockInputStream.java, MockInputStreamTestCase.java
>
>
> I have created a MockInputStream which can be plugged in for testing parts of systems where the data doesn't matter - the main use I've had for it was testing large files - without actually having the InputStream process large amounts of bytes.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Updated: (IO-94) MockInputStream

Posted by "Niall Pemberton (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/IO-94?page=all ]

Niall Pemberton updated IO-94:
------------------------------

    Attachment: MockInputStream.java
                MockInputStreamTestCase.java

> MockInputStream
> ---------------
>
>                 Key: IO-94
>                 URL: http://issues.apache.org/jira/browse/IO-94
>             Project: Commons IO
>          Issue Type: New Feature
>          Components: Streams/Writers
>            Reporter: Niall Pemberton
>         Assigned To: Niall Pemberton
>            Priority: Minor
>             Fix For: 1.3
>
>         Attachments: MockInputStream.java, MockInputStreamTestCase.java
>
>
> I have created a MockInputStream which can be plugged in for testing parts of systems where the data doesn't matter - the main use I've had for it was testing large files - without actually having the InputStream process large amounts of bytes.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Closed: (IO-94) New NullnputStream & NullReader implementations

Posted by "Stephen Colebourne (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/IO-94?page=all ]

Stephen Colebourne closed IO-94.
--------------------------------

    Resolution: Fixed

> New NullnputStream & NullReader implementations
> -----------------------------------------------
>
>                 Key: IO-94
>                 URL: http://issues.apache.org/jira/browse/IO-94
>             Project: Commons IO
>          Issue Type: New Feature
>          Components: Streams/Writers
>            Reporter: Niall Pemberton
>         Assigned To: Niall Pemberton
>            Priority: Minor
>             Fix For: 1.3
>
>         Attachments: MockInputStream.java, MockInputStreamTestCase.java
>
>
> I have created a MockInputStream which can be plugged in for testing parts of systems where the data doesn't matter - the main use I've had for it was testing large files - without actually having the InputStream process large amounts of bytes.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Commented: (IO-94) New NullnputStream & NullReader implementations

Posted by "Niall Pemberton (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/IO-94?page=comments#action_12441911 ] 
            
Niall Pemberton commented on IO-94:
-----------------------------------

MockInputStream and MockReader  have been renamed to NullInputStream and NullReader 

> New NullnputStream & NullReader implementations
> -----------------------------------------------
>
>                 Key: IO-94
>                 URL: http://issues.apache.org/jira/browse/IO-94
>             Project: Commons IO
>          Issue Type: New Feature
>          Components: Streams/Writers
>            Reporter: Niall Pemberton
>         Assigned To: Niall Pemberton
>            Priority: Minor
>             Fix For: 1.3
>
>         Attachments: MockInputStream.java, MockInputStreamTestCase.java
>
>
> I have created a MockInputStream which can be plugged in for testing parts of systems where the data doesn't matter - the main use I've had for it was testing large files - without actually having the InputStream process large amounts of bytes.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Commented: (IO-94) New Mock InputStream & Writer implementations

Posted by "Niall Pemberton (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/IO-94?page=comments#action_12441505 ] 
            
Niall Pemberton commented on IO-94:
-----------------------------------

I can't think of a use case that isn't as a mock test object. If you do remove it then could move it into the "test" suite?  - I have tests for the IO-84 2GB bug that use it.

> New Mock InputStream & Writer implementations
> ---------------------------------------------
>
>                 Key: IO-94
>                 URL: http://issues.apache.org/jira/browse/IO-94
>             Project: Commons IO
>          Issue Type: New Feature
>          Components: Streams/Writers
>            Reporter: Niall Pemberton
>         Assigned To: Niall Pemberton
>            Priority: Minor
>             Fix For: 1.3
>
>         Attachments: MockInputStream.java, MockInputStreamTestCase.java
>
>
> I have created a MockInputStream which can be plugged in for testing parts of systems where the data doesn't matter - the main use I've had for it was testing large files - without actually having the InputStream process large amounts of bytes.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Updated: (IO-94) New NullnputStream & NullReader implementations

Posted by "Niall Pemberton (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/IO-94?page=all ]

Niall Pemberton updated IO-94:
------------------------------

    Summary: New NullnputStream & NullReader implementations  (was: New Mock InputStream & Writer implementations)

> New NullnputStream & NullReader implementations
> -----------------------------------------------
>
>                 Key: IO-94
>                 URL: http://issues.apache.org/jira/browse/IO-94
>             Project: Commons IO
>          Issue Type: New Feature
>          Components: Streams/Writers
>            Reporter: Niall Pemberton
>         Assigned To: Niall Pemberton
>            Priority: Minor
>             Fix For: 1.3
>
>         Attachments: MockInputStream.java, MockInputStreamTestCase.java
>
>
> I have created a MockInputStream which can be plugged in for testing parts of systems where the data doesn't matter - the main use I've had for it was testing large files - without actually having the InputStream process large amounts of bytes.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Commented: (IO-94) New Mock InputStream & Writer implementations

Posted by "Niall Pemberton (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/IO-94?page=comments#action_12441672 ] 
            
Niall Pemberton commented on IO-94:
-----------------------------------

OK but can you create a mock on the fly that emulates a file of a specified size - such as a 2GB file?

> New Mock InputStream & Writer implementations
> ---------------------------------------------
>
>                 Key: IO-94
>                 URL: http://issues.apache.org/jira/browse/IO-94
>             Project: Commons IO
>          Issue Type: New Feature
>          Components: Streams/Writers
>            Reporter: Niall Pemberton
>         Assigned To: Niall Pemberton
>            Priority: Minor
>             Fix For: 1.3
>
>         Attachments: MockInputStream.java, MockInputStreamTestCase.java
>
>
> I have created a MockInputStream which can be plugged in for testing parts of systems where the data doesn't matter - the main use I've had for it was testing large files - without actually having the InputStream process large amounts of bytes.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Commented: (IO-94) New Mock InputStream & Writer implementations

Posted by "Joerg Schaible (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/IO-94?page=comments#action_12441670 ] 
            
Joerg Schaible commented on IO-94:
----------------------------------

Personally I have always used (CGLIB-enhanced) jMock to create mocks of streams on the fly. Therefore I agree with Stephen, that this is not really something that should be included into the runtime part. Moving to test is IMHO fine though.

> New Mock InputStream & Writer implementations
> ---------------------------------------------
>
>                 Key: IO-94
>                 URL: http://issues.apache.org/jira/browse/IO-94
>             Project: Commons IO
>          Issue Type: New Feature
>          Components: Streams/Writers
>            Reporter: Niall Pemberton
>         Assigned To: Niall Pemberton
>            Priority: Minor
>             Fix For: 1.3
>
>         Attachments: MockInputStream.java, MockInputStreamTestCase.java
>
>
> I have created a MockInputStream which can be plugged in for testing parts of systems where the data doesn't matter - the main use I've had for it was testing large files - without actually having the InputStream process large amounts of bytes.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Updated: (IO-94) New Mock InputStream & Writer implementations

Posted by "Niall Pemberton (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/IO-94?page=all ]

Niall Pemberton updated IO-94:
------------------------------

    Summary: New Mock InputStream & Writer implementations  (was: MockInputStream)

> New Mock InputStream & Writer implementations
> ---------------------------------------------
>
>                 Key: IO-94
>                 URL: http://issues.apache.org/jira/browse/IO-94
>             Project: Commons IO
>          Issue Type: New Feature
>          Components: Streams/Writers
>            Reporter: Niall Pemberton
>         Assigned To: Niall Pemberton
>            Priority: Minor
>             Fix For: 1.3
>
>         Attachments: MockInputStream.java, MockInputStreamTestCase.java
>
>
> I have created a MockInputStream which can be plugged in for testing parts of systems where the data doesn't matter - the main use I've had for it was testing large files - without actually having the InputStream process large amounts of bytes.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Commented: (IO-94) New Mock InputStream & Writer implementations

Posted by "Joerg Schaible (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/IO-94?page=comments#action_12441674 ] 
            
Joerg Schaible commented on IO-94:
----------------------------------

Yes, but not *that* easy :)

But what I really needed and wrote once was a NullInputStream of a specific capacity delivering bytes of value 0 (because of assembling a data stream on the fly for a format with 'holes'). Maybe such an implementation with an arbitrary byte value might be added as ConstantInputStream with a certain capacity. Something like this should be similar/equal to the MockInputStream  but does not sound so determined for test ;-)

> New Mock InputStream & Writer implementations
> ---------------------------------------------
>
>                 Key: IO-94
>                 URL: http://issues.apache.org/jira/browse/IO-94
>             Project: Commons IO
>          Issue Type: New Feature
>          Components: Streams/Writers
>            Reporter: Niall Pemberton
>         Assigned To: Niall Pemberton
>            Priority: Minor
>             Fix For: 1.3
>
>         Attachments: MockInputStream.java, MockInputStreamTestCase.java
>
>
> I have created a MockInputStream which can be plugged in for testing parts of systems where the data doesn't matter - the main use I've had for it was testing large files - without actually having the InputStream process large amounts of bytes.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Commented: (IO-94) New Mock InputStream & Writer implementations

Posted by "Stephen Colebourne (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/IO-94?page=comments#action_12441851 ] 
            
Stephen Colebourne commented on IO-94:
--------------------------------------

As I said before, I'm unsure of the use case outside mocking, but this is a strange world, and someone will probably think of one... perhaps in a pipeline of some kind.

Certainly, the 'mock' name is inappropriate, and I agree that they are a parallel to the 'null' ones, but the 'null' name may be inappropriate here, not sure.

I suggest that we accept them as the parallel to the null inputs. Can you rename them to Null* (unless anyone can think of a better name) add to the release notes.

> New Mock InputStream & Writer implementations
> ---------------------------------------------
>
>                 Key: IO-94
>                 URL: http://issues.apache.org/jira/browse/IO-94
>             Project: Commons IO
>          Issue Type: New Feature
>          Components: Streams/Writers
>            Reporter: Niall Pemberton
>         Assigned To: Niall Pemberton
>            Priority: Minor
>             Fix For: 1.3
>
>         Attachments: MockInputStream.java, MockInputStreamTestCase.java
>
>
> I have created a MockInputStream which can be plugged in for testing parts of systems where the data doesn't matter - the main use I've had for it was testing large files - without actually having the InputStream process large amounts of bytes.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org