Example usage for java.lang IllegalArgumentException getMessage

List of usage examples for java.lang IllegalArgumentException getMessage

Introduction

In this page you can find the example usage for java.lang IllegalArgumentException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.smartitengineering.cms.content.api.impl.IdTest.java

public void testSettersWithBlank() {
    final String suffix = ContentTypeIdImpl.STANDARD_ERROR_MSG.substring(2);
    WorkspaceIdImpl workspaceIdImpl = new WorkspaceIdImpl();
    try {//from   ww  w  .  j  a  v a 2  s . c o m
        workspaceIdImpl.setGlobalNamespace("\t\n");
        fail("Setter with blank value should not exit normally");
    } catch (IllegalArgumentException exception) {
        assertTrue(exception.getMessage().endsWith(suffix));
    }
    try {
        workspaceIdImpl.setName("");
        fail("Setter with blank value should not exit normally");
    } catch (IllegalArgumentException exception) {
        assertTrue(exception.getMessage().endsWith(suffix));
    }
    ContentTypeIdImpl idImpl = new ContentTypeIdImpl();
    try {
        idImpl.setWorkspace(null);
        fail("Setter with blank value should not exit normally");
    } catch (IllegalArgumentException exception) {
        assertTrue(exception.getMessage().endsWith(suffix));
    }
    try {
        idImpl.setNamespace(" \t");
        fail("Setter with blank value should not exit normally");
    } catch (IllegalArgumentException exception) {
        assertTrue(exception.getMessage().endsWith(suffix));
    }
    try {
        idImpl.setName(null);
        fail("Setter with blank value should not exit normally");
    } catch (IllegalArgumentException exception) {
        assertTrue(exception.getMessage().endsWith(suffix));
    }
}

From source file:org.echocat.redprecursor.annotations.ParametersPassesExpressionUnitTest.java

@Test
public void testEvaluateWithNoMethodElementType() throws Exception {
    try {//ww  w.  j  ava  2 s. c om
        new Evaluator().evaluate(proxyAnnotation(ParametersPassesExpression.class), PARAMETER, "foo",
                mock(MethodCall.class));
        fail("Expected exception missing.");
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), is("This evaluator only supports " + METHOD + " elementTypes."));
    }
}

From source file:org.echocat.redprecursor.annotations.ParametersPassesExpressionUnitTest.java

private void evaluateAndExpectExceptionWithMessage(MethodCall<ParametersPassesExpressionUnitTest> methodCall,
        String expression, String violationMessage, String expectedExceptionMessage) {
    try {//from   w ww.  j ava  2 s  .  co  m
        new Evaluator().evaluate(proxyAnnotation(ParametersPassesExpression.class, "value", expression,
                "messageOnViolation", violationMessage), METHOD, "test", methodCall);
        fail("Expected exception missing.");
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), is(expectedExceptionMessage));
    }
}

From source file:com.kakao.hbase.manager.command.ExportKeysTest.java

@Test
public void testInvalidTable() throws Exception {
    String[] argsParam = { "zookeeper" };
    Args args = new ManagerArgs(argsParam);
    assertEquals("zookeeper", args.getZookeeperQuorum());

    try {//w w w .j  a  v a2 s. c  om
        ExportKeys command = new ExportKeys(admin, args);
        command.run();
        fail();
    } catch (IllegalArgumentException e) {
        if (!e.getMessage().contains(Args.INVALID_ARGUMENTS))
            throw e;
    }
}

From source file:ste.web.http.api.BugFreeApiHandlerExec.java

@Test
public void constructors() throws Exception {
    try {//www .j  av  a 2 s  .c o m
        new ApiHandler(null);
        fail("missing check for null parameters");
    } catch (IllegalArgumentException x) {
        then(x.getMessage()).contains("apiroot").contains("not be null");
    }

    String root = new File("src/test/apiroot").getAbsolutePath();
    ApiHandler h = new ApiHandler(root);
    then(PrivateAccess.getInstanceValue(h, "apiroot")).isEqualTo(root);
}

