aboutsummaryrefslogtreecommitdiffstats
path: root/jdisc_core/src/test/java/com/yahoo/jdisc/test/NonWorkingContentChannelTestCase.java
blob: 46bbbad95ca89c6d8f0997cedf2efa467c204525 (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jdisc.test;

import com.yahoo.jdisc.handler.CompletionHandler;
import com.yahoo.jdisc.handler.ContentChannel;
import org.junit.jupiter.api.Test;

import java.nio.ByteBuffer;

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


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

    @Test
    void requireThatWriteThrowsException() {
        ContentChannel content = new NonWorkingContentChannel();
        try {
            content.write(null, null);
            fail();
        } catch (UnsupportedOperationException e) {

        }
        content = new NonWorkingContentChannel();
        try {
            content.write(ByteBuffer.allocate(69), null);
            fail();
        } catch (UnsupportedOperationException e) {

        }
        content = new NonWorkingContentChannel();
        try {
            content.write(ByteBuffer.allocate(69), new MyCompletion());
            fail();
        } catch (UnsupportedOperationException e) {

        }
        content = new NonWorkingContentChannel();
        try {
            content.write(null, new MyCompletion());
            fail();
        } catch (UnsupportedOperationException e) {

        }
    }

    @Test
    void requireThatCloseThrowsException() {
        ContentChannel content = new NonWorkingContentChannel();
        try {
            content.close(null);
            fail();
        } catch (UnsupportedOperationException e) {

        }
        content = new NonWorkingContentChannel();
        try {
            content.close(new MyCompletion());
            fail();
        } catch (UnsupportedOperationException e) {

        }
    }

    private static class MyCompletion implements CompletionHandler {

        @Override
        public void completed() {

        }

        @Override
        public void failed(Throwable t) {

        }
    }
}