Example usage for java.lang NullPointerException getMessage

List of usage examples for java.lang NullPointerException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.github.fge.jsonschema.core.load.configuration.LoadingConfigurationBuilderTest.java

@Test
public void cannotSetNullDereferencingMode() {
    try {// w ww  . j a v  a  2  s  . com
        cfg.dereferencing(null);
        fail("No exception thrown!!");
    } catch (NullPointerException e) {
        assertEquals(e.getMessage(), BUNDLE.getMessage("loadingCfg.nullDereferencingMode"));
    }
}

From source file:org.elasticsearch.client.RestClientTests.java

public void testPerformAsyncWithNullParams() throws Exception {
    RestClient.SyncResponseListener listener = new RestClient.SyncResponseListener(10000);
    try (RestClient restClient = createRestClient()) {
        restClient.performRequestAsync(randomAsciiOfLength(5), randomAsciiOfLength(5), null, listener);
        listener.get();/*from w  w  w  .  j  ava2s .c  om*/

        fail("should have failed because of null parameters");
    } catch (NullPointerException exception) {
        assertEquals("params must not be null", exception.getMessage());
    }
}

From source file:org.elasticsearch.client.RestClientTests.java

public void testPerformAsyncWithNullHeaders() throws Exception {
    RestClient.SyncResponseListener listener = new RestClient.SyncResponseListener(10000);
    try (RestClient restClient = createRestClient()) {
        restClient.performRequestAsync("GET", randomAsciiOfLength(5), listener, (Header) null);
        listener.get();//  ww  w . j  a  v  a 2s .  com

        fail("should have failed because of null headers");
    } catch (NullPointerException exception) {
        assertEquals("request header must not be null", exception.getMessage());
    }
}

From source file:net.lmxm.ute.utils.FileSystemTargetUtilsTest.java

/**
 * Test get full path.//from  w  ww.j  av  a2  s  . c  om
 */
@Test
public void testGetFullPath() {
    // Null target
    try {
        FileSystemTargetUtils.getFullPath(null);
        fail();
    } catch (final NullPointerException e) {
        assertNotNull(e.getMessage());
    }

    // Null target location
    try {
        FileSystemTargetUtils.getFullPath(new FileSystemTarget());
        fail();
    } catch (final NullPointerException e) {
        assertNotNull(e.getMessage());
    }

    // Null target location path
    try {
        final FileSystemTarget fileSystemTarget = new FileSystemTarget();

        fileSystemTarget.setLocation(new FileSystemLocation());

        FileSystemTargetUtils.getFullPath(fileSystemTarget);
        fail();
    } catch (final NullPointerException e) {
        assertNotNull(e.getMessage());
    }

    final FileSystemTarget fileSystemTarget = new FileSystemTarget();
    final FileSystemLocation fileSystemLocation = new FileSystemLocation();

    fileSystemLocation.setPath("path");
    fileSystemTarget.setLocation(fileSystemLocation);

    // Null relative path
    final String fullPath = FileSystemTargetUtils.getFullPath(fileSystemTarget);
    assertTrue(StringUtils.isNotBlank(fullPath));

    // Empty relative path
    fileSystemTarget.setRelativePath("");
    final String fullPathEmptyRelativePath = FileSystemTargetUtils.getFullPath(fileSystemTarget);
    assertTrue(StringUtils.isNotBlank(fullPathEmptyRelativePath));
    assertEquals(fullPath, fullPathEmptyRelativePath);

    // Blank relative path
    fileSystemTarget.setRelativePath("    ");
    final String fullPathBlankRelativePath = FileSystemTargetUtils.getFullPath(fileSystemTarget);
    assertTrue(StringUtils.isNotBlank(fullPathBlankRelativePath));
    assertEquals(fullPath, fullPathBlankRelativePath);

    // Valid relative path
    fileSystemTarget.setRelativePath("test");
    final String fullPathWithRelativePath = FileSystemTargetUtils.getFullPath(fileSystemTarget);
    assertTrue(StringUtils.isNotBlank(fullPathWithRelativePath));
    assertFalse(fullPath.equals(fullPathWithRelativePath));
    assertEquals(fullPath + "/" + "test", fullPathWithRelativePath);
}

