forked from github/copilot-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAgentModeTest.java
More file actions
70 lines (57 loc) · 2.44 KB
/
Copy pathAgentModeTest.java
File metadata and controls
70 lines (57 loc) · 2.44 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
package com.github.copilot;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.copilot.rpc.AgentMode;
/**
* Unit tests for {@link AgentMode} serialization, deserialization, and
* unknown-value behavior.
*/
public class AgentModeTest {
private final ObjectMapper mapper = new ObjectMapper();
@ParameterizedTest
@EnumSource(AgentMode.class)
void jsonRoundTrip_allValues(AgentMode mode) throws Exception {
String json = mapper.writeValueAsString(mode);
AgentMode deserialized = mapper.readValue(json, AgentMode.class);
assertEquals(mode, deserialized);
}
@Test
void getValue_returnsExpectedStrings() {
assertEquals("interactive", AgentMode.INTERACTIVE.getValue());
assertEquals("plan", AgentMode.PLAN.getValue());
assertEquals("autopilot", AgentMode.AUTOPILOT.getValue());
assertEquals("shell", AgentMode.SHELL.getValue());
}
@Test
void fromValue_knownValues_returnsCorrectEnum() {
assertEquals(AgentMode.INTERACTIVE, AgentMode.fromValue("interactive"));
assertEquals(AgentMode.PLAN, AgentMode.fromValue("plan"));
assertEquals(AgentMode.AUTOPILOT, AgentMode.fromValue("autopilot"));
assertEquals(AgentMode.SHELL, AgentMode.fromValue("shell"));
}
@Test
void fromValue_null_returnsNull() {
assertNull(AgentMode.fromValue(null));
}
@Test
void fromValue_unknownValue_throwsWithConsistentMessage() {
var ex = assertThrows(IllegalArgumentException.class, () -> AgentMode.fromValue("unknown"));
assertEquals("Unknown AgentMode value: unknown", ex.getMessage());
}
@Test
void jsonDeserialize_unknownValue_throws() {
String json = "\"not-a-mode\"";
assertThrows(Exception.class, () -> mapper.readValue(json, AgentMode.class));
}
@Test
void jsonSerialize_writesStringValue() throws Exception {
String json = mapper.writeValueAsString(AgentMode.AUTOPILOT);
assertEquals("\"autopilot\"", json);
}
}