This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch ci-issue-TASK-231
in repository https://gitbox.apache.org/repos/asf/camel.git

commit b40a04dc52c393f0698ac50d690d025c4fd8bbae
Author: Andrea Cosentino <[email protected]>
AuthorDate: Thu Apr 2 14:22:19 2026 +0200

    TASK-231: Fix voiceFileId never assigned in InlineQueryResultCachedVoice 
builder
    
    The Builder.voiceFileId() method was incorrectly assigning to this.id
    instead of this.voiceFileId, causing the voiceFileId to always be null
    when using the builder pattern. This also had the side effect of
    overwriting the id field.
    
    Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
---
 .../model/InlineQueryResultCachedVoice.java        |  4 +-
 .../model/InlineQueryResultCachedVoiceTest.java    | 85 ++++++++++++++++++++++
 2 files changed, 87 insertions(+), 2 deletions(-)

diff --git 
a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/InlineQueryResultCachedVoice.java
 
b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/InlineQueryResultCachedVoice.java
index 0dc069b8e951..a32b34328320 100644
--- 
a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/InlineQueryResultCachedVoice.java
+++ 
b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/InlineQueryResultCachedVoice.java
@@ -54,7 +54,7 @@ public class InlineQueryResultCachedVoice extends 
InlineQueryResult {
     public static final class Builder {
         private String id;
         private InlineKeyboardMarkup replyMarkup;
-        private String voiceFileId; // TODO this field is never assigned
+        private String voiceFileId;
         private String title;
         private String caption;
         private String parseMode;
@@ -69,7 +69,7 @@ public class InlineQueryResultCachedVoice extends 
InlineQueryResult {
         }
 
         public Builder voiceFileId(String voiceFileId) {
-            this.id = voiceFileId;
+            this.voiceFileId = voiceFileId;
             return this;
         }
 
diff --git 
a/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/model/InlineQueryResultCachedVoiceTest.java
 
b/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/model/InlineQueryResultCachedVoiceTest.java
new file mode 100644
index 000000000000..785f31579714
--- /dev/null
+++ 
b/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/model/InlineQueryResultCachedVoiceTest.java
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.telegram.model;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Tests for {@link InlineQueryResultCachedVoice} builder and JSON 
serialization.
+ */
+class InlineQueryResultCachedVoiceTest {
+
+    private final ObjectMapper objectMapper = new ObjectMapper();
+
+    @Test
+    void testBuilderAssignsVoiceFileId() {
+        InlineQueryResultCachedVoice result = 
InlineQueryResultCachedVoice.builder()
+                .id("1")
+                .voiceFileId("voice-file-123")
+                .title("Test Voice")
+                .build();
+
+        assertThat(result.getId()).isEqualTo("1");
+        assertThat(result.getVoiceFileId()).isEqualTo("voice-file-123");
+        assertThat(result.getTitle()).isEqualTo("Test Voice");
+    }
+
+    @Test
+    void testBuilderVoiceFileIdDoesNotOverwriteId() {
+        InlineQueryResultCachedVoice result = 
InlineQueryResultCachedVoice.builder()
+                .id("query-result-1")
+                .voiceFileId("voice-file-456")
+                .build();
+
+        assertThat(result.getId()).isEqualTo("query-result-1");
+        assertThat(result.getVoiceFileId()).isEqualTo("voice-file-456");
+    }
+
+    @Test
+    void testSerializesToJsonWithVoiceFileId() throws JsonProcessingException {
+        InlineQueryResultCachedVoice result = 
InlineQueryResultCachedVoice.builder()
+                .id("1")
+                .voiceFileId("voice-file-789")
+                .title("My Voice")
+                .caption("A voice message")
+                .build();
+
+        String json = objectMapper.writeValueAsString(result);
+
+        assertThat(json)
+                .contains("\"voice_file_id\":\"voice-file-789\"")
+                .contains("\"id\":\"1\"")
+                .contains("\"title\":\"My Voice\"")
+                .contains("\"caption\":\"A voice message\"")
+                .contains("\"type\":\"voice\"");
+    }
+
+    @Test
+    void testDeserializesFromJson() throws JsonProcessingException {
+        String json = 
"{\"type\":\"voice\",\"id\":\"1\",\"voice_file_id\":\"voice-file-abc\",\"title\":\"Voice\"}";
+
+        InlineQueryResultCachedVoice result = objectMapper.readValue(json, 
InlineQueryResultCachedVoice.class);
+
+        assertThat(result.getVoiceFileId()).isEqualTo("voice-file-abc");
+        assertThat(result.getId()).isEqualTo("1");
+        assertThat(result.getTitle()).isEqualTo("Voice");
+    }
+}

Reply via email to