blob: 4a9ec9286406f9fa24b36ea4204ebb85c3a70e96 (
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 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jdisc.handler;
import org.junit.Test;
import org.mockito.Mockito;
import java.nio.ByteBuffer;
import static org.junit.Assert.fail;
/**
* @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
*/
public class NullContentTestCase {
@Test
public void requireThatWriteThrowsException() {
CompletionHandler completion = Mockito.mock(CompletionHandler.class);
try {
NullContent.INSTANCE.write(ByteBuffer.allocate(69), completion);
fail();
} catch (UnsupportedOperationException e) {
}
Mockito.verifyZeroInteractions(completion);
}
@Test
public void requireThatWriteEmptyDoesNotThrowException() {
CompletionHandler completion = Mockito.mock(CompletionHandler.class);
NullContent.INSTANCE.write(ByteBuffer.allocate(0), completion);
Mockito.verify(completion).completed();
Mockito.verifyNoMoreInteractions(completion);
}
@Test
public void requireThatCloseCallsCompletion() {
CompletionHandler completion = Mockito.mock(CompletionHandler.class);
NullContent.INSTANCE.close(completion);
Mockito.verify(completion).completed();
Mockito.verifyNoMoreInteractions(completion);
}
@Test
public void requireThatCloseWithoutCompletionDoesNotThrow() {
NullContent.INSTANCE.close(null);
}
}
|