@BeforeMethod public void init() { attribute = mock(FormatAttribute.class); when(attribute.supportedTypes()).thenReturn(SUPPORTED); report = mock(ProcessingReport.class); final Dictionary<FormatAttribute> dictionary = Dictionary.<FormatAttribute>newBuilder().addEntry(FMT, attribute) .freeze(); processor = new FormatProcessor(dictionary); }
/** * Remove a keyword by its name * * @param name the name * @return this * @throws NullPointerException name is null */ public LibraryBuilder removeKeyword(final String name) { BUNDLE.checkNotNull(name, "nullName"); syntaxCheckers.removeEntry(name); digesters.removeEntry(name); validators.removeEntry(name); return this; }
/** * Return a new, empty builder for a dictionary of this type * * @param <T> the type of values * @return a new, empty builder */ public static <T> DictionaryBuilder<T> newBuilder() { return new DictionaryBuilder<T>(); }
@Test public void removedValueCannotBeRetrieved() { builder.addEntry(KEY, MOCK1); builder.removeEntry(KEY); assertNull(builder.freeze().entries().get(KEY)); }
/** * Add a new keyword to this library * * @param keyword the keyword * @return this * @throws NullPointerException keyword is null */ public LibraryBuilder addKeyword(final Keyword keyword) { BUNDLE.checkNotNull(keyword, "nullKeyword"); final String name = keyword.name; removeKeyword(name); syntaxCheckers.addEntry(name, keyword.syntaxChecker); if (keyword.validatorFactory != null) { digesters.addEntry(name, keyword.digester); validators.addEntry(name, keyword.validatorFactory); } return this; }
/** * Constructor from a library builder * * @param builder the builder * @see LibraryBuilder#freeze() */ Library(final LibraryBuilder builder) { syntaxCheckers = builder.syntaxCheckers.freeze(); digesters = builder.digesters.freeze(); validators = builder.validators.freeze(); formatAttributes = builder.formatAttributes.freeze(); }
@Test public void cannotImportFromNullDictionary() { try { builder.addAll(null); fail("No exception thrown!!"); } catch (NullPointerException e) { assertEquals(e.getMessage(), BUNDLE.getMessage("dictionary.nullDict")); } }
/** * Return a builder with a copy of all entries from this dictionary * * @return a {@link DictionaryBuilder} */ @Override public DictionaryBuilder<T> thaw() { return new DictionaryBuilder<T>(this); } }
/** * Add a format attribute * * @param name the name for this attribute * @param attribute the format attribute * @return this * @throws NullPointerException the name or attribute is null */ public LibraryBuilder addFormatAttribute(final String name, final FormatAttribute attribute) { removeFormatAttribute(name); BUNDLE.checkNotNullPrintf(attribute, "nullAttribute", name); formatAttributes.addEntry(name, attribute); return this; }
public ValidatorBuilderTest() throws NoSuchMethodException { final DictionaryBuilder<KeywordValidatorFactory> builder = Dictionary.newBuilder(); KeywordValidatorFactory factory; factory = new ReflectionKeywordValidatorFactory(K1, Keyword1.class); builder.addEntry(K1, factory); factory = new ReflectionKeywordValidatorFactory(K2, Keyword2.class); builder.addEntry(K2, factory); factory = new ReflectionKeywordValidatorFactory(CHALLENGED, Challenged.class); builder.addEntry(CHALLENGED, factory); validatorBuilder = new ValidatorBuilder(builder.freeze()); }
/** * Return a builder with a copy of all entries from this dictionary * * @return a {@link DictionaryBuilder} */ @Override public DictionaryBuilder<T> thaw() { return new DictionaryBuilder<T>(this); } }
@Test public void cannotInsertNullValue() { try { builder.addEntry(KEY, null); fail("No exception thrown!!"); } catch (NullPointerException e) { assertEquals(e.getMessage(), BUNDLE.getMessage("dictionary.nullValue")); } }
/** * Remove a format attribute by its name * * @param name the format attribute name * @return this * @throws NullPointerException name is null */ public LibraryBuilder removeFormatAttribute(final String name) { BUNDLE.checkNotNull(name, "nullFormat"); formatAttributes.removeEntry(name); return this; }
@BeforeMethod public void setupDigesters() { final DictionaryBuilder<Digester> builder = Dictionary.newBuilder(); digester1 = mock(Digester.class); when(digester1.digest(any(JsonNode.class))).thenReturn(digest1); when(digester1.supportedTypes()).thenReturn(TYPES1); builder.addEntry(K1, digester1); digester2 = mock(Digester.class); when(digester2.digest(any(JsonNode.class))).thenReturn(digest2); when(digester2.supportedTypes()).thenReturn(TYPES2); builder.addEntry(K2, digester2); schemaDigester = new SchemaDigester(builder.freeze()); }
/** * Return a new, empty builder for a dictionary of this type * * @param <T> the type of values * @return a new, empty builder */ public static <T> DictionaryBuilder<T> newBuilder() { return new DictionaryBuilder<T>(); }
@Test public void cannotInsertNullKey() { try { builder.addEntry(null, null); fail("No exception thrown!!"); } catch (NullPointerException e) { assertEquals(e.getMessage(), BUNDLE.getMessage("dictionary.nullKey")); } }
/** * Return a builder with a copy of all entries from this dictionary * * @return a {@link DictionaryBuilder} */ @Override public DictionaryBuilder<T> thaw() { return new DictionaryBuilder<T>(this); } }
/** * Return a new, empty builder for a dictionary of this type * * @param <T> the type of values * @return a new, empty builder */ public static <T> DictionaryBuilder<T> newBuilder() { return new DictionaryBuilder<T>(); }