From source file:com.googlecode.jsendnsca.MessagePayloadTest.java

@Test
public void shouldThrowIllegalArgumentExceptionIfStringLevelIsNotRecognised() throws Exception {
    final MessagePayload messagePayload = new MessagePayload();

    try {/*  w  w  w  .j a  v a  2  s . c  om*/
        messagePayload.setLevel("foobar");
        fail("Should throw IllegalArgumentException");
    } catch (IllegalArgumentException e) {
        assertEquals("[foobar] is not valid level", e.getMessage());
    }
}

From source file:org.echocat.redprecursor.annotations.ParametersPassesExpressionUnitTest.java

@Test
public void testEvaluateWithNotMatchingElementNameAndMethodName() throws Exception {
    try {//w w  w.j  a  v  a  2  s  . c  om
        final MethodCall<ParametersPassesExpressionUnitTest> methodCall = toMethodCall(
                ParametersPassesExpressionUnitTest.class, this, "bar");
        new Evaluator().evaluate(proxyAnnotation(ParametersPassesExpression.class), METHOD, "foo", methodCall);
        fail("Expected exception missing.");
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), is(
                "The provided elementName ('foo') is not the same as the name ('bar') of the provided method call."));
    }
}

From source file:com.eharmony.services.swagger.resource.DocumentationRepositoryResource.java

/**
 * Saves a services documentation. Validates all required fields. If the same service name and
 * environment is found, it is overwritten.
 * @param documentation The unique documentation id.
 *//*from  www .  ja  v  a  2 s.com*/
@POST
@ApiOperation(value = "Save documentation", notes = "Saves a services documentation. Validates all required fields. If the same service name and "
        + "environment is found, it is overwritten.")
@ApiResponses({ @ApiResponse(code = 200, message = "The documentation was overwritten successfully."),
        @ApiResponse(code = 201, message = "The documentation was created successfully."),
        @ApiResponse(code = 400, message = "A required field is missing."),
        @ApiResponse(code = 500, message = "An error occurred when attempting to save the documentation.") })
public Response saveDocumentationForService(
        @ApiParam(value = "A single service documentation object") Documentation documentation) {
    try {
        validateDocumentation(documentation);
        Documentation existingDocumentation = repository.getDocumentationByServiceNameAndEnvironment(
                documentation.getServiceName(), documentation.getEnvironment());
        if (existingDocumentation != null) {
            documentation.setId(existingDocumentation.getId());
            repository.saveDocumentation(documentation);
            return Response.ok().build();
        } else {
            repository.saveDocumentation(documentation);
            return Response.status(201).build();
        }
    } catch (IllegalArgumentException iae) {
        return Response.status(400).entity(iae.getMessage()).build();
    } catch (Exception ex) {
        LOG.error("Unable to save documentation", ex);
        return Response.serverError().build();
    }
}

From source file:com.graphaware.module.timetree.api.TimedEventsApi.java

@ExceptionHandler(IllegalArgumentException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)//www  .  ja  v a  2  s  . co m
@ResponseBody
public Map<String, String> handleIllegalArgument(IllegalArgumentException e) {
    LOG.warn("Bad Request: " + e.getMessage(), e);
    return Collections.singletonMap("message", e.getMessage());
}

From source file:org.echocat.redprecursor.annotations.ParametersPassesExpressionUnitTest.java

@Test
public void testEvaluationThrowsException() throws Exception {
    final MethodCall<ParametersPassesExpressionUnitTest> methodCall = toMethodCall(
            ParametersPassesExpressionUnitTest.class, this, "test", "a", 1, "b", '2');
    try {//from   w  w  w  .  j a  va  2 s  .co m
        new Evaluator().evaluate(proxyAnnotation(ParametersPassesExpression.class, "value", "a eq b"), METHOD,
                "test", methodCall);
        fail("Expected exception missing.");
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), is("Expression not passed: a eq b"));
        assertThat(e.getCause() instanceof SpelEvaluationException, is(true));
    }
}