Skip to content

Commit

Permalink
creates document entity test
Browse files Browse the repository at this point in the history
  • Loading branch information
otaviojava committed Mar 9, 2021
1 parent 203f0a7 commit a7dab0d
Showing 1 changed file with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package jakarta.nosql.communication.tck.document;

import jakarta.nosql.TypeReference;
import jakarta.nosql.TypeSupplier;
import jakarta.nosql.Value;
import jakarta.nosql.document.Document;
import jakarta.nosql.document.DocumentEntity;
Expand Down Expand Up @@ -71,6 +73,15 @@ public void shouldDoCopy() {

}

@Test
public void shouldReturnErrorWhenFindHasNullParameter() {
Document document = Document.of("name", "name");
DocumentEntity entity = DocumentEntity.of("entity", singletonList(document));
Assertions.assertThrows(NullPointerException.class, () -> entity.find(null));
Assertions.assertThrows(NullPointerException.class, () -> entity.find("name", (Class<Object>) null));
Assertions.assertThrows(NullPointerException.class, () -> entity.find("name", (TypeSupplier<Object>) null));
}

@Test
public void shouldFindDocument() {
Document document = Document.of("name", "name");
Expand All @@ -82,15 +93,53 @@ public void shouldFindDocument() {
assertEquals(document, name.get());
}


@Test
public void shouldReturnErroWhenFindDocumentIsNull() {
public void shouldReturnErrorWhenFindDocumentIsNull() {
Assertions.assertThrows(NullPointerException.class, () -> {
Document document = Document.of("name", "name");
DocumentEntity entity = DocumentEntity.of("entity", singletonList(document));
entity.find(null);
});
}

@Test
public void shouldFindValue() {
Document column = Document.of("name", "name");
DocumentEntity entity = DocumentEntity.of("entity", singletonList(column));
Optional<String> name = entity.find("name", String.class);
Assertions.assertNotNull(name);
Assertions.assertTrue(name.isPresent());
Assertions.assertEquals("name", name.orElse(""));
}

@Test
public void shouldNotFindValue() {
Document column = Document.of("name", "name");
DocumentEntity entity = DocumentEntity.of("entity", singletonList(column));
Optional<String> notFound = entity.find("not_found", String.class);
Assertions.assertNotNull(notFound);
Assertions.assertFalse(notFound.isPresent());
}

@Test
public void shouldFindTypeSupplier() {
Document column = Document.of("name", "name");
DocumentEntity entity = DocumentEntity.of("entity", singletonList(column));
List<String> names = entity.find("name", new TypeReference<List<String>>() {});
Assertions.assertNotNull(names);
Assertions.assertFalse(names.isEmpty());
}

@Test
public void shouldNotFindTypeSupplier() {
Document column = Document.of("name", "name");
DocumentEntity entity = DocumentEntity.of("entity", singletonList(column));
List<String> names = entity.find("not_found", new TypeReference<List<String>>() {});
Assertions.assertNotNull(names);
Assertions.assertTrue(names.isEmpty());
}

@Test
public void shouldRemoveDocumentByName() {
Document document = Document.of("name", "name");
Expand Down

0 comments on commit a7dab0d

Please sign in to comment.