Skip to content

Commit

Permalink
✨ feat(QueryHelperTest.java): Add unit tests for QueryHelper utility.
Browse files Browse the repository at this point in the history
  • Loading branch information
vnobo committed Dec 19, 2024
1 parent 70a398d commit 58de83c
Showing 1 changed file with 0 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -1,48 +1,4 @@
package com.plate.boot.commons.utils.query;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

import java.util.Collection;
import java.util.Set;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

class QueryHelperTest {

private static final Pageable DEFAULT_PAGEABLE = PageRequest
.of(0, 25, Sort.by("id").ascending());

private Object testObject;
private Pageable pageable;
private Collection<String> skipKeys;
private String prefix;

@BeforeEach
void setUp() {
testObject = new Object();
pageable = DEFAULT_PAGEABLE;
skipKeys = Set.of("skipKey1", "skipKey2");
prefix = "prefix";
}

@Test
void query_withValidObjectAndPageable_returnsQueryFragment() {
QueryFragment result = QueryHelper.query(testObject, pageable, skipKeys, prefix);
assertNotNull(result);
assertTrue(result.getColumns().toString().indexOf("*") > 0);
}

@Test
void query_withEmptyObject_returnsEmptyQueryFragment() {
testObject = new Object();
QueryFragment result = QueryHelper.query(testObject, pageable, skipKeys, prefix);
assertNotNull(result);
assertTrue(result.getColumns().toString().indexOf("*") > 0);
}

}

0 comments on commit 58de83c

Please sign in to comment.