/** * Set a friendly name for this context. * Typically done during initialization of concrete context implementations. * <p>Default is the object id of the context instance. */ public void setDisplayName(String displayName) { Assert.hasLength(displayName, "Display name must not be empty"); this.displayName = displayName; }
public HttpCookie(String name, @Nullable String value) { Assert.hasLength(name, "'name' is required and must not be empty."); this.name = name; this.value = (value != null ? value : ""); }
private static void addToMap(Map<String, Object> map, String name, Object value) { Assert.hasLength(name, "'name' must not be empty"); Assert.notNull(value, "'value' must not be null"); map.put(name, value); }
@Override public void declareRoles(String... roleNames) { Assert.notNull(roleNames, "Role names array must not be null"); for (String roleName : roleNames) { Assert.hasLength(roleName, "Role name must not be empty"); this.declaredRoles.add(roleName); } }
private static <T> void addToMultiValueMap(MultiValueMap<String, T> map, String name, T[] values) { Assert.hasLength(name, "'name' must not be empty"); Assert.notEmpty(values, "'values' must not be empty"); for (T value : values) { map.add(name, value); } }
/** * Assert that the given String is not empty; that is, * it must not be {@code null} and not the empty String. * @deprecated as of 4.3.7, in favor of {@link #hasLength(String, String)} */ @Deprecated public static void hasLength(@Nullable String text) { hasLength(text, "[Assertion failed] - this String argument must have length; it must not be null or empty"); }
public PathResourceLookupFunction(String pattern, Resource location) { Assert.hasLength(pattern, "'pattern' must not be empty"); Assert.notNull(location, "'location' must not be null"); this.pattern = PATTERN_PARSER.parse(pattern); this.location = location; }
/** * Constructor for a part with a filename and byte[] content. * @see #getHeaders() */ public MockPart(String name, @Nullable String filename, @Nullable byte[] content) { Assert.hasLength(name, "'name' must not be empty"); this.name = name; this.filename = filename; this.content = (content != null ? content : new byte[0]); this.headers.setContentDispositionFormData(name, filename); }
protected void checkParameters(String attribute, String value) { Assert.hasLength(attribute, "'attribute' must not be empty"); Assert.hasLength(value, "'value' must not be empty"); checkToken(attribute); if (PARAM_CHARSET.equals(attribute)) { value = unquote(value); Charset.forName(value); } else if (!isQuotedString(value)) { checkToken(value); } }
@Override public void declareRoles(String... roleNames) { Assert.notNull(roleNames, "Role names array must not be null"); for (String roleName : roleNames) { Assert.hasLength(roleName, "Role name must not be empty"); this.declaredRoles.add(roleName); } }
/** * Constructor for a part with a filename and byte[] content. * @see #getHeaders() */ public MockPart(String name, @Nullable String filename, @Nullable byte[] content) { Assert.hasLength(name, "'name' must not be empty"); this.name = name; this.filename = filename; this.content = (content != null ? content : new byte[0]); this.headers.setContentDispositionFormData(name, filename); }
@Test public void hasLengthWithMessageSupplier() { Assert.hasLength("foo", () -> "enigma"); }
@Test public void hasLength() { Assert.hasLength("I Heart ...", "enigma"); }
@Test public void hasLengthWithWhitespaceOnly() { Assert.hasLength("\t ", "enigma"); }
@Test public void hasLengthWithWhitespaceOnlyAndMessageSupplier() { Assert.hasLength("\t", () -> "enigma"); }
@Test public void hasLengthWithNullAndNullMessageSupplier() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage(equalTo(null)); Assert.hasLength(null, (Supplier<String>) null); }
@Test public void hasLengthWithNull() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("enigma"); Assert.hasLength(null, "enigma"); }
@Test public void hasLengthWithNullAndMessageSupplier() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("enigma"); Assert.hasLength(null, () -> "enigma"); }
@Test public void hasLengthWithEmptyStringAndMessageSupplier() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("enigma"); Assert.hasLength("", () -> "enigma"); }
@Test public void hasLengthWithEmptyString() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("enigma"); Assert.hasLength("", "enigma"); }