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:org.springframework.cloud.dataflow.rest.client.DataflowTemplateTests.java

@Test
public void testPrepareRestTemplateWithRestTemplateThatHasNoMessageConverters() {
    final RestTemplate providedRestTemplate = new RestTemplate();
    providedRestTemplate.getMessageConverters().clear();

    try {//from   w  w  w. j  a v a 2  s  .  c  o m
        DataFlowTemplate.prepareRestTemplate(providedRestTemplate);
    } catch (IllegalArgumentException e) {
        assertEquals("'messageConverters' must not be empty", e.getMessage());
        return;
    }

    fail("Expected an IllegalArgumentException to be thrown.");
}

From source file:com.neiljbrown.brighttalk.channels.reportingapi.client.spring.SpringApiClientImplTest.java

/**
 * Tests constructor {@link SpringApiClientImpl#SpringApiClientImpl(String, String, Integer, RestTemplate)} in the
 * case where the supplied protocol is invalid, because it's an unknown string.
 *//*from  w w w . j  a  v  a2 s  .c  o m*/
@Test
public final void testConstructInvalidProtocolUnknown() {
    final String protocol = "foo";
    try {
        new SpringApiClientImpl(protocol, "api.test.brighttalk.net", 80, new RestTemplate());
        fail("Expected an exception to be thrown.");
    } catch (IllegalArgumentException e) {
        assertTrue("Unexepected exception message [" + e.toString() + "].",
                e.getMessage().matches(".*protocol.*" + protocol + ".*"));
    }
}

From source file:com.neiljbrown.brighttalk.channels.reportingapi.client.spring.SpringApiClientImplTest.java

/**
 * Tests constructor {@link SpringApiClientImpl#SpringApiClientImpl(String, String, Integer, RestTemplate)} in the
 * case where the supplied port is invalid, because it's a negative number.
 *//* w w w .j  av a2  s.c om*/
@Test
public final void testConstructInvalidPortNegative() {
    int port = -1;
    try {
        new SpringApiClientImpl("https", "api.test.brighttalk.net", port, new RestTemplate());
        fail("Expected an exception to be thrown.");
    } catch (IllegalArgumentException e) {
        assertTrue("Unexepected exception message [" + e.toString() + "].",
                e.getMessage().matches(".*port.*" + port + ".*"));
    }
}

From source file:com.neiljbrown.brighttalk.channels.reportingapi.client.spring.SpringApiClientImplTest.java

/**
 * Tests constructor {@link SpringApiClientImpl#SpringApiClientImpl(String, RestTemplate)} in the case where the
 * supplied host name is invalid, because it contains an unsupported character e.g a space.
 *//*w w w  .jav  a 2 s  . co  m*/
@Test
public final void testConstructInvalidHostNameUnsupportedCharacter() {
    final String hostName = "<invalid host name>";
    try {
        new SpringApiClientImpl(hostName, new RestTemplate());
        fail("Expected an exception to be thrown.");
    } catch (IllegalArgumentException e) {
        assertTrue("Unexepected exception message [" + e.toString() + "].",
                e.getMessage().matches(".*host name.*" + hostName + ".*"));
    }
}

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

@Test
public void testThrowMessageForEmptyMessageOnViolation() throws Exception {
    final ParametersPassesExpression annotation = proxyAnnotation(ParametersPassesExpression.class, "value",
            "myExpression", "messageOnViolation", "");
    final MethodCall<ParametersPassesExpressionUnitTest> methodCall = toMethodCall(
            ParametersPassesExpressionUnitTest.class, this, "test", "a", 1, "b", 2);
    try {//from   w ww.  j  a va2 s  . c  om
        new Evaluator().throwMessageFor(annotation, methodCall, null);
        fail("Exception missing");
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), is("Expression not passed: " + annotation.value()));
        assertThat(e.getCause(), nullValue());
    }
    final Throwable cause = new Throwable("myCause");
    try {
        new Evaluator().throwMessageFor(annotation, methodCall, cause);
        fail("Exception missing");
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), is("Expression not passed: " + annotation.value()));
        assertThat(e.getCause(), is(cause));
    }
}

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

