import org.sonar.api.server.ws.LocalConnector;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.WebService;
-import org.sonar.api.utils.log.Loggers;
+import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
@CheckForNull
private String readParamOrDefaultValue(String key, @Nullable WebService.Param definition) {
- if (definition == null) {
- String message = String.format("BUG - parameter '%s' is undefined for action '%s'", key, action.key());
- Loggers.get(getClass()).error(message);
- throw new IllegalArgumentException(message);
- }
+ checkArgument(definition != null, "BUG - parameter '%s' is undefined for action '%s'", key, action.key());
+
String deprecatedKey = definition.deprecatedKey();
String value = deprecatedKey != null ? StringUtils.defaultString(readParam(deprecatedKey), readParam(key)) : readParam(key);
value = StringUtils.defaultString(value, definition.defaultValue());
- if (value == null) {
- return null;
- }
- return value;
+ return value == null ? null : value;
}
private List<String> readMultiParamOrDefaultValue(String key, @Nullable WebService.Param definition) {
- if (definition == null) {
- String message = String.format("BUG - parameter '%s' is undefined for action '%s'", key, action.key());
- Loggers.get(getClass()).error(message);
- throw new IllegalArgumentException(message);
- }
+ checkArgument(definition != null, "BUG - parameter '%s' is undefined for action '%s'", key, action.key());
List<String> keyValues = readMultiParam(key);
if (!keyValues.isEmpty()) {
underTest.param("unknown");
}
+ @Test
+ public void fail_if_multi_param_is_not_defined() {
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("BUG - parameter 'unknown' is undefined for action 'my_action'");
+
+ underTest.multiParam("unknown");
+ }
+
@Test
public void verify_possible_values() {
underTest.setParam("has_possible_values", "foo");