@Test
        public void shouldIncludeAdditionalHasStepsAndAppendPartitionOnMutatingSteps() {
            final String repr = traversal.getGremlinLang().getGremlin();
            final PartitionStrategy strategy = PartitionStrategy.build()
                    .partitionKey("p").writePartition("a").readPartitions("a").create();

            if (hasMutatingStep) {
                if (TraversalHelper.hasStepOfAssignableClass(AddEdgeStep.class, traversal.asAdmin())) {
                    strategy.apply(traversal.asAdmin());
                    final List<AddEdgeStep> addEdgeSteps = TraversalHelper.getStepsOfAssignableClass(AddEdgeStep.class, traversal.asAdmin());
                    assertEquals(1, addEdgeSteps.size());
                    addEdgeSteps.forEach(s -> {
                        assertEquals(repr, GValue.of(null, "test"), s.getParameters().get(T.label, () -> Edge.DEFAULT_LABEL).get(0));
                        assertEquals(repr, "a", s.getParameters().get("p", null).get(0));
                    });
                } else if (TraversalHelper.hasStepOfAssignableClass(AddVertexStep.class, traversal.asAdmin())) {
                    strategy.apply(traversal.asAdmin());
                    final List<AddVertexStep> addVertexSteps = TraversalHelper.getStepsOfAssignableClass(AddVertexStep.class, traversal.asAdmin());
                    assertEquals(repr, 1, addVertexSteps.size());
                    addVertexSteps.forEach(s -> assertEquals(repr, "a", s.getParameters().get("p", null).get(0)));
                } else if (TraversalHelper.hasStepOfAssignableClass(AddVertexStartStep.class, traversal.asAdmin())) {
                    strategy.apply(traversal.asAdmin());
                    final List<AddVertexStartStep> addVertexSteps = TraversalHelper.getStepsOfAssignableClass(AddVertexStartStep.class, traversal.asAdmin());
                    assertEquals(repr, 1, addVertexSteps.size());
                    addVertexSteps.forEach(s -> assertEquals(repr, "a", s.getParameters().get("p", null).get(0)));
                } else
                    fail("This test should not be marked as having a mutating step or there is something else amiss.");
            } else {
                strategy.apply(traversal.asAdmin());
            }

            final List<HasStep> steps = TraversalHelper.getStepsOfClass(HasStep.class, traversal.asAdmin());
            assertEquals(repr, expectedInsertedSteps, steps.size());

            final List<String> keySet = new ArrayList<>(strategy.getReadPartitions());
            steps.forEach(s -> {
                assertEquals(repr, 1, s.getHasContainers().size());
                final HasContainer hasContainer = (HasContainer) s.getHasContainers().get(0);

                // if it is a partition has() then ensure it is not followed by has(). if it is something else, let it
                // be followed by partition has()
                if (hasContainer.getKey().equals("p")) {
                    assertEquals(repr, keySet, hasContainer.getValue());
                    assertEquals(repr, Contains.within, hasContainer.getBiPredicate());

                    // no has() after the partition filter
                    assertThat(s.getNextStep(), not(instanceOf(HasStep.class)));
                } else {
                    // last has() in the sequence should be the partition has()
                    Step insertAfter = s;
                    while (insertAfter.getNextStep() instanceof HasStep) {
                        insertAfter = insertAfter.getNextStep();
                    }

                    final HasContainer insertAfterHasContainer = (HasContainer) ((HasStep) insertAfter).getHasContainers().get(0);

                    assertEquals(repr, "p", insertAfterHasContainer.getKey());
                    assertEquals(repr, keySet, insertAfterHasContainer.getValue());
                    assertEquals(repr, Contains.within, insertAfterHasContainer.getBiPredicate());
                }
            });
        }
@author Stephen Mallette (http://stephen.genoprime.com)
gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/PartitionStrategyTest.java