diff --git a/jnosql-communication/jnosql-communication-column/src/test/java/org/eclipse/jnosql/communication/column/DefaultColumnDeleteQueryTest.java b/jnosql-communication/jnosql-communication-column/src/test/java/org/eclipse/jnosql/communication/column/DefaultColumnDeleteQueryTest.java index f6c6285c4..603974700 100644 --- a/jnosql-communication/jnosql-communication-column/src/test/java/org/eclipse/jnosql/communication/column/DefaultColumnDeleteQueryTest.java +++ b/jnosql-communication/jnosql-communication-column/src/test/java/org/eclipse/jnosql/communication/column/DefaultColumnDeleteQueryTest.java @@ -22,6 +22,7 @@ import java.util.List; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -36,11 +37,25 @@ public void setUp() { } @Test - public void shouldNotEditColumns() { + void shouldNotEditColumns() { Assertions.assertThrows(UnsupportedOperationException.class, () -> { List columns = query.columns(); assertTrue(columns.isEmpty()); columns.clear(); }); } + + @Test + void shouldHasCode(){ + var query =ColumnDeleteQuery.delete().from("columnFamily").build(); + var query1 =ColumnDeleteQuery.delete().from("columnFamily").build(); + assertThat(query.hashCode()).isEqualTo(query1.hashCode()); + } + + @Test + void shouldEquals(){ + var query =ColumnDeleteQuery.delete().from("columnFamily").build(); + var query1 =ColumnDeleteQuery.delete().from("columnFamily").build(); + assertThat(query).isEqualTo(query1); + } } \ No newline at end of file diff --git a/jnosql-communication/jnosql-communication-column/src/test/java/org/eclipse/jnosql/communication/column/DefaultColumnQueryTest.java b/jnosql-communication/jnosql-communication-column/src/test/java/org/eclipse/jnosql/communication/column/DefaultColumnQueryTest.java index b38600e3b..2d55cbbc2 100644 --- a/jnosql-communication/jnosql-communication-column/src/test/java/org/eclipse/jnosql/communication/column/DefaultColumnQueryTest.java +++ b/jnosql-communication/jnosql-communication-column/src/test/java/org/eclipse/jnosql/communication/column/DefaultColumnQueryTest.java @@ -39,7 +39,7 @@ public void setUp() { } @Test - public void shouldNotRemoveColumns() { + void shouldNotRemoveColumns() { Assertions.assertThrows(UnsupportedOperationException.class, () -> { List columns = query.columns(); assertTrue(columns.isEmpty()); @@ -48,7 +48,7 @@ public void shouldNotRemoveColumns() { } @Test - public void shouldNotRemoveSort() { + void shouldNotRemoveSort() { Assertions.assertThrows(UnsupportedOperationException.class, () -> { List sorts = query.sorts(); assertTrue(sorts.isEmpty()); @@ -57,7 +57,7 @@ public void shouldNotRemoveSort() { } @Test - public void shouldConvertCountyBy() { + void shouldConvertCountyBy() { ColumnQuery query = ColumnQuery.select().from("entity") .where("name").eq("predicate") .orderBy("name").asc().build(); @@ -73,7 +73,7 @@ public void shouldConvertCountyBy() { } @Test - public void shouldConvertExistsBy() { + void shouldConvertExistsBy() { ColumnQuery query = ColumnQuery.select().from("entity") .where("name").eq("predicate") .orderBy("name").asc().build(); @@ -87,4 +87,28 @@ public void shouldConvertExistsBy() { ColumnCondition condition = countQuery.condition().orElseThrow(); Assertions.assertEquals(Condition.EQUALS, condition.condition()); } + + @Test + void shouldHasCode(){ + ColumnQuery query = ColumnQuery.select().from("entity") + .where("name").eq("predicate") + .orderBy("name").asc().build(); + ColumnQuery query2 = ColumnQuery.select().from("entity") + .where("name").eq("predicate") + .orderBy("name").asc().build(); + + Assertions.assertEquals(query.hashCode(), query2.hashCode()); + } + + @Test + void shouldEquals(){ + ColumnQuery query = ColumnQuery.select().from("entity") + .where("name").eq("predicate") + .orderBy("name").asc().build(); + ColumnQuery query2 = ColumnQuery.select().from("entity") + .where("name").eq("predicate") + .orderBy("name").asc().build(); + + Assertions.assertEquals(query, query2); + } } \ No newline at end of file diff --git a/jnosql-communication/jnosql-communication-core/src/test/java/org/eclipse/jnosql/communication/DefaultValueTest.java b/jnosql-communication/jnosql-communication-core/src/test/java/org/eclipse/jnosql/communication/DefaultValueTest.java index f58ac8f23..5036b7c65 100644 --- a/jnosql-communication/jnosql-communication-core/src/test/java/org/eclipse/jnosql/communication/DefaultValueTest.java +++ b/jnosql-communication/jnosql-communication-core/src/test/java/org/eclipse/jnosql/communication/DefaultValueTest.java @@ -18,6 +18,7 @@ */ package org.eclipse.jnosql.communication; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -164,4 +165,18 @@ void shouldConvertMapIgnoringKeyValue() { }).isInstanceOf(UnsupportedOperationException.class) .hasMessage("The type TypeReference{type=java.util.Map>} is not supported"); } + + @Test + void shouldHasCode(){ + var value = Value.of(asList(10, 20, 30)); + var valueB = Value.of(asList(10, 20, 30)); + Assertions.assertThat(value.hashCode()).isEqualTo(valueB.hashCode()); + } + + @Test + void shouldEquals(){ + var value = Value.of(asList(10, 20, 30)); + var valueB = Value.of(asList(10, 20, 30)); + Assertions.assertThat(value).isEqualTo(valueB); + } } diff --git a/jnosql-communication/jnosql-communication-document/src/test/java/org/eclipse/jnosql/communication/document/DefaultDocumentDeleteQueryTest.java b/jnosql-communication/jnosql-communication-document/src/test/java/org/eclipse/jnosql/communication/document/DefaultDocumentDeleteQueryTest.java index 36fac3bbe..efdb0a97d 100644 --- a/jnosql-communication/jnosql-communication-document/src/test/java/org/eclipse/jnosql/communication/document/DefaultDocumentDeleteQueryTest.java +++ b/jnosql-communication/jnosql-communication-document/src/test/java/org/eclipse/jnosql/communication/document/DefaultDocumentDeleteQueryTest.java @@ -23,6 +23,8 @@ import java.util.List; +import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.jnosql.communication.document.DocumentDeleteQuery.delete; import static org.junit.jupiter.api.Assertions.assertTrue; public class DefaultDocumentDeleteQueryTest { @@ -32,16 +34,32 @@ public class DefaultDocumentDeleteQueryTest { @BeforeEach - public void setUp() { - query = DocumentDeleteQuery.delete().from("columnFamily").build(); + void setUp() { + query = delete().from("columnFamily").build(); } @Test - public void shouldNotEditColumns() { + void shouldNotEditColumns() { Assertions.assertThrows(UnsupportedOperationException.class, () -> { List documents = query.documents(); assertTrue(documents.isEmpty()); documents.clear(); }); } + + @Test + void shouldGenerateEquals() { + DocumentDeleteQuery query = delete().from("columnFamily").build(); + DocumentDeleteQuery query2 = delete().from("columnFamily").build(); + + assertThat(query).isEqualTo(query2); + } + + @Test + void shouldGenerateHashCode() { + DocumentDeleteQuery query = delete().from("columnFamily").build(); + DocumentDeleteQuery query2 = delete().from("columnFamily").build(); + + assertThat(query.hashCode()).isEqualTo(query2.hashCode()); + } } diff --git a/jnosql-communication/jnosql-communication-document/src/test/java/org/eclipse/jnosql/communication/document/DefaultDocumentQueryTest.java b/jnosql-communication/jnosql-communication-document/src/test/java/org/eclipse/jnosql/communication/document/DefaultDocumentQueryTest.java index ce2eec127..8c387dcfd 100644 --- a/jnosql-communication/jnosql-communication-document/src/test/java/org/eclipse/jnosql/communication/document/DefaultDocumentQueryTest.java +++ b/jnosql-communication/jnosql-communication-document/src/test/java/org/eclipse/jnosql/communication/document/DefaultDocumentQueryTest.java @@ -24,6 +24,7 @@ import java.util.List; +import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.jnosql.communication.document.DocumentQuery.select; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -42,7 +43,7 @@ public void setUp() { @Test - public void shouldNotRemoveColumns() { + void shouldNotRemoveColumns() { Assertions.assertThrows(UnsupportedOperationException.class, () -> { List columns = query.documents(); assertTrue(columns.isEmpty()); @@ -52,7 +53,7 @@ public void shouldNotRemoveColumns() { @Test - public void shouldNotRemoveSort() { + void shouldNotRemoveSort() { Assertions.assertThrows(UnsupportedOperationException.class, () -> { List sorts = query.sorts(); assertTrue(sorts.isEmpty()); @@ -61,7 +62,7 @@ public void shouldNotRemoveSort() { } @Test - public void shouldConvertCountyBy() { + void shouldConvertCountyBy() { DocumentQuery query = DocumentQuery.select().from("entity") .where("name").eq("predicate") .orderBy("name").asc().build(); @@ -77,7 +78,7 @@ public void shouldConvertCountyBy() { } @Test - public void shouldConvertExistsBy() { + void shouldConvertExistsBy() { DocumentQuery query = DocumentQuery.select().from("entity") .where("name").eq("predicate") .orderBy("name").asc().build(); @@ -91,4 +92,30 @@ public void shouldConvertExistsBy() { DocumentCondition condition = countQuery.condition().orElseThrow(); Assertions.assertEquals(Condition.EQUALS, condition.condition()); } + + @Test + void shouldGenerateEquals(){ + DocumentQuery query = DocumentQuery.select().from("entity") + .where("name").eq("predicate") + .orderBy("name").asc().build(); + + DocumentQuery query2 = DocumentQuery.select().from("entity") + .where("name").eq("predicate") + .orderBy("name").asc().build(); + + assertThat(query).isEqualTo(query2); + } + + @Test + void shouldGenerateHashCode(){ + DocumentQuery query = DocumentQuery.select().from("entity") + .where("name").eq("predicate") + .orderBy("name").asc().build(); + + DocumentQuery query2 = DocumentQuery.select().from("entity") + .where("name").eq("predicate") + .orderBy("name").asc().build(); + + assertThat(query.hashCode()).isEqualTo(query2.hashCode()); + } } \ No newline at end of file diff --git a/jnosql-communication/jnosql-communication-document/src/test/java/org/eclipse/jnosql/communication/document/DocumentEntityTest.java b/jnosql-communication/jnosql-communication-document/src/test/java/org/eclipse/jnosql/communication/document/DocumentEntityTest.java index 5b8cdbab5..1e3c6df50 100644 --- a/jnosql-communication/jnosql-communication-document/src/test/java/org/eclipse/jnosql/communication/document/DocumentEntityTest.java +++ b/jnosql-communication/jnosql-communication-document/src/test/java/org/eclipse/jnosql/communication/document/DocumentEntityTest.java @@ -41,17 +41,17 @@ public class DocumentEntityTest { @Test - public void shouldReturnErrorWhenNameIsNull() { + void shouldReturnErrorWhenNameIsNull() { Assertions.assertThrows(NullPointerException.class, () -> DocumentEntity.of(null)); } @Test - public void shouldReturnErrorWhenDocumentsIsNull() { + void shouldReturnErrorWhenDocumentsIsNull() { Assertions.assertThrows(NullPointerException.class, () -> DocumentEntity.of("entity", null)); } @Test - public void shouldReturnOneDocument() { + void shouldReturnOneDocument() { DocumentEntity entity = DocumentEntity.of("entity"); assertEquals(Integer.valueOf(0), Integer.valueOf(entity.size())); assertTrue(entity.isEmpty()); @@ -64,7 +64,7 @@ public void shouldReturnOneDocument() { } @Test - public void shouldDoCopy() { + void shouldDoCopy() { DocumentEntity entity = DocumentEntity.of("entity", singletonList(Document.of("name", "name"))); DocumentEntity copy = entity.copy(); assertNotSame(entity, copy); @@ -73,7 +73,7 @@ public void shouldDoCopy() { } @Test - public void shouldFindDocument() { + void shouldFindDocument() { Document document = Document.of("name", "name"); DocumentEntity entity = DocumentEntity.of("entity", singletonList(document)); Optional name = entity.find("name"); @@ -84,7 +84,7 @@ public void shouldFindDocument() { } @Test - public void shouldReturnErrorWhenFindDocumentIsNull() { + void shouldReturnErrorWhenFindDocumentIsNull() { Assertions.assertThrows(NullPointerException.class, () -> { Document document = Document.of("name", "name"); DocumentEntity entity = DocumentEntity.of("entity", singletonList(document)); @@ -93,7 +93,7 @@ public void shouldReturnErrorWhenFindDocumentIsNull() { } @Test - public void shouldRemoveDocumentByName() { + void shouldRemoveDocumentByName() { Document document = Document.of("name", "name"); DocumentEntity entity = DocumentEntity.of("entity", singletonList(document)); assertTrue(entity.remove("name")); @@ -101,7 +101,7 @@ public void shouldRemoveDocumentByName() { } @Test - public void shouldConvertToMap() { + void shouldConvertToMap() { Document document = Document.of("name", "name"); DocumentEntity entity = DocumentEntity.of("entity", singletonList(document)); Map result = entity.toMap(); @@ -112,7 +112,7 @@ public void shouldConvertToMap() { } @Test - public void shouldConvertSubColumnToMap() { + void shouldConvertSubColumnToMap() { Document document = Document.of("name", "name"); DocumentEntity entity = DocumentEntity.of("entity", singletonList(Document.of("sub", document))); Map result = entity.toMap(); @@ -123,7 +123,7 @@ public void shouldConvertSubColumnToMap() { } @Test - public void shouldConvertSubDocumentListToMap() { + void shouldConvertSubDocumentListToMap() { DocumentEntity entity = DocumentEntity.of("entity"); entity.add(Document.of("_id", "id")); List documents = asList(Document.of("name", "Ada"), Document.of("type", "type"), @@ -140,7 +140,7 @@ public void shouldConvertSubDocumentListToMap() { } @Test - public void shouldConvertSubDocumentListToMap2() { + void shouldConvertSubDocumentListToMap2() { DocumentEntity entity = DocumentEntity.of("entity"); entity.add(Document.of("_id", "id")); List> documents = new ArrayList<>(); @@ -160,20 +160,20 @@ public void shouldConvertSubDocumentListToMap2() { } @Test - public void shouldShouldCreateANewInstance() { + void shouldShouldCreateANewInstance() { String name = "name"; DocumentEntity entity = new DocumentEntity(name); assertEquals(name, entity.name()); } @Test - public void shouldCreateAnEmptyEntity() { + void shouldCreateAnEmptyEntity() { DocumentEntity entity = new DocumentEntity("name"); assertTrue(entity.isEmpty()); } @Test - public void shouldReturnAnErrorWhenAddANullDocument() { + void shouldReturnAnErrorWhenAddANullDocument() { Assertions.assertThrows(NullPointerException.class, () -> { DocumentEntity entity = new DocumentEntity("name"); entity.add(null); @@ -181,7 +181,7 @@ public void shouldReturnAnErrorWhenAddANullDocument() { } @Test - public void shouldAddANewDocument() { + void shouldAddANewDocument() { DocumentEntity entity = new DocumentEntity("name"); entity.add(Document.of("document", 12)); assertFalse(entity.isEmpty()); @@ -189,7 +189,7 @@ public void shouldAddANewDocument() { } @Test - public void shouldReturnErrorWhenAddAnNullIterable() { + void shouldReturnErrorWhenAddAnNullIterable() { Assertions.assertThrows(NullPointerException.class, () -> { DocumentEntity entity = new DocumentEntity("name"); entity.addAll(null); @@ -197,7 +197,7 @@ public void shouldReturnErrorWhenAddAnNullIterable() { } @Test - public void shouldAddAllDocuments() { + void shouldAddAllDocuments() { DocumentEntity entity = new DocumentEntity("name"); entity.addAll(asList(Document.of("name", 12), Document.of("value", "value"))); assertFalse(entity.isEmpty()); @@ -206,14 +206,14 @@ public void shouldAddAllDocuments() { @Test - public void shouldNotFindDocument() { + void shouldNotFindDocument() { DocumentEntity entity = new DocumentEntity("name"); Optional document = entity.find("name"); assertFalse(document.isPresent()); } @Test - public void shouldFindValue() { + void shouldFindValue() { Document document = Document.of("name", "name"); DocumentEntity entity = DocumentEntity.of("entity", singletonList(document)); Optional name = entity.find("name", String.class); @@ -223,7 +223,7 @@ public void shouldFindValue() { } @Test - public void shouldNotFindValue() { + void shouldNotFindValue() { Document document = Document.of("name", "name"); DocumentEntity entity = DocumentEntity.of("entity", singletonList(document)); Optional name = entity.find("not_found", String.class); @@ -232,7 +232,7 @@ public void shouldNotFindValue() { } @Test - public void shouldFindTypeSupplier() { + void shouldFindTypeSupplier() { Document document = Document.of("name", "name"); DocumentEntity entity = DocumentEntity.of("entity", singletonList(document)); List names = entity.find("name", new TypeReference>() {}) @@ -243,7 +243,7 @@ public void shouldFindTypeSupplier() { } @Test - public void shouldNotFindTypeSupplier() { + void shouldNotFindTypeSupplier() { Document document = Document.of("name", "name"); DocumentEntity entity = DocumentEntity.of("entity", singletonList(document)); List names = entity.find("not_find", new TypeReference>() {}) @@ -253,7 +253,7 @@ public void shouldNotFindTypeSupplier() { } @Test - public void shouldRemoveByName() { + void shouldRemoveByName() { DocumentEntity entity = new DocumentEntity("name"); entity.add(Document.of("value", 32D)); assertTrue(entity.remove("value")); @@ -261,7 +261,7 @@ public void shouldRemoveByName() { } @Test - public void shouldNotRemoveByName() { + void shouldNotRemoveByName() { DocumentEntity entity = new DocumentEntity("name"); entity.add(Document.of("value", 32D)); @@ -270,7 +270,7 @@ public void shouldNotRemoveByName() { } @Test - public void shouldReturnErrorWhenRemoveByNameIsNull() { + void shouldReturnErrorWhenRemoveByNameIsNull() { Assertions.assertThrows(NullPointerException.class, () -> { DocumentEntity entity = new DocumentEntity("name"); entity.remove(null); @@ -279,7 +279,7 @@ public void shouldReturnErrorWhenRemoveByNameIsNull() { @Test - public void shouldAddDocumentAsNameAndObject() { + void shouldAddDocumentAsNameAndObject() { DocumentEntity entity = new DocumentEntity("documentCollection"); entity.add("name", 10); assertEquals(1, entity.size()); @@ -289,7 +289,7 @@ public void shouldAddDocumentAsNameAndObject() { } @Test - public void shouldAddDocumentAsNameAndValue() { + void shouldAddDocumentAsNameAndValue() { DocumentEntity entity = new DocumentEntity("documentCollection"); entity.add("name", Value.of(10)); assertEquals(1, entity.size()); @@ -299,7 +299,7 @@ public void shouldAddDocumentAsNameAndValue() { } @Test - public void shouldReturnErrorWhenAddDocumentsObjectWhenHasNullObject() { + void shouldReturnErrorWhenAddDocumentsObjectWhenHasNullObject() { Assertions.assertThrows(NullPointerException.class, () -> { DocumentEntity entity = new DocumentEntity("documentCollection"); entity.add("name", null); @@ -307,7 +307,7 @@ public void shouldReturnErrorWhenAddDocumentsObjectWhenHasNullObject() { } @Test - public void shouldReturnErrorWhenAddDocumentsObjectWhenHasNullDocumentName() { + void shouldReturnErrorWhenAddDocumentsObjectWhenHasNullDocumentName() { Assertions.assertThrows(NullPointerException.class, () -> { DocumentEntity entity = new DocumentEntity("documentCollection"); entity.add(null, 10); @@ -315,7 +315,7 @@ public void shouldReturnErrorWhenAddDocumentsObjectWhenHasNullDocumentName() { } @Test - public void shouldReturnErrorWhenAddDocumentsValueWhenHasNullDocumentName() { + void shouldReturnErrorWhenAddDocumentsValueWhenHasNullDocumentName() { Assertions.assertThrows(NullPointerException.class, () -> { DocumentEntity entity = new DocumentEntity("documentCollection"); entity.add(null, Value.of(12)); @@ -324,7 +324,7 @@ public void shouldReturnErrorWhenAddDocumentsValueWhenHasNullDocumentName() { @Test - public void shouldAvoidDuplicatedDocument() { + void shouldAvoidDuplicatedDocument() { DocumentEntity entity = new DocumentEntity("documentCollection"); entity.add("name", 10); entity.add("name", 13); @@ -334,7 +334,7 @@ public void shouldAvoidDuplicatedDocument() { } @Test - public void shouldAvoidDuplicatedDocumentWhenAddList() { + void shouldAvoidDuplicatedDocumentWhenAddList() { List documents = asList(Document.of("name", 10), Document.of("name", 13)); DocumentEntity entity = new DocumentEntity("documentCollection"); entity.addAll(documents); @@ -343,7 +343,7 @@ public void shouldAvoidDuplicatedDocumentWhenAddList() { } @Test - public void shouldReturnsTheDocumentNames() { + void shouldReturnsTheDocumentNames() { List documents = asList(Document.of("name", 10), Document.of("name2", 11), Document.of("name3", 12), Document.of("name4", 13), Document.of("name5", 14), Document.of("name5", 16)); @@ -354,7 +354,7 @@ public void shouldReturnsTheDocumentNames() { } @Test - public void shouldReturnsTheDocumentValues() { + void shouldReturnsTheDocumentValues() { List documents = asList(Document.of("name", 10), Document.of("name2", 11), Document.of("name3", 12), Document.of("name4", 13), Document.of("name5", 14), Document.of("name5", 16)); @@ -365,7 +365,7 @@ public void shouldReturnsTheDocumentValues() { } @Test - public void shouldReturnTrueWhenContainsElement() { + void shouldReturnTrueWhenContainsElement() { List documents = asList(Document.of("name", 10), Document.of("name2", 11), Document.of("name3", 12), Document.of("name4", 13), Document.of("name5", 14), Document.of("name5", 16)); @@ -380,7 +380,7 @@ public void shouldReturnTrueWhenContainsElement() { } @Test - public void shouldReturnFalseWhenDoesNotContainElement() { + void shouldReturnFalseWhenDoesNotContainElement() { List documents = asList(Document.of("name", 10), Document.of("name2", 11), Document.of("name3", 12), Document.of("name4", 13), Document.of("name5", 14), Document.of("name5", 16)); @@ -395,7 +395,7 @@ public void shouldReturnFalseWhenDoesNotContainElement() { } @Test - public void shouldRemoveAllElementsWhenUseClearMethod() { + void shouldRemoveAllElementsWhenUseClearMethod() { List documents = asList(Document.of("name", 10), Document.of("name2", 11), Document.of("name3", 12), Document.of("name4", 13), Document.of("name5", 14), Document.of("name5", 16)); @@ -407,4 +407,28 @@ public void shouldRemoveAllElementsWhenUseClearMethod() { assertTrue(collection.isEmpty()); } + @Test + void shouldHashCode(){ + List documents = List.of(Document.of("name", 10)); + var collection = DocumentEntity.of("documentCollection", documents); + var collection2 = DocumentEntity.of("documentCollection", documents); + assertThat(collection.hashCode()).isEqualTo(collection2.hashCode()); + } + + @Test + void shouldEquals(){ + List documents = List.of(Document.of("name", 10)); + var collection = DocumentEntity.of("documentCollection", documents); + var collection2 = DocumentEntity.of("documentCollection", documents); + assertThat(collection).isEqualTo(collection2); + } + + @Test + void shouldToString(){ + List documents = List.of(Document.of("name", 10)); + var collection = DocumentEntity.of("documentCollection", documents); + assertThat(collection.toString()).isEqualTo("DefaultDocumentEntity{documents={name=DefaultDocument" + + "[name=name, value=DefaultValue[value=10]]}, name='documentCollection'}"); + } + } \ No newline at end of file diff --git a/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/BooleanQueryValue.java b/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/BooleanQueryValue.java index 14cfeb496..9bd080c7d 100644 --- a/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/BooleanQueryValue.java +++ b/jnosql-communication/jnosql-communication-query/src/main/java/org/eclipse/jnosql/communication/query/BooleanQueryValue.java @@ -67,7 +67,7 @@ public String toString() { public static QueryValue of(QueryParser.BoolContext context) { String text = context.BOOLEAN().getText(); - return new BooleanQueryValue(Boolean.parseBoolean(text)); + return Boolean.parseBoolean(text)? TRUE : FALSE; } } diff --git a/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/DefaultArrayQueryValueTest.java b/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/DefaultArrayQueryValueTest.java index dae87ba14..210d1896e 100644 --- a/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/DefaultArrayQueryValueTest.java +++ b/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/DefaultArrayQueryValueTest.java @@ -19,7 +19,7 @@ class DefaultArrayQueryValueTest { @Test - public void shouldReturnArrayType() { + void shouldReturnArrayType() { ArrayQueryValue array = DefaultArrayQueryValue.of(new QueryValue[]{ BooleanQueryValue.FALSE}); assertThat(array).isNotNull(); @@ -28,14 +28,14 @@ public void shouldReturnArrayType() { } @Test - public void shouldReturnArrayValue() { + void shouldReturnArrayValue() { ArrayQueryValue array = DefaultArrayQueryValue.of(new QueryValue[]{ BooleanQueryValue.FALSE, BooleanQueryValue.TRUE}); assertThat(array.get()).containsExactly(BooleanQueryValue.FALSE, BooleanQueryValue.TRUE); } @Test - public void shouldEquals(){ + void shouldEquals(){ ArrayQueryValue array = DefaultArrayQueryValue.of(new QueryValue[]{ BooleanQueryValue.FALSE, BooleanQueryValue.TRUE}); ArrayQueryValue arrayB = DefaultArrayQueryValue.of(new QueryValue[]{ @@ -44,11 +44,18 @@ public void shouldEquals(){ } @Test - public void shouldHashCode(){ + void shouldHashCode(){ ArrayQueryValue array = DefaultArrayQueryValue.of(new QueryValue[]{ BooleanQueryValue.FALSE, BooleanQueryValue.TRUE}); ArrayQueryValue arrayB = DefaultArrayQueryValue.of(new QueryValue[]{ BooleanQueryValue.FALSE, BooleanQueryValue.TRUE}); Assertions.assertEquals(arrayB.hashCode(), array.hashCode()); } + + @Test + void shouldToString(){ + ArrayQueryValue array = DefaultArrayQueryValue.of(new QueryValue[]{ + BooleanQueryValue.FALSE, BooleanQueryValue.TRUE}); + assertThat(array.toString()).isEqualTo("[BooleanQueryValue{value=false}, BooleanQueryValue{value=true}]"); + } } \ No newline at end of file diff --git a/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/DefaultFunctionTest.java b/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/DefaultFunctionTest.java index 2664e589c..e087afa7e 100644 --- a/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/DefaultFunctionTest.java +++ b/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/DefaultFunctionTest.java @@ -20,7 +20,7 @@ class DefaultFunctionTest { @Test - public void shouldReturnType() { + void shouldReturnType() { Function function = DefaultFunction.of("sum", new Object[]{1, 2}); assertThat(function).isNotNull() .extracting(Function::name).isEqualTo("sum"); @@ -29,23 +29,29 @@ public void shouldReturnType() { } @Test - public void shouldReturnValue(){ + void shouldReturnValue(){ Function function = DefaultFunction.of("sum", new Object[]{1, 2}); assertThat(function).extracting(Function::params) .isEqualTo(new Object[]{1, 2}); } @Test - public void shouldReturnEquals(){ + void shouldReturnEquals(){ Function f = DefaultFunction.of("sum", new Object[]{1, 2}); Function f2 = DefaultFunction.of("sum", new Object[]{1, 2}); assertEquals(f, f2); } @Test - public void shouldReturnHashCode() { + void shouldReturnHashCode() { Function f = DefaultFunction.of("sum", new Object[]{1, 2}); Function f2 = DefaultFunction.of("sum", new Object[]{1, 2}); assertEquals(f.hashCode(), f2.hashCode()); } + + @Test + void shouldToString(){ + var f = DefaultFunction.of("sum", new Object[]{1, 2}); + assertEquals("sum([1, 2])", f.toString()); + } } \ No newline at end of file diff --git a/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/DeleteQueryTest.java b/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/DeleteQueryTest.java new file mode 100644 index 000000000..ee3c35bfc --- /dev/null +++ b/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/DeleteQueryTest.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and Apache License v2.0 which accompanies this distribution. + * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html + * and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. + * You may elect to redistribute this code under either of these licenses. + * Contributors: + * Otavio Santana + */ +package org.eclipse.jnosql.communication.query; + +import org.eclipse.jnosql.communication.Condition; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.Arrays; + +import static org.junit.jupiter.api.Assertions.*; + +class DeleteQueryTest { + + private Where where; + + @BeforeEach + void setUp() { + QueryCondition condition = new DefaultQueryCondition("name", Condition.EQUALS, BooleanQueryValue.TRUE); + where = new Where(condition); + } + @Test + void shouldDeleteQueryEquality() { + DeleteQuery query1 = DeleteQuery.of("Entity1", Arrays.asList("field1", "field2"), where); + DeleteQuery query2 = DeleteQuery.of("Entity1", Arrays.asList("field1", "field2"), where); + DeleteQuery query3 = DeleteQuery.of("Entity2", Arrays.asList("field1", "field2"), where); + + // Test equality + assertEquals(query1, query2); + assertNotEquals(query1, query3); + } + + @Test + void shouldDeleteQueryHashcode() { + DeleteQuery query1 = DeleteQuery.of("Entity1", Arrays.asList("field1", "field2"), where); + DeleteQuery query2 = DeleteQuery.of("Entity1", Arrays.asList("field1", "field2"), where); + DeleteQuery query3 = DeleteQuery.of("Entity2", Arrays.asList("field1", "field2"), where); + + assertEquals(query1.hashCode(), query2.hashCode()); + assertNotEquals(query1.hashCode(), query3.hashCode()); + } + + @Test + void shouldDeleteQueryToString() { + DeleteQuery query = DeleteQuery.of("Entity1", Arrays.asList("field1", "field2"), where); + assertEquals("DeleteQuery{entity='Entity1', fields=[field1, field2], where=where name EQUALS BooleanQueryValue{value=true}}", query.toString()); + } + + @Test + void shouldCreateDeleteQueryWithEmptyFields() { + DeleteQuery query = DeleteQuery.of("Entity1", where); + + // Test that fields are empty + assertTrue(query.fields().isEmpty()); + } + + @Test + void shouldCreateDeleteQueryWithNullEntity() { + // Test NullPointerException when entity is null + assertThrows(NullPointerException.class, () -> DeleteQuery.of(null, Arrays.asList("field1", "field2"), where)); + } + + @Test + void shouldCreateDeleteQueryWithNullFields() { + // Test NullPointerException when fields is null + assertThrows(NullPointerException.class, () -> DeleteQuery.of("Entity1", null, where)); + } + + @Test + void shouldCreateDeleteQueryWithNullWhere() { + // Test creating DeleteQuery with null Where + DeleteQuery query = DeleteQuery.of("Entity1", Arrays.asList("field1", "field2"), null); + + // Test that where is empty + assertFalse(query.where().isPresent()); + } +} \ No newline at end of file diff --git a/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/FunctionQueryValueTest.java b/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/FunctionQueryValueTest.java index 609c60b4f..98898efc8 100644 --- a/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/FunctionQueryValueTest.java +++ b/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/FunctionQueryValueTest.java @@ -11,6 +11,7 @@ */ package org.eclipse.jnosql.communication.query; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -27,7 +28,7 @@ public void setUp() { } @Test - public void shouldReturnFunctionType() { + void shouldReturnFunctionType() { FunctionQueryValue queryValue = new FunctionQueryValue(function); assertThat(queryValue).isNotNull(); assertThat(queryValue).extracting(FunctionQueryValue::type) @@ -35,7 +36,7 @@ public void shouldReturnFunctionType() { } @Test - public void shouldReturnValue() { + void shouldReturnValue() { FunctionQueryValue queryValue = new FunctionQueryValue(function); assertThat(queryValue).isNotNull(); assertThat(queryValue).extracting(FunctionQueryValue::get) @@ -43,15 +44,21 @@ public void shouldReturnValue() { } @Test - public void shouldEquals() { + void shouldEquals() { FunctionQueryValue queryValue = new FunctionQueryValue(function); assertEquals(queryValue, new FunctionQueryValue(function)); } @Test - public void shouldHashCode() { + void shouldHashCode() { FunctionQueryValue queryValue = new FunctionQueryValue(function); assertEquals(queryValue.hashCode(), new FunctionQueryValue(function).hashCode()); } + + @Test + void shouldToString(){ + var queryValue = new FunctionQueryValue(function); + Assertions.assertEquals(queryValue.toString(), function.toString()); + } } \ No newline at end of file diff --git a/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/GetQueryTest.java b/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/GetQueryTest.java index ffa3c8271..3f70b614a 100644 --- a/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/GetQueryTest.java +++ b/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/GetQueryTest.java @@ -26,6 +26,8 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ArgumentsSource; +import static org.assertj.core.api.Assertions.assertThat; + public class GetQueryTest { @ParameterizedTest @@ -46,23 +48,30 @@ public void shouldNotExecute(String query) { } @Test - public void shouldCreateFromMethodFactory(){ + void shouldCreateFromMethodFactory(){ GetQuery query = GetQuery.parse("get \"Ada Lovelace\""); Assertions.assertNotNull(query); } @Test - public void shouldEquals(){ + void shouldEquals(){ String text = "get \"Ada Lovelace\""; Assertions.assertEquals(GetQuery.parse(text), GetQuery.parse(text)); } @Test - public void shouldHashCode() { + void shouldHashCode() { String text = "get \"Ada Lovelace\""; Assertions.assertEquals(GetQuery.parse(text).hashCode(), GetQuery.parse(text).hashCode()); } + @Test + void shouldToString(){ + String text = "get \"Ada Lovelace\""; + assertThat((GetQuery.parse(text).toString())) + .isEqualTo("['Ada Lovelace']"); + } + private void testQuery(String query) { CharStream stream = CharStreams.fromString(query); QueryLexer lexer = new QueryLexer(stream); diff --git a/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/InsertQueryTest.java b/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/InsertQueryTest.java index 05b851acd..8cba2d25b 100644 --- a/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/InsertQueryTest.java +++ b/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/InsertQueryTest.java @@ -26,6 +26,8 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ArgumentsSource; +import static org.assertj.core.api.Assertions.assertThat; + public class InsertQueryTest { @ParameterizedTest @@ -41,28 +43,34 @@ public void shouldIgnoreComments() { @ParameterizedTest @ArgumentsSource(WrongInsertQueryArgumentProvider.class) - public void shouldNotExecute(String query) { + void shouldNotExecute(String query) { Assertions.assertThrows(QueryException.class, () -> testQuery(query)); } @Test - public void shouldCreateFromStaticMethod() { + void shouldCreateFromStaticMethod() { InsertQuery query = InsertQuery.parse("insert Person (name = \"Ada Lovelace\")"); Assertions.assertNotNull(query); } @Test - public void shouldEquals(){ + void shouldEquals(){ String text = "insert Person (name = \"Ada Lovelace\")"; Assertions.assertEquals(InsertQuery.parse(text), InsertQuery.parse(text)); } @Test - public void shouldHashCode() { + void shouldHashCode() { String text = "insert Person (name = \"Ada Lovelace\")"; Assertions.assertEquals(InsertQuery.parse(text).hashCode(), InsertQuery.parse(text).hashCode()); } + @Test + void shouldToString() { + String text = "insert Person (name = \"Ada Lovelace\")"; + assertThat(InsertQuery.parse(text).toString()).isNotBlank(); + } + private void testQuery(String query) { CharStream stream = CharStreams.fromString(query); QueryLexer lexer = new QueryLexer(stream); diff --git a/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/NumberQueryValueTest.java b/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/NumberQueryValueTest.java index 0a57b1adb..80a01a868 100644 --- a/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/NumberQueryValueTest.java +++ b/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/NumberQueryValueTest.java @@ -19,7 +19,7 @@ class NumberQueryValueTest { @Test - public void shouldReturnType() { + void shouldReturnType() { NumberQueryValue queryValue = new NumberQueryValue(10); Assertions.assertThat(queryValue.type()) @@ -27,7 +27,7 @@ public void shouldReturnType() { } @Test - public void shouldReturnGet() { + void shouldReturnGet() { NumberQueryValue queryValue = new NumberQueryValue(10); Assertions.assertThat(queryValue.get()) @@ -35,14 +35,18 @@ public void shouldReturnGet() { } @Test - public void shouldEquals() { + void shouldEquals() { assertEquals(new NumberQueryValue(10), new NumberQueryValue(10)); - } @Test - public void shouldHashCode() { + void shouldHashCode() { assertEquals(new NumberQueryValue(10).hashCode(), new NumberQueryValue(10).hashCode()); } + @Test + void shouldToString(){ + assertEquals("10", new NumberQueryValue(10).toString()); + } + } \ No newline at end of file diff --git a/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/StringQueryValueTest.java b/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/StringQueryValueTest.java index bc9fc67cf..f7f2b23d4 100644 --- a/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/StringQueryValueTest.java +++ b/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/StringQueryValueTest.java @@ -19,7 +19,7 @@ class StringQueryValueTest { @Test - public void shouldReturnType() { + void shouldReturnType() { StringQueryValue string = new StringQueryValue("text"); Assertions.assertThat(string).isNotNull() .extracting(StringQueryValue::type) @@ -28,7 +28,7 @@ public void shouldReturnType() { @Test - public void shouldReturnValue() { + void shouldReturnValue() { StringQueryValue string = new StringQueryValue("text"); Assertions.assertThat(string).isNotNull() .extracting(StringQueryValue::get) @@ -36,14 +36,19 @@ public void shouldReturnValue() { } @Test - public void shouldEquals() { + void shouldEquals() { assertEquals(new StringQueryValue("text"), new StringQueryValue("text")); } @Test - public void shouldHasCode() { + void shouldHasCode() { assertEquals(new StringQueryValue("text").hashCode() , new StringQueryValue("text").hashCode()); } + + @Test + void shouldReturnToString() { + assertEquals("'text'", new StringQueryValue("text").toString()); + } } \ No newline at end of file diff --git a/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/UpdateQueryTest.java b/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/UpdateQueryTest.java index 26a31809f..60e048c63 100644 --- a/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/UpdateQueryTest.java +++ b/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/UpdateQueryTest.java @@ -26,6 +26,8 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ArgumentsSource; +import static org.assertj.core.api.Assertions.assertThat; + public class UpdateQueryTest { @ParameterizedTest @@ -46,25 +48,33 @@ public void shouldNotExecute(String query) { } @Test - public void shouldCreateFromMethodFactory() { + void shouldCreateFromMethodFactory() { UpdateQuery query = UpdateQuery.parse("update Person (name = \"Ada Lovelace\")"); Assertions.assertNotNull(query); } @Test - public void shouldEquals() { + void shouldEquals() { String text = "update Person (name = \"Ada Lovelace\")"; UpdateQuery query = UpdateQuery.parse(text); Assertions.assertEquals(query, UpdateQuery.parse(text)); } @Test - public void shouldHashCode() { + void shouldHashCode() { String text = "update Person (name = \"Ada Lovelace\")"; UpdateQuery query = UpdateQuery.parse(text); Assertions.assertEquals(query.hashCode(), UpdateQuery.parse(text).hashCode()); } + @Test + void shouldToString(){ + String text = "update Person (name = \"Ada Lovelace\")"; + UpdateQuery query = UpdateQuery.parse(text); + assertThat(query.toString()) + .isEqualTo("update Person ([name EQUALS 'Ada Lovelace']) "); + } + private void testQuery(String query) { CharStream stream = CharStreams.fromString(query); QueryLexer lexer = new QueryLexer(stream); diff --git a/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/method/MethodArrayValueTest.java b/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/method/MethodArrayValueTest.java index 3ebdf3e51..5312105b4 100644 --- a/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/method/MethodArrayValueTest.java +++ b/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/method/MethodArrayValueTest.java @@ -22,7 +22,7 @@ class MethodArrayValueTest { @Test - public void shouldReturnArrayType() { + void shouldReturnArrayType() { ArrayQueryValue array = MethodArrayValue.of("method"); assertThat(array).isNotNull(); ValueType type = array.type(); @@ -30,19 +30,21 @@ public void shouldReturnArrayType() { } @Test - public void shouldReturnArrayValue() { + void shouldReturnArrayValue() { ArrayQueryValue array = MethodArrayValue.of("name"); assertThat(array.get()).isInstanceOf(QueryValue[].class); } @Test - public void shouldEquals(){ - ArrayQueryValue array = MethodArrayValue.of("name"); + void shouldEquals(){ + var array = MethodArrayValue.of("name"); + var array2 = MethodArrayValue.of("name"); + Assertions.assertNotEquals(array, array2); Assertions.assertEquals(array, array); } @Test - public void shouldHashCode(){ + void shouldHashCode(){ ArrayQueryValue array = MethodArrayValue.of("name"); Assertions.assertEquals(array.hashCode(), array.hashCode()); } diff --git a/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/method/MethodParamQueryValueTest.java b/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/method/MethodParamQueryValueTest.java index 669100571..f44caa070 100644 --- a/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/method/MethodParamQueryValueTest.java +++ b/jnosql-communication/jnosql-communication-query/src/test/java/org/eclipse/jnosql/communication/query/method/MethodParamQueryValueTest.java @@ -46,4 +46,43 @@ public void shouldHashCode() { MethodParamQueryValue param = new MethodParamQueryValue("name"); assertEquals(param.hashCode(), param.hashCode()); } + + @Test + void shouldEquality() { + String value = "testValue"; + MethodParamQueryValue queryValue1 = new MethodParamQueryValue(value); + assertEquals(queryValue1, queryValue1); + } + + @Test + void shouldInequality() { + MethodParamQueryValue queryValue1 = new MethodParamQueryValue("value1"); + MethodParamQueryValue queryValue2 = new MethodParamQueryValue("value2"); + + // Should have inequality + assertNotEquals(queryValue1, queryValue2); + } + + @Test + void shouldConsistentHashcode() { + String value = "testValue"; + MethodParamQueryValue queryValue1 = new MethodParamQueryValue(value); + Assertions.assertThat(queryValue1.hashCode()).isEqualTo(queryValue1.hashCode()); + } + + @Test + void shouldToStringRepresentation() { + String value = "testValue"; + MethodParamQueryValue queryValue = new MethodParamQueryValue(value); + + Assertions.assertThat(queryValue.toString()).startsWith("@" + value); + } + + @Test + void shouldValueWithPrefix() { + MethodParamQueryValue queryValue = new MethodParamQueryValue("test"); + + // Should generate a value with the original prefix and nano time + assertTrue(queryValue.get().startsWith("test_")); + } } \ No newline at end of file