-
-
Notifications
You must be signed in to change notification settings - Fork 200
Expand file tree
/
Copy pathSenderTest.java
More file actions
54 lines (42 loc) · 1.49 KB
/
SenderTest.java
File metadata and controls
54 lines (42 loc) · 1.49 KB
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
/*
* Jooby https://jooby.io
* Apache License Version 2.0 https://jooby.io/LICENSE.txt
* Copyright 2014 Edgar Espina
*/
package io.jooby;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.CALLS_REAL_METHODS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.withSettings;
import java.nio.charset.StandardCharsets;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public class SenderTest {
private Sender sender;
private Sender.Callback callback;
@BeforeEach
void setUp() {
// We use CALLS_REAL_METHODS to test the default logic in the interface
sender = mock(Sender.class, withSettings().defaultAnswer(CALLS_REAL_METHODS));
callback = mock(Sender.Callback.class);
}
@Test
void writeStringWithDefaultCharset() {
String data = "hello";
byte[] expectedBytes = data.getBytes(StandardCharsets.UTF_8);
sender.write(data, callback);
// Verify it delegates to write(String, Charset, Callback)
// which delegates to write(byte[], Callback)
verify(sender).write(eq(expectedBytes), eq(callback));
}
@Test
void writeStringWithCustomCharset() {
String data = "hello";
var charset = StandardCharsets.UTF_16;
byte[] expectedBytes = data.getBytes(charset);
sender.write(data, charset, callback);
// Verify it delegates to write(byte[], Callback) with correct bytes
verify(sender).write(eq(expectedBytes), eq(callback));
}
}