From source file:com.github.fge.jackson.jsonpointer.TreePointerTest.java

@Test
public void attemptToBuildTokensFromNullRaisesAnError() throws JsonPointerException {
    try {//w w  w .  j ava  2 s . c o  m
        TreePointer.tokensFromInput(null);
        fail("No exception thrown!!");
    } catch (NullPointerException e) {
        assertEquals(e.getMessage(), BUNDLE.getMessage("nullInput"));
    }
}

From source file:net.lmxm.ute.subversion.utils.SubversionRepositoryLocationUtilsTest.java

/**
 * Test get full url./*from   w  w  w.  j a  v  a2s .co m*/
 */
@Test
public void testGetFullUrl() {
    // Null target
    try {
        SubversionRepositoryLocationUtils.getFullUrl(null);
        fail();
    } catch (final NullPointerException e) {
        assertNotNull(e.getMessage());
    }

    // Null target location
    try {
        SubversionRepositoryLocationUtils.getFullUrl(new SubversionRepositorySource());
        fail();
    } catch (final NullPointerException e) {
        assertNotNull(e.getMessage());
    }

    // Null target location path
    try {
        final SubversionRepositorySource subversionRepositorySource = new SubversionRepositorySource();

        subversionRepositorySource.setLocation(new SubversionRepositoryLocation());

        SubversionRepositoryLocationUtils.getFullUrl(subversionRepositorySource);
        fail();
    } catch (final NullPointerException e) {
        assertNotNull(e.getMessage());
    }

    final SubversionRepositorySource subversionRepositorySource = new SubversionRepositorySource();
    final SubversionRepositoryLocation subversionRepositoryLocation = new SubversionRepositoryLocation();

    subversionRepositoryLocation.setUrl("http://ea");
    subversionRepositorySource.setLocation(subversionRepositoryLocation);

    // Null relative path
    final String fullPath = SubversionRepositoryLocationUtils.getFullUrl(subversionRepositorySource);
    assertTrue(StringUtils.isNotBlank(fullPath));

    // Empty relative path
    subversionRepositorySource.setRelativePath("");
    final String fullPathEmptyRelativePath = SubversionRepositoryLocationUtils
            .getFullUrl(subversionRepositorySource);
    assertTrue(StringUtils.isNotBlank(fullPathEmptyRelativePath));
    assertEquals(fullPath, fullPathEmptyRelativePath);

    // Blank relative path
    subversionRepositorySource.setRelativePath("    ");
    final String fullPathBlankRelativePath = SubversionRepositoryLocationUtils
            .getFullUrl(subversionRepositorySource);
    assertTrue(StringUtils.isNotBlank(fullPathBlankRelativePath));
    assertEquals(fullPath, fullPathBlankRelativePath);

    // Valid relative path
    subversionRepositorySource.setRelativePath("test");
    final String fullPathWithRelativePath = SubversionRepositoryLocationUtils
            .getFullUrl(subversionRepositorySource);
    assertTrue(StringUtils.isNotBlank(fullPathWithRelativePath));
    assertFalse(fullPath.equals(fullPathWithRelativePath));
    assertEquals(fullPath + "/" + "test", fullPathWithRelativePath);
}

From source file:org.elasticsearch.client.sniff.SnifferBuilderTests.java

