Polishing.

Make fields final where possible. Update javadoc. Simplify assertions. Update reference docs.

See: #3715, See #3717, See #3727
Original pull request: #3741.
This commit is contained in:
Mark Paluch
2021-08-24 10:59:06 +02:00
parent 510028a834
commit c8a791d367
6 changed files with 291 additions and 283 deletions

View File

@@ -82,7 +82,7 @@ public class DocumentOperators {
*/
public static class DocumentOperatorsFactory {
private Object target;
private final Object target;
public DocumentOperatorsFactory(Object target) {
this.target = target;

View File

@@ -102,7 +102,7 @@ class SpelExpressionTransformer implements AggregationExpressionTransformer {
ExpressionState state = new ExpressionState(new StandardEvaluationContext(params), CONFIG);
ExpressionNode node = ExpressionNode.from(spelExpression.getAST(), state);
return transform(new AggregationExpressionTransformationContext<ExpressionNode>(node, null, null, context));
return transform(new AggregationExpressionTransformationContext<>(node, null, null, context));
}
/*

View File

@@ -16,7 +16,7 @@
package org.springframework.data.mongodb.core.spel;
/**
* SPI interface to implement components that can transfrom an {@link ExpressionTransformationContextSupport} into an
* SPI interface to implement components that can transform an {@link ExpressionTransformationContextSupport} into an
* object.
*
* @author Oliver Gierke

View File

@@ -15,45 +15,46 @@
*/
package org.springframework.data.mongodb.core.aggregation;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.data.mongodb.core.aggregation.DocumentOperators.*;
import static org.springframework.data.mongodb.test.util.Assertions.*;
import org.bson.Document;
import org.junit.jupiter.api.Test;
/**
* Unit tests for {@link DocumentOperators}.
*
* @author Christoph Strobl
*/
class DocumentOperatorsUnitTests {
@Test // GH-3715
void rendersRank() {
assertThat(rank().toDocument(Aggregation.DEFAULT_CONTEXT)).isEqualTo(new Document("$rank", new Document()));
assertThat(rank().toDocument(Aggregation.DEFAULT_CONTEXT)).isEqualTo("{ $rank: { } }");
}
@Test // GH-3715
void rendersDenseRank() {
assertThat(denseRank().toDocument(Aggregation.DEFAULT_CONTEXT))
.isEqualTo(new Document("$denseRank", new Document()));
.isEqualTo("{ $denseRank: { } }");
}
@Test // GH-3717
void rendersDocumentNumber() {
assertThat(documentNumber().toDocument(Aggregation.DEFAULT_CONTEXT))
.isEqualTo(new Document("$documentNumber", new Document()));
.isEqualTo("{ $documentNumber: { } }");
}
@Test // GH-3727
void rendersShift() {
assertThat(valueOf("quantity").shift(1).toDocument(Aggregation.DEFAULT_CONTEXT))
.isEqualTo(Document.parse("{ $shift: { output: \"$quantity\", by: 1 } }"));
.isEqualTo("{ $shift: { output: \"$quantity\", by: 1 } }");
}
@Test // GH-3727
void rendersShiftWithDefault() {
assertThat(valueOf("quantity").shift(1).defaultTo("Not available").toDocument(Aggregation.DEFAULT_CONTEXT))
.isEqualTo(Document.parse("{ $shift: { output: \"$quantity\", by: 1, default: \"Not available\" } }"));
.isEqualTo("{ $shift: { output: \"$quantity\", by: 1, default: \"Not available\" } }");
}
}

View File

@@ -2506,13 +2506,16 @@ At the time of this writing, we provide support for the following Aggregation Op
| `addToSet`, `covariancePop`, `covarianceSamp`, `expMovingAvg`, `first`, `last`, `max`, `min`, `avg`, `push`, `sum`, `(*count)`, `stdDevPop`, `stdDevSamp`
| Arithmetic Aggregation Operators
| `abs`, `add` (*via `plus`), `ceil`, `divide`, `exp`, `floor`, `ln`, `log`, `log10`, `mod`, `multiply`, `pow`, `round`, `sqrt`, `subtract` (*via `minus`), `trunc`
| `abs`, `add` (via `plus`), `ceil`, `divide`, `exp`, `floor`, `ln`, `log`, `log10`, `mod`, `multiply`, `pow`, `round`, `sqrt`, `subtract` (*via `minus`), `trunc`
| Document Operators
| `rank`, `denseRank`, `documentNumber`, `shift`
| String Aggregation Operators
| `concat`, `substr`, `toLower`, `toUpper`, `stcasecmp`, `indexOfBytes`, `indexOfCP`, `split`, `strLenBytes`, `strLenCP`, `substrCP`, `trim`, `ltrim`, `rtim`
| Comparison Aggregation Operators
| `eq` (*via: `is`), `gt`, `gte`, `lt`, `lte`, `ne`
| `eq` (via: `is`), `gt`, `gte`, `lt`, `lte`, `ne`
| Array Aggregation Operators
| `arrayElementAt`, `arrayToObject`, `concatArrays`, `filter`, `in`, `indexOfArray`, `isArray`, `range`, `reverseArray`, `reduce`, `size`, `slice`, `zip`