@Test
public void testThrowMessageForMessageOnViolation() throws Exception {
    final ParametersPassesExpression annotation = proxyAnnotation(ParametersPassesExpression.class, "value",
            "myExpression", "messageOnViolation", "My message - ${#expression}");
    final MethodCall<ParametersPassesExpressionUnitTest> methodCall = toMethodCall(
            ParametersPassesExpressionUnitTest.class, this, "test", "a", 1, "b", 2);
    try {/*from ww  w  .jav  a2 s.  co m*/
        new Evaluator().throwMessageFor(annotation, methodCall, null);
        fail("Exception missing");
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), is("My message - " + annotation.value()));
        assertThat(e.getCause(), nullValue());
    }
    final Throwable cause = new Throwable("myCause");
    try {
        new Evaluator().throwMessageFor(annotation, methodCall, cause);
        fail("Exception missing");
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), is("My message - " + annotation.value()));
        assertThat(e.getCause(), is(cause));
    }
}

From source file:com.xtructure.xutil.valid.strategy.UTestArgumentValidationStrategy.java

public void processFailureBehavesAsExpected() {
    Condition predicate = isNotNull();
    Object object = null;//from  ww w  . j  a va2  s . c  om
    String msg = RandomStringUtils.randomAlphanumeric(10);
    ArgumentValidationStrategy<Object> vs = new ArgumentValidationStrategy<Object>(predicate);
    try {
        vs.validate(object);
    } catch (IllegalArgumentException e) {
        if (!String.format("%s (%s): %s", ArgumentValidationStrategy.DEFAULT_MSG, object, predicate)
                .equals(e.getMessage())) {
            throw new AssertionError();
        }
    }
    try {
        vs.validate(object, msg);
    } catch (IllegalArgumentException e) {
        if (!String.format("%s (%s): %s", msg, object, predicate).equals(e.getMessage())) {
            throw new AssertionError();
        }
    }
}

From source file:org.obiba.onyx.core.service.impl.DefaultAppointmentManagementServiceImplTest.java

@Test
public void testInitializeEmptyInputDirectoryString() {
    appointmentServiceImpl.setInputDirectory("");

    try {//from   w  w w  . jav a 2s  . co m
        appointmentServiceImpl.initialize();
        fail("Should get IllegalArgumentException.");
    } catch (IllegalArgumentException e) {
        Assert.assertEquals("DefaultAppointmentManagementServiceImpl: InputDirectory should not be null",
                e.getMessage());
    }
}

From source file:com.netflix.scheduledactions.web.controllers.ValidationController.java

@RequestMapping(value = "/validateCronExpression", method = RequestMethod.GET)
@ResponseStatus(value = HttpStatus.OK)/*ww  w . ja va2s.  c  o m*/
public Map<String, Object> validateCronExpression(@RequestParam String cronExpression) {
    ImmutableMap.Builder<String, Object> mapBuilder = ImmutableMap.builder();
    try {
        TriggerUtils.validateCronExpression(cronExpression);
        mapBuilder.put("response", "Cron expression is valid");
        try {
            Options options = new Options();
            options.setZeroBasedDayOfWeek(false);
            mapBuilder.put("description", CronExpressionDescriptor.getDescription(cronExpression, options));
        } catch (ParseException IGNORED) {
            mapBuilder.put("description", "No description available");
        }
        return mapBuilder.build();
    } catch (IllegalArgumentException e) {
        throw new InvalidCronExpressionException(
                String.format("Cron expression '%s' is not valid: %s", cronExpression, e.getMessage()));
    }
}

From source file:com.netflix.scheduledactions.web.controllers.ValidationController.java

@RequestMapping(value = "/validateISO8601Interval", method = RequestMethod.GET)
@ResponseStatus(value = HttpStatus.OK)//from   w w  w  . j a v  a  2  s  . co  m
public Map<String, String> validateISO8601Interval(@RequestParam String iso8601Interval) {
    try {
        TriggerUtils.validateISO8601Interval(iso8601Interval);
        return ImmutableMap.<String, String>builder().put("response", "ISO8601 interval format is valid")
                .build();
    } catch (IllegalArgumentException e) {
        throw new InvalidISO8601IntervalException(String.format("ISO8601 interval format '%s' is not valid: %s",
                iso8601Interval, e.getMessage()));
    }
}