@Test public void testInternalWriteAllJson() { final SomeDefinition def = mock(SomeDefinition.class); when(def.getAttributeValues()).thenReturn(Arrays.asList("a", "b", "c", "?")); final WhateverKeyDefToken alphaToken = mock(WhateverKeyDefToken.class); when(alphaToken.getLexTokens()).thenReturn(new String[]{"a", "alpha"}); final WhateverKeyDefToken bravoToken = mock(WhateverKeyDefToken.class); when(bravoToken.getLexTokens()).thenReturn(new String[]{"b", "bravo"}); final WhateverKeyDefToken unknownToken = mock(WhateverKeyDefToken.class); when(unknownToken.getLexTokens()).thenReturn(new String[]{"?", "unknown"}); final WhateverKeyDefToken[] tokens = new WhateverKeyDefToken[]{alphaToken, bravoToken, unknownToken}; for (WhateverKeyDefToken token : tokens) { doCallRealMethod().when(token).nonUnknown(); doCallRealMethod().when(token).getToken(); doCallRealMethod().when(token).writeJson(any(SomeDefinition.class), any(NamePathResolver.class)); } final JsonValue parentValue = JsonCnd.internalWriteAllJson(def, resolver, tokens); assertSame("parentValue is JsonObject", parentValue.getValueType(), JsonValue.ValueType.OBJECT); final JsonObject parentObject = parentValue.asJsonObject(); assertEquals("alpha key is present and is equal to [a, alpha]", Json.createArrayBuilder().add("a").add("alpha").build(), parentObject.get("a")); assertEquals("bravo key is present and is equal to [b, bravo]", Json.createArrayBuilder().add("b").add("bravo").build(), parentObject.get("b")); assertFalse("charlie key is not present", parentObject.containsKey("c")); assertFalse("unknown key is not present", parentObject.containsKey("?")); }
static <D, K extends KeyDefinitionToken<?, D>> JsonValue internalWriteAllJson(final @NotNull D def, final @NotNull NamePathResolver resolver, final @NotNull K[] tokens) { return Stream.of(tokens) .filter(DefinitionToken::nonUnknown) .map(key -> toEntry(key.getToken(), key.writeJson(def, resolver))) .filter(testValue(JavaxJson::nonEmptyValue)) .collect(JsonCollectors.toJsonObject()); }
JsonCnd { static <D, K extends KeyDefinitionToken<?, D>> JsonValue internalWriteAllJson(final @NotNull D def, final @NotNull NamePathResolver resolver, final @NotNull K[] tokens) { return Stream.of(tokens) .filter(DefinitionToken::nonUnknown) .map(key -> toEntry(key.getToken(), key.writeJson(def, resolver))) .filter(testValue(JavaxJson::nonEmptyValue)) .collect(JsonCollectors.toJsonObject()); } }
JsonCnd { static <D, K extends KeyDefinitionToken<?, D>> JsonValue internalWriteAllJson(final @NotNull D def, final @NotNull NamePathResolver resolver, final @NotNull K[] tokens) { return Stream.of(tokens) .filter(DefinitionToken::nonUnknown) .map(key -> toEntry(key.getToken(), key.writeJson(def, resolver))) .filter(testValue(JavaxJson::nonEmptyValue)) .collect(JsonCollectors.toJsonObject()); } private  JsonCnd(); }
JsonCnd { static <D, K extends KeyDefinitionToken<?, D>> JsonValue internalWriteAllJson(final @NotNull D def, final @NotNull NamePathResolver resolver, final @NotNull K[] tokens) { return Stream.of(tokens) .filter(DefinitionToken::nonUnknown) .map(key -> toEntry(key.getToken(), key.writeJson(def, resolver))) .filter(testValue(JavaxJson::nonEmptyValue)) .collect(JsonCollectors.toJsonObject()); } private  JsonCnd(); @SuppressWarnings("WeakerAccess") static List<QNodeTypeDefinition> getQTypesFromJson(final @NotNull JsonObject json,
                      final @NotNull NamespaceMapping mapping); @SuppressWarnings("WeakerAccess") static List<PrivilegeDefinition> getPrivilegesFromJson(final @NotNull JsonValue json,
                          final @NotNull NamespaceMapping mapping); static JsonObject toJson(final @NotNull List<QNodeTypeDefinition> ntDefs,
                                    final @NotNull NamespaceMapping mapping); static JsonValue privilegesToJson(final @NotNull List<PrivilegeDefinition> privDefs,
                                             final @NotNull NamespaceMapping mapping); static List<JcrNs> toJcrNsList(final @NotNull NamespaceMapping mapping,
                                          final @NotNull NamespaceMappingRequest request); static Function<NodeTypeDefinition, QNodeTypeDefinition> adaptToQ(final @NotNull Session session); static Stream<Name> namedBy(final @NotNull QNodeTypeDefinition def); static Stream<Name> namedBy(final @NotNull PrivilegeDefinition def); static NamespaceMapping toNamespaceMapping(final List<JcrNs> jcrNsList); static @NotNull Stream<String> streamNsPrefix(final @NotNull String name); static List<Result<NodeTypeSet>> readNodeTypes(final @NotNull NamespaceMapping mapping,
                                                          final @NotNull List<URL> cndUrls); static NodeTypeSet aggregateNodeTypes(final @NotNull NamespaceMapping mapping,
                                                 final @NotNull List<NodeTypeSet> nodeTypeSets); }
JsonCnd { static <D, K extends KeyDefinitionToken<?, D>> JsonValue internalWriteAllJson(final @NotNull D def, final @NotNull NamePathResolver resolver, final @NotNull K[] tokens) { return Stream.of(tokens) .filter(DefinitionToken::nonUnknown) .map(key -> toEntry(key.getToken(), key.writeJson(def, resolver))) .filter(testValue(JavaxJson::nonEmptyValue)) .collect(JsonCollectors.toJsonObject()); } private  JsonCnd(); @SuppressWarnings("WeakerAccess") static List<QNodeTypeDefinition> getQTypesFromJson(final @NotNull JsonObject json,
                      final @NotNull NamespaceMapping mapping); @SuppressWarnings("WeakerAccess") static List<PrivilegeDefinition> getPrivilegesFromJson(final @NotNull JsonValue json,
                          final @NotNull NamespaceMapping mapping); static JsonObject toJson(final @NotNull List<QNodeTypeDefinition> ntDefs,
                                    final @NotNull NamespaceMapping mapping); static JsonValue privilegesToJson(final @NotNull List<PrivilegeDefinition> privDefs,
                                             final @NotNull NamespaceMapping mapping); static List<JcrNs> toJcrNsList(final @NotNull NamespaceMapping mapping,
                                          final @NotNull NamespaceMappingRequest request); static Function<NodeTypeDefinition, QNodeTypeDefinition> adaptToQ(final @NotNull Session session); static Stream<Name> namedBy(final @NotNull QNodeTypeDefinition def); static Stream<Name> namedBy(final @NotNull PrivilegeDefinition def); static NamespaceMapping toNamespaceMapping(final List<JcrNs> jcrNsList); static @NotNull Stream<String> streamNsPrefix(final @NotNull String name); static List<Result<NodeTypeSet>> readNodeTypes(final @NotNull NamespaceMapping mapping,
                                                          final @NotNull List<URL> cndUrls); static NodeTypeSet aggregateNodeTypes(final @NotNull NamespaceMapping mapping,
                                                 final @NotNull List<NodeTypeSet> nodeTypeSets); static final NamespaceMapping BUILTIN_MAPPINGS; static final List<String> BUILTIN_NODETYPES; static final List<String> BUILTIN_PRIVILEGES; }