Outputstream .write() test läuft durch?

Kann mir bitte jemand erklären, warum mein Test hier durchläuft.

Der off ist 7, das ist die Indexstelle, aber der die Bytes von dem Byte-Array ausgelesen werden sollen. In meinem Array sind aber nur 5 Zahlen.

Wie kann dann der Test durchlaufen?

public class AusgabeStream extends OutputStream {

    @Override
    public void write(int b) throws IOException {

    }

    public void write(byte b[], int off, int len) throws IOException {
        /*
          Einschränkungen:
          byteArray nicht null
          kein negativer off und len
         */

        if (len < 0) {
            throw new RuntimeException("Länge ist kleiner null");
        }
        if (b == null) {
            throw new NullPointerException("Array ist null");
        }

Jetzt kommt der Test:

class AusgabeStreamTest {

    AusgabeStream os = new AusgabeStream();

    @Test
    void ungueltigIndex() {

        // Fragen warum durchläuft, off geht bei 7 los?

        try {
            os.write(new byte[]{101, 90,30,20,44}, 7, 2);
//            fail("IndexOutofBoundsException erwartet");
        } catch (IndexOutOfBoundsException e) {
            assertEquals("", e.getMessage());
        } catch (IOException e) { }
        }

Warum läuft der Test hier durch?

(1 votes)
Loading...

Similar Posts

Subscribe
Notify of
4 Answers
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
gogogo
1 year ago

You overwrite write() in OutputStream. This will call your and not the ones from OutputStream.

What is the method going on? Do you want them to call something from OutputStream? There is the write method with the meaning of offset and length?

Then you need super.write(…

gogogo
1 year ago
Reply to  RedDevil1982

In your write() method you call super.write(b, off, len ) if you want.