aboutsummaryrefslogtreecommitdiffstats
path: root/jdisc_core/src/test/java/com/yahoo/jdisc/handler/NullContentTestCase.java
blob: e7eccf465d984ceeb0f4dc1d28c2805a19c4256c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jdisc.handler;

import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import java.nio.ByteBuffer;

import static org.junit.jupiter.api.Assertions.fail;

/**
 * @author Simon Thoresen Hult
 */
public class NullContentTestCase {

    @Test
    void requireThatWriteThrowsException() {
        CompletionHandler completion = Mockito.mock(CompletionHandler.class);
        try {
            NullContent.INSTANCE.write(ByteBuffer.allocate(69), completion);
            fail();
        } catch (UnsupportedOperationException e) {

        }
        Mockito.verifyNoInteractions(completion);
    }

    @Test
    void requireThatWriteEmptyDoesNotThrowException() {
        CompletionHandler completion = Mockito.mock(CompletionHandler.class);
        NullContent.INSTANCE.write(ByteBuffer.allocate(0), completion);
        Mockito.verify(completion).completed();
        Mockito.verifyNoMoreInteractions(completion);
    }

    @Test
    void requireThatCloseCallsCompletion() {
        CompletionHandler completion = Mockito.mock(CompletionHandler.class);
        NullContent.INSTANCE.close(completion);
        Mockito.verify(completion).completed();
        Mockito.verifyNoMoreInteractions(completion);
    }

    @Test
    void requireThatCloseWithoutCompletionDoesNotThrow() {
        NullContent.INSTANCE.close(null);
    }
}