PrivilegeDescriptorSupport implements PrivilegeDescriptor<T,Y> { protected static String humanizeActions(final String... actions) { checkArgument(actions.length > 0); final StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(Joiner.on(", ").join(Iterables.transform(Arrays.asList(actions), new Function<String, String>() { @Override public String apply(final String action) { if (ALL.equals(action)) { return "All"; } else { return UPPER_UNDERSCORE.to(UPPER_CAMEL, action); } } }))); if (actions.length > 1 || ALL.equals(actions[0])) { stringBuilder.append(" privileges"); } else { stringBuilder.append(" privilege"); } return stringBuilder.toString(); } PrivilegeDescriptorSupport(final String type); @Override String getType(); @Override String toString(); static final String ALL; static final String INVALID_ACTIONS; }
@Test public void humanizeActionsTest() throws Exception { assertThat(humanizeActions(ALL), equalTo("All privileges")); assertThat(humanizeActions("FOO"), equalTo("Foo privilege")); assertThat(humanizeActions("foo"), equalTo("Foo privilege")); assertThat(humanizeActions("FOO", "BAR", "BAZ"), equalTo("Foo, Bar, Baz privileges")); assertThat(humanizeActions("foo", "bar", "baz"), equalTo("Foo, Bar, Baz privileges")); }