@@ -39,125 +39,49 @@ public final class GeminiUtilTest {
3939 Content .fromParts (Part .fromText (GeminiUtil .CONTINUE_OUTPUT_MESSAGE ));
4040
4141 @ Test
42- public void stripThoughts_emptyList_returnsEmptyList () {
43- assertThat (GeminiUtil .stripThoughts (ImmutableList .of ())).isEmpty ();
44- }
45-
46- @ Test
47- public void stripThoughts_contentWithNoParts_returnsContentWithNoParts () {
48- Content content = Content .builder ().build ();
49- Content expected = toContent ();
50-
51- List <Content > result = GeminiUtil .stripThoughts (ImmutableList .of (content ));
52-
53- assertThat (result ).containsExactly (expected );
54- }
55-
56- @ Test
57- public void stripThoughts_partsWithoutThought_returnsAllParts () {
58- Part part1 = createTextPart ("Hello" );
59- Part part2 = createTextPart ("World" );
60- Content content = toContent (part1 , part2 );
61-
62- List <Content > result = GeminiUtil .stripThoughts (ImmutableList .of (content ));
63-
64- assertThat (result .get (0 ).parts ().get ()).containsExactly (part1 , part2 ).inOrder ();
65- }
66-
67- @ Test
68- public void stripThoughts_partsWithThoughtFalse_returnsAllParts () {
69- Part part1 = createThoughtPart ("Regular text" , false );
70- Part part2 = createTextPart ("Another text" );
71- Content content = toContent (part1 , part2 );
72-
73- List <Content > result = GeminiUtil .stripThoughts (ImmutableList .of (content ));
74-
75- assertThat (result .get (0 ).parts ().get ()).containsExactly (part1 , part2 ).inOrder ();
76- }
77-
78- @ Test
79- public void stripThoughts_partsWithThoughtTrue_stripsThoughtParts () {
80- Part part1 = createTextPart ("Visible text" );
81- Part part2 = createThoughtPart ("Internal thought" , true );
82- Part part3 = createTextPart ("More visible text" );
83- Content content = toContent (part1 , part2 , part3 );
84-
85- List <Content > result = GeminiUtil .stripThoughts (ImmutableList .of (content ));
86-
87- assertThat (result .get (0 ).parts ().get ()).containsExactly (part1 , part3 ).inOrder ();
88- }
89-
90- @ Test
91- public void stripThoughts_mixedParts_stripsOnlyThoughtTrue () {
92- Part part1 = createTextPart ("Text 1" );
93- Part part2 = createThoughtPart ("Thought 1" , true );
94- Part part3 = createTextPart ("Text 2" );
95- Part part4 = createThoughtPart ("Not a thought" , false );
96- Part part5 = createThoughtPart ("Thought 2" , true );
97- Content content = toContent (part1 , part2 , part3 , part4 , part5 );
98-
99- List <Content > result = GeminiUtil .stripThoughts (ImmutableList .of (content ));
100-
101- assertThat (result .get (0 ).parts ().get ()).containsExactly (part1 , part3 , part4 ).inOrder ();
102- }
103-
104- @ Test
105- public void stripThoughts_multipleContents_stripsThoughtsFromEach () {
106- Part partA1 = createTextPart ("A1" );
107- Part partA2 = createThoughtPart ("A2 Thought" , true );
108- Content contentA = toContent (partA1 , partA2 );
109-
110- Part partB1 = createThoughtPart ("B1 Thought" , true );
111- Part partB2 = createTextPart ("B2" );
112- Part partB3 = createThoughtPart ("B3 Not Thought" , false );
113- Content contentB = toContent (partB1 , partB2 , partB3 );
114-
115- List <Content > result = GeminiUtil .stripThoughts (ImmutableList .of (contentA , contentB ));
42+ public void getPart0FromLlmResponse_noContent_returnsEmpty () {
43+ LlmResponse llmResponse = LlmResponse .builder ().build ();
11644
117- assertThat (result ).hasSize (2 );
118- assertThat (result .get (0 ).parts ().get ()).containsExactly (partA1 );
119- assertThat (result .get (1 ).parts ().get ()).containsExactly (partB2 , partB3 ).inOrder ();
45+ assertThat (GeminiUtil .getPart0FromLlmResponse (llmResponse )).isEmpty ();
12046 }
12147
12248 @ Test
123- public void getTextFromLlmResponse_noContent_returnsEmptyString () {
124- LlmResponse llmResponse = LlmResponse .builder ().build ();
49+ public void getPart0FromLlmResponse_contentWithNoParts_returnsEmpty () {
50+ LlmResponse llmResponse = toResponse ( Content .builder ().build () );
12551
126- assertThat (GeminiUtil .getTextFromLlmResponse (llmResponse )).isEmpty ();
52+ assertThat (GeminiUtil .getPart0FromLlmResponse (llmResponse )).isEmpty ();
12753 }
12854
12955 @ Test
130- public void getTextFromLlmResponse_contentWithNoParts_returnsEmptyString () {
131- LlmResponse llmResponse = toResponse (Content . builder (). build ());
56+ public void getPart0FromLlmResponse_contentWithEmptyPartsList_returnsEmpty () {
57+ LlmResponse llmResponse = toResponse (toContent ());
13258
133- assertThat (GeminiUtil .getTextFromLlmResponse (llmResponse )).isEmpty ();
59+ assertThat (GeminiUtil .getPart0FromLlmResponse (llmResponse )).isEmpty ();
13460 }
13561
13662 @ Test
137- public void getTextFromLlmResponse_firstPartHasNoText_returnsEmptyString () {
138- Part part1 = Part . builder (). inlineData ( Blob . builder (). mimeType ( "image/png" ). build ()). build ( );
139- LlmResponse llmResponse = toResponse (part1 );
63+ public void getPart0FromLlmResponse_contentWithSinglePart_returnsFirstPart () {
64+ Part expectedPart = createTextPart ( "Hello world" );
65+ LlmResponse llmResponse = toResponse (expectedPart );
14066
141- assertThat (GeminiUtil .getTextFromLlmResponse (llmResponse )).isEmpty ( );
67+ assertThat (GeminiUtil .getPart0FromLlmResponse (llmResponse )).hasValue ( expectedPart );
14268 }
14369
14470 @ Test
145- public void getTextFromLlmResponse_firstPartHasText_returnsText () {
146- String expectedText = "The quick brown fox." ;
147- Part part1 = createTextPart (expectedText );
148- LlmResponse llmResponse = toResponse (part1 );
71+ public void getPart0FromLlmResponse_contentWithMultipleParts_returnsFirstPart () {
72+ Part firstPart = createTextPart ( "First part" ) ;
73+ Part secondPart = createTextPart ("Second part" );
74+ LlmResponse llmResponse = toResponse (firstPart , secondPart );
14975
150- assertThat (GeminiUtil .getTextFromLlmResponse (llmResponse )).isEqualTo ( expectedText );
76+ assertThat (GeminiUtil .getPart0FromLlmResponse (llmResponse )).hasValue ( firstPart );
15177 }
15278
15379 @ Test
154- public void getTextFromLlmResponse_multipleParts_returnsTextFromFirstPartOnly () {
155- String expectedText = "First part text." ;
156- Part part1 = createTextPart (expectedText );
157- Part part2 = createTextPart ("Second part text." );
158- LlmResponse llmResponse = toResponse (part1 , part2 );
80+ public void getPart0FromLlmResponse_contentWithThoughtPart_returnsFirstPart () {
81+ Part expectedPart = createThoughtPart ("I need to think about this" , true );
82+ LlmResponse llmResponse = toResponse (expectedPart );
15983
160- assertThat (GeminiUtil .getTextFromLlmResponse (llmResponse )).isEqualTo ( expectedText );
84+ assertThat (GeminiUtil .getPart0FromLlmResponse (llmResponse )).hasValue ( expectedPart );
16185 }
16286
16387 @ Test
0 commit comments