### Question:
RedactStage implements AggregationStage { private Document redact(Document document) { Object value = Expression.evaluateDocument(expression, document); if (!(value instanceof String)) { throw new TypeMismatchException("Result of $redact expression should be: " + "$$DESCEND, $$PRUNE or $$KEEP, but found " + value); } switch ((String) value) { case "$$DESCEND": throw new MongoServerError(ErrorCode.CommandNotFound, "$$DESCEND is not implemented yet"); case "$$PRUNE": return null; case "$$KEEP": return document; default: throw new TypeMismatchException("Result of $redact expression should be: " + "$$DESCEND, $$PRUNE or $$KEEP, but found " + value); } } RedactStage(Document expression); @Override Stream<Document> apply(Stream<Document> stream);  }### Answer:
@Test void testRedact() { assertThat(redact( json("_id: 1"), json("$cond: {if: {$eq: [\"$_id\", 1]}, then: \"$$KEEP\", else: \"$$PRUNE\"}")) ).contains(json("_id: 1")); assertThat(redact( json("_id: 1"), json("$cond: {if: {$eq: [\"$_id\", 0]}, then: \"$$PRUNE\", else: \"$$KEEP\"}")) ).contains(json("_id: 1")); assertThat(redact( json("_id: 1"), json("$cond: {if: {$eq: [\"$_id\", 1]}, then: \"$$PRUNE\", else: \"$$KEEP\"}")) ).isEmpty(); assertThat(redact( json("_id: 1"), json("$cond: {if: {$eq: [\"$_id\", 0]}, then: \"$$KEEP\", else: \"$$PRUNE\"}")) ).isEmpty(); }