Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,23 @@ void testErrorEventTypeWithEmptyContentBlock() {
assertThat(response).isNotNull();
}

@Test
void testMultipleErrorEventsHandling() {
StreamHelper streamHelper = new StreamHelper();
AtomicReference<ChatCompletionResponseBuilder> contentBlockReference = new AtomicReference<>();

AnthropicApi.ErrorEvent firstError = new AnthropicApi.ErrorEvent(AnthropicApi.EventType.ERROR,
new AnthropicApi.ErrorEvent.Error("validation_error", "Invalid input"));
AnthropicApi.ErrorEvent secondError = new AnthropicApi.ErrorEvent(AnthropicApi.EventType.ERROR,
new AnthropicApi.ErrorEvent.Error("server_error", "Internal server error"));

AnthropicApi.ChatCompletionResponse response1 = streamHelper.eventToChatCompletionResponse(firstError,
contentBlockReference);
AnthropicApi.ChatCompletionResponse response2 = streamHelper.eventToChatCompletionResponse(secondError,
contentBlockReference);

assertThat(response1).isNotNull();
assertThat(response2).isNotNull();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,139 @@
import java.util.List;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import org.springframework.core.convert.support.DefaultConversionService;

import static org.assertj.core.api.Assertions.assertThat;

class ListOutputConverterTest {

private ListOutputConverter listOutputConverter;

@BeforeEach
void setUp() {
listOutputConverter = new ListOutputConverter(new DefaultConversionService());
}

@Test
void csv() {
String csvAsString = "foo, bar, baz";
ListOutputConverter listOutputConverter = new ListOutputConverter(new DefaultConversionService());
List<String> list = listOutputConverter.convert(csvAsString);
assertThat(list).containsExactlyElementsOf(List.of("foo", "bar", "baz"));
}

@Test
void csvWithoutSpaces() {
String csvAsString = "A,B,C";
List<String> list = listOutputConverter.convert(csvAsString);
assertThat(list).containsExactlyElementsOf(List.of("A", "B", "C"));
}

@Test
void csvWithExtraSpaces() {
String csvAsString = "A , B , C ";
List<String> list = listOutputConverter.convert(csvAsString);
assertThat(list).containsExactlyElementsOf(List.of("A", "B", "C"));
}

@Test
void csvWithSingleItem() {
String csvAsString = "single-item";
List<String> list = listOutputConverter.convert(csvAsString);
assertThat(list).containsExactlyElementsOf(List.of("single-item"));
}

@Test
void csvWithEmptyString() {
String csvAsString = "";
List<String> list = listOutputConverter.convert(csvAsString);
assertThat(list).isEmpty();
}

@Test
void csvWithEmptyValues() {
String csvAsString = "A, , C";
List<String> list = listOutputConverter.convert(csvAsString);
assertThat(list).containsExactlyElementsOf(List.of("A", "", "C"));
}

@Test
void csvWithOnlyCommas() {
String csvAsString = ",,";
List<String> list = listOutputConverter.convert(csvAsString);
assertThat(list).containsExactlyElementsOf(List.of("", "", ""));
}

@Test
void csvWithTrailingComma() {
String csvAsString = "A, B,";
List<String> list = listOutputConverter.convert(csvAsString);
assertThat(list).containsExactlyElementsOf(List.of("A", "B", ""));
}

@Test
void csvWithLeadingComma() {
String csvAsString = ", A, B";
List<String> list = listOutputConverter.convert(csvAsString);
assertThat(list).containsExactlyElementsOf(List.of("", "A", "B"));
}

@Test
void csvWithSpecialCharacters() {
String csvAsString = "[email protected], item#123, $data%";
List<String> list = listOutputConverter.convert(csvAsString);
assertThat(list).containsExactlyElementsOf(List.of("[email protected]", "item#123", "$data%"));
}

@ParameterizedTest
@ValueSource(strings = { "a,b,c", "1,2,3", "X,Y,Z", "alpha,beta,gamma" })
void csvWithVariousInputs(String csvString) {
List<String> result = listOutputConverter.convert(csvString);
assertThat(result).hasSize(3);
assertThat(result).doesNotContainNull();
}

@Test
void csvWithTabsAndSpecialWhitespace() {
String csvAsString = "A\t, \tB\r, \nC ";
List<String> list = listOutputConverter.convert(csvAsString);
// Behavior depends on implementation - this tests current behavior
assertThat(list).hasSize(3);
assertThat(list).doesNotContainNull();
}

@Test
void csvWithOnlySpacesAndCommas() {
String csvAsString = " , , ";
List<String> list = listOutputConverter.convert(csvAsString);
assertThat(list).containsExactlyElementsOf(List.of("", "", ""));
}

@Test
void csvWithBooleanLikeValues() {
String csvAsString = "true, false, TRUE, FALSE, yes, no";
List<String> list = listOutputConverter.convert(csvAsString);
assertThat(list).containsExactlyElementsOf(List.of("true", "false", "TRUE", "FALSE", "yes", "no"));
}

@Test
void csvWithDifferentDataTypes() {
String csvAsString = "string, 123, 45.67, true, null";
List<String> list = listOutputConverter.convert(csvAsString);
assertThat(list).containsExactlyElementsOf(List.of("string", "123", "45.67", "true", "null"));
// All values should be strings since it's a ListOutputConverter for strings
}

@Test
void csvWithAlternativeDelimiters() {
// Test behavior with semicolon (common in some locales)
String csvAsString = "A; B; C";
List<String> list = listOutputConverter.convert(csvAsString);
// This tests current behavior - might be one item if semicolon isn't supported
assertThat(list).isNotEmpty();
}

}