public void testBuild() throws Exception {
    int numNodes = RandomNumbers.randomIntBetween(getRandom(), 1, 5);
    HttpHost[] hosts = new HttpHost[numNodes];
    for (int i = 0; i < numNodes; i++) {
        hosts[i] = new HttpHost("localhost", 9200 + i);
    }/*from  w  w  w  .  j a  va 2  s . c om*/

    try (RestClient client = RestClient.builder(hosts).build()) {
        try {
            Sniffer.builder(null).build();
            fail("should have failed");
        } catch (NullPointerException e) {
            assertEquals("restClient cannot be null", e.getMessage());
        }

        try {
            Sniffer.builder(client)
                    .setSniffIntervalMillis(RandomNumbers.randomIntBetween(getRandom(), Integer.MIN_VALUE, 0));
            fail("should have failed");
        } catch (IllegalArgumentException e) {
            assertEquals("sniffIntervalMillis must be greater than 0", e.getMessage());
        }

        try {
            Sniffer.builder(client).setSniffAfterFailureDelayMillis(
                    RandomNumbers.randomIntBetween(getRandom(), Integer.MIN_VALUE, 0));
            fail("should have failed");
        } catch (IllegalArgumentException e) {
            assertEquals("sniffAfterFailureDelayMillis must be greater than 0", e.getMessage());
        }

        try {
            Sniffer.builder(client).setHostsSniffer(null);
            fail("should have failed");
        } catch (NullPointerException e) {
            assertEquals("hostsSniffer cannot be null", e.getMessage());
        }

        try (Sniffer sniffer = Sniffer.builder(client).build()) {
            assertNotNull(sniffer);
        }

        SnifferBuilder builder = Sniffer.builder(client);
        if (getRandom().nextBoolean()) {
            builder.setSniffIntervalMillis(RandomNumbers.randomIntBetween(getRandom(), 1, Integer.MAX_VALUE));
        }
        if (getRandom().nextBoolean()) {
            builder.setSniffAfterFailureDelayMillis(
                    RandomNumbers.randomIntBetween(getRandom(), 1, Integer.MAX_VALUE));
        }
        if (getRandom().nextBoolean()) {
            builder.setHostsSniffer(new MockHostsSniffer());
        }

        try (Sniffer sniffer = builder.build()) {
            assertNotNull(sniffer);
        }
    }
}

From source file:com.teasoft.teavote.controller.BackupController.java

@ExceptionHandler(NullPointerException.class)
@ResponseBody//w  ww . j av  a  2  s .c  o m
public JSONResponse nullPointerException(NullPointerException e) {
    return new JSONResponse(false, 0, null, e.getMessage());
}

From source file:org.testeditor.fixture.webservice.soap.SoapFixtureTest.java

@Test
public void exceptionInSendToShouldEmptyResponse() throws Exception {
    when(soapConnection.call(any(SOAPMessage.class), any(Object.class)))
            .thenThrow(new NullPointerException("Simulated runtime exception in soap call"));
    ReflectionTestUtils.setField(soapFixture, "responseMessage", MessageFactory.newInstance().createMessage());
    try {//ww w. j  a va2  s  . c o m
        soapFixture.sendTo("http://example.com");
    } catch (NullPointerException e) {
        assertThat(e.getMessage(), is("Simulated runtime exception in soap call"));
    }
    assertNull(ReflectionTestUtils.getField(soapFixture, "responseMessage"));
}

From source file:krt.com.cityguide.Fragments.PageMapFragment.java

public void addObjectMarker(ObjectModel objectModel) {
    //     googleMap.addCircle(new CircleOptions().center(new LatLng(objectModel.getLat(), objectModel.getLon()))
    //     .fillColor(0x000000).radius(1));
    //      if (objectModel == null || googleMap == null) return;
    try {//ww w .j av a  2  s . co  m
        Bitmap.Config conf = Bitmap.Config.ARGB_8888;
        Bitmap bmp = Bitmap.createBitmap(20, 20, conf);
        Canvas canvas1 = new Canvas(bmp);

        // paint defines the text color, stroke width and size
        Paint color = new Paint();
        color.setTextSize(35);
        color.setColor(Color.BLACK);
        canvas1.drawCircle(10, 10, 10, color);
        googleMap.addMarker(new MarkerOptions().position(new LatLng(objectModel.getLat(), objectModel.getLon()))
                .title(objectModel.getName()).snippet("snippet").icon(BitmapDescriptorFactory.fromBitmap(bmp)));
    } catch (NullPointerException e) {
        Log.d("error", e.getMessage());
    }

}