Skip to content

Commit ca11e0f

Browse files
committed
test(core): Improve test quality of core module
1 parent 2456c6f commit ca11e0f

File tree

8 files changed

+48
-48
lines changed

8 files changed

+48
-48
lines changed

embedding-stores/langchain4j-community-memfile/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</parent>
1010

1111
<artifactId>langchain4j-community-memfile</artifactId>
12-
<name>LangChain4j :: Community :: memfile</name>
12+
<name>LangChain4j :: Community :: Integration :: MemFile</name>
1313

1414
<dependencies>
1515
<dependency>

langchain4j-community-core/src/test/java/dev/langchain4j/community/chain/RetrievalQAChainTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void beforeEach() {
6363
}
6464

6565
@Test
66-
void should_inject_retrieved_segments() {
66+
void should_inject_retrieved_segments_when_content_available() {
6767

6868
// given
6969
when(contentRetriever.retrieve(any())).thenReturn(asList(Content.from("Segment 1"), Content.from("Segment 2")));
@@ -87,7 +87,7 @@ void should_inject_retrieved_segments() {
8787
}
8888

8989
@Test
90-
void should_inject_retrieved_segments_using_custom_prompt_template() {
90+
void should_inject_retrieved_segments_when_custom_prompt_template_used() {
9191

9292
// given
9393
when(contentRetriever.retrieve(any())).thenReturn(asList(Content.from("Segment 1"), Content.from("Segment 2")));
@@ -151,7 +151,7 @@ void should_inject_retrieved_segments_using_custom_prompt_template() {
151151
}
152152

153153
@Test
154-
void should_inject_retrieved_segments_using_custom_prompt_template_and_metadata() {
154+
void should_inject_retrieved_segments_when_custom_prompt_template_and_metadata_used() {
155155
final List<Content> list1 = List.of(
156156
Content.from(TextSegment.from("Segment 1 with meta")),
157157
Content.from(TextSegment.from("Segment 2 with meta")));
@@ -198,7 +198,7 @@ void should_inject_retrieved_segments_using_custom_prompt_template_and_metadata(
198198
}
199199

200200
@Test
201-
void should_throws_exception_if_neither_retriever_nor_retrieval_augmentor_is_defined() {
201+
void should_throw_exception_when_neither_retriever_nor_retrieval_augmentor_defined() {
202202
try {
203203
RetrievalQAChain.builder().chatModel(chatModel).build();
204204
fail("Should fail due to missing builder configurations");
@@ -208,7 +208,7 @@ void should_throws_exception_if_neither_retriever_nor_retrieval_augmentor_is_def
208208
}
209209

210210
@Test
211-
void should_throws_exception_if_retriever_is_null() {
211+
void should_throw_exception_when_retriever_is_null() {
212212
try {
213213
RetrievalQAChain.builder()
214214
.chatModel(chatModel)

langchain4j-community-core/src/test/java/dev/langchain4j/community/data/document/graph/GraphDocumentTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
class GraphDocumentTest {
1313

1414
@Test
15-
void test_equals_hash_code() {
15+
void should_return_true_when_documents_are_equal_and_false_when_not_equal() {
1616

1717
// given
1818
Document source = mock(Document.class);
@@ -38,7 +38,7 @@ void test_equals_hash_code() {
3838
}
3939

4040
@Test
41-
void test_from_all_attributes() {
41+
void should_create_graph_document_with_all_attributes_when_provided() {
4242

4343
// given
4444
GraphNode node = mock(GraphNode.class);
@@ -57,7 +57,7 @@ void test_from_all_attributes() {
5757
}
5858

5959
@Test
60-
void test_from_only_source() {
60+
void should_create_graph_document_with_empty_collections_when_only_source_provided() {
6161

6262
// given
6363
Document source = mock(Document.class);
@@ -72,15 +72,15 @@ void test_from_only_source() {
7272
}
7373

7474
@Test
75-
void test_failed_on_empty_source() {
75+
void should_throw_exception_when_source_is_null() {
7676

7777
assertThatThrownBy(() -> new GraphDocument(Set.of(), Set.of(), null))
7878
.isInstanceOf(IllegalArgumentException.class)
7979
.hasMessage("source cannot be null");
8080
}
8181

8282
@Test
83-
void test_to_string() {
83+
void should_return_string_representation_when_toString_called() {
8484

8585
// given
8686
Document source = mock(Document.class);

langchain4j-community-core/src/test/java/dev/langchain4j/community/data/document/graph/GraphEdgeTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class GraphEdgeTest {
1010

1111
@Test
12-
void test_constructor_and_getters() {
12+
void should_initialize_edge_with_all_attributes_when_constructed() {
1313
// given
1414
GraphNode source = mock(GraphNode.class);
1515
GraphNode target = mock(GraphNode.class);
@@ -27,7 +27,7 @@ void test_constructor_and_getters() {
2727
}
2828

2929
@Test
30-
void test_copyIfNotNull_behavior_in_constructor() {
30+
void should_create_empty_properties_map_when_properties_are_null() {
3131
// given
3232
GraphNode source = mock(GraphNode.class);
3333
GraphNode target = mock(GraphNode.class);
@@ -41,7 +41,7 @@ void test_copyIfNotNull_behavior_in_constructor() {
4141
}
4242

4343
@Test
44-
void test_from_with_properties() {
44+
void should_create_edge_with_properties_when_using_from_method() {
4545
// given
4646
GraphNode source = mock(GraphNode.class);
4747
GraphNode target = mock(GraphNode.class);
@@ -59,7 +59,7 @@ void test_from_with_properties() {
5959
}
6060

6161
@Test
62-
void test_from_without_properties() {
62+
void should_create_edge_with_empty_properties_when_using_from_method_without_properties() {
6363
// given
6464
GraphNode source = mock(GraphNode.class);
6565
GraphNode target = mock(GraphNode.class);
@@ -76,7 +76,7 @@ void test_from_without_properties() {
7676
}
7777

7878
@Test
79-
void test_equals_and_hashcode() {
79+
void should_return_true_when_edges_are_equal_and_false_when_not_equal() {
8080
// given
8181
GraphNode source = mock(GraphNode.class);
8282
GraphNode target = mock(GraphNode.class);
@@ -94,7 +94,7 @@ void test_equals_and_hashcode() {
9494
}
9595

9696
@Test
97-
void test_to_string_contains_all_fields() {
97+
void should_return_string_representation_containing_all_fields_when_toString_called() {
9898
// given
9999
GraphNode source = mock(GraphNode.class);
100100
GraphNode target = mock(GraphNode.class);

langchain4j-community-core/src/test/java/dev/langchain4j/community/data/document/graph/GraphNodeTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class GraphNodeTest {
99

1010
@Test
11-
void test_constructor_and_getters() {
11+
void should_initialize_node_with_all_attributes_when_constructed() {
1212
// given
1313
String id = "node1";
1414
String type = "Person";
@@ -24,7 +24,7 @@ void test_constructor_and_getters() {
2424
}
2525

2626
@Test
27-
void test_constructor_with_null_type_and_properties() {
27+
void should_use_default_values_when_type_and_properties_are_null() {
2828
// given
2929
String id = "node2";
3030

@@ -38,7 +38,7 @@ void test_constructor_with_null_type_and_properties() {
3838
}
3939

4040
@Test
41-
void test_static_factory_method_with_all_fields() {
41+
void should_create_node_with_all_fields_when_using_from_method() {
4242
// given
4343
String id = "node3";
4444
String type = "City";
@@ -54,7 +54,7 @@ void test_static_factory_method_with_all_fields() {
5454
}
5555

5656
@Test
57-
void test_static_factory_method_with_only_id() {
57+
void should_create_node_with_default_type_and_empty_properties_when_using_from_method_with_only_id() {
5858
// given
5959
String id = "node4";
6060

@@ -68,7 +68,7 @@ void test_static_factory_method_with_only_id() {
6868
}
6969

7070
@Test
71-
void test_equals_and_hashcode() {
71+
void should_return_true_when_nodes_are_equal_and_false_when_not_equal() {
7272
// given
7373
Map<String, String> props = Map.of("k", "v");
7474

@@ -88,7 +88,7 @@ void test_equals_and_hashcode() {
8888
}
8989

9090
@Test
91-
void test_to_string_contains_all_fields() {
91+
void should_return_string_representation_containing_all_fields_when_toString_called() {
9292
// given
9393
GraphNode node = new GraphNode("id123", "Label", Map.of("x", "y"));
9494

langchain4j-community-core/src/test/java/dev/langchain4j/community/data/document/transformer/graph/GraphTransformerTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public GraphDocument transform(Document document) {
2525
}
2626

2727
@Test
28-
void should_return_empty_when_null() {
28+
void should_return_empty_list_when_input_is_null() {
2929
GraphTransformer graphTransformer = new MockGraphTransformer();
3030

3131
// when
@@ -36,7 +36,7 @@ void should_return_empty_when_null() {
3636
}
3737

3838
@Test
39-
void should_return_empty_when_empty() {
39+
void should_return_empty_list_when_input_is_empty() {
4040
GraphTransformer graphTransformer = new MockGraphTransformer();
4141

4242
// when
@@ -47,7 +47,7 @@ void should_return_empty_when_empty() {
4747
}
4848

4949
@Test
50-
void should_return_transformed_documents() {
50+
void should_return_transformed_documents_when_input_provided() {
5151
GraphTransformer graphTransformer = new MockGraphTransformer();
5252

5353
// given

langchain4j-community-core/src/test/java/dev/langchain4j/community/embedding/ParentChildEmbeddingStoreIngestorTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
import java.util.stream.Stream;
2828
import org.junit.jupiter.api.Test;
2929

30-
public class ParentChildEmbeddingStoreIngestorTest {
30+
class ParentChildEmbeddingStoreIngestorTest {
3131

3232
@Test
33-
void should_extract_text_then_split_into_segments_then_embed_them_and_store_in_embedding_store() {
33+
void should_extract_text_split_into_segments_embed_them_and_store_in_embedding_store() {
3434

3535
Document firstDocument = Document.from("First sentence.");
3636
Document secondDocument = Document.from("Second sentence. Third sentence.");
@@ -217,7 +217,7 @@ void should_extract_text_then_split_into_segments_then_embed_them_and_store_in_e
217217
}
218218

219219
@Test
220-
void should_not_split_when_no_splitter_is_specified() {
220+
void should_not_split_when_no_splitter_specified() {
221221

222222
// given
223223
String text = "Some text";

0 commit comments

Comments
 (0)