private static void validatePair(String key, Object value) { Preconditions.checkNotEmpty(key, "key is empty"); Preconditions.checkNotEmpty(String.valueOf(value), "value is empty"); }
public Kirai put(String key, Object value) { Preconditions.checkNotEmpty(key, "key is empty"); Preconditions.checkNotEmpty(String.valueOf(value), "value is empty"); if (!tags.contains(key)) { throw new IllegalArgumentException("Tag {" + key + "} was not defined in input string"); } input = input.replace(BRACE_START + key + BRACE_END, String.valueOf(value)); return this; }
@Override public void validateColorCode(String code) { Preconditions.checkNotEmpty(code, "color code is empty"); if (code.length() != 7) { throw new IllegalArgumentException( "Hex value have to contain 7 characters including hash sign (#)"); } if (code.charAt(0) != '#') { throw new IllegalArgumentException("Hex value have to start from hash sign (#)"); } }
/** * Validates terminal color code For reference check website: * http://misc.flogisoft.com/bash/tip_colors_and_formatting * * @param code numeric value as a String */ @Override public void validateColorCode(String code) { Preconditions.checkNotEmpty(code, "color code is empty"); Integer numericColorCode = Integer.valueOf(code); boolean isColorCodeValid = numericColorCode > 0 && numericColorCode < 257; if (!isColorCodeValid) { throw new IllegalArgumentException("color code should be a number between 1 and 256"); } }
private Kirai(String string) { Preconditions.checkNotEmpty(string, "string is empty"); input = string; if (!isInputBalanced()) { throw new IllegalArgumentException("Braces in provided string are not balanced"); } if (!areTagsValid()) { throw new IllegalArgumentException( "Tags have to start from lower case letter and can contain " + "only lower case letters [a-z] numbers [0-9] and underscore [_]"); } }
@Test(expected = IllegalArgumentException.class) public void testNullStringShouldBeEmpty() { // given String emptyString = null; // when Preconditions.checkNotEmpty(emptyString, "string is empty"); // then // an exception is thrown }
@Test public void testStringShouldNotBeEmpty() { // given String notEmptyString = "not empty string"; // when Preconditions.checkNotEmpty(notEmptyString, "string is empty"); // then // no exception is thrown }
@Test(expected = IllegalArgumentException.class) public void testStringShouldBeEmpty() { // given String emptyString = ""; // when Preconditions.checkNotEmpty(emptyString, "string is empty"); // then // an exception is thrown }