Error : java.lang.Nullpointerexception: Cannot invoke method Trim()

Asked

Viewed 1,212 times

-1

I have tried using Port and baseUri and does not run the rest, always fails.

Complete error:

java.lang.NullPointerException: Cannot invoke method trim() on null object at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:91) at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:47) at org.codehaus.groovy.runtime.callsite.Callsitearray

Project code:

package br.com.academia.poo;

import static com.jayway.restassured.RestAssured.given;
import static org.hamcrest.Matchers.containsString;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import com.jayway.restassured.RestAssured;

@RunWith(SpringRunner.class)
@SpringBootTest
public class AcademiapooApplicationTests {

    public AcademiapooApplicationTests() {
        RestAssured.baseURI = "localhost:8080/" ;
    }

    @Test
    /* Chama o serviço pelo metodo POST */
    public void testCriaUsuario() {
        String myJson = "{\"id\":\"1\",\"name\": \"vanessa\"}";

        given()
            .contentType("application/json")
            .body(myJson)
        .when()
            .post("/clientes")
        .then()
            .statusCode(200)
            .body("message",containsString("usuário criado com sucesso"));
    }

    /*
     * @Test public void testPegarCliente() {
     * 
     * given() .when() .get("/clientes/1") .then() .statusCode(200) .body("id",
     * is(1)) .body("username", equalTo("vanessa")) .assertThat()
     * .body(matchesJsonSchemaInClasspath("clienteTest.json")); }
     */
}

1 answer

-2

The error you are getting says that you are calling the TRIM method in through a string that has not been initialized with any valid value, probably a NULL, look for your error there by the Pogometaclasssite file in the call method next to line 47.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.