0

Trying to custom format my REST Assured method chaining using the latest version of IntelliJ IDEA.


Am using IntelliJ IDEA Ultimate 2020.3 Build #IU-203.5981.144, built on November 30, 2020 and REST Assured 4.3.2.


pom.xml:

<dependency>
    <groupId>io.rest-assured</groupId>
    <artifactId>rest-assured</artifactId>
    <version>4.3.2</version>
</dependency>

<dependency>
    <groupId>io.rest-assured</groupId>
    <artifactId>json-path</artifactId>
    <version>4.3.2</version>
</dependency>

When I write code in IntelliJ IDEA, it automatically formats the method chaining as follows:

enter image description here

What I seek to do is somehow have IntelliJ IDEA let me format the code inside the getOrders() method to display like this:

given().
 when().
     get(BASE_URL+"/v1/orders").
 then().
     statusCode(200); 

When trying to start lines with the period first, it still doesn't format correctly, so when trying this:

given()
 .when()
     .get(BASE_URL+"/v1/orders")
 .then()
     .statusCode(200); 

IntelliJ IDEA automatically reformats it to:

 given().when()
        .get(BASE_URL+"/v1/orders")
        .then()
        .statusCode(200); 

I want the .then() method to indented (e.g. 4 spaces to the right) and not on the same column as get(BASE_URL+"/v1/orders") and statusCode(200);


Currently, IntelliJ reformats the method chaining in a default setting and its impossible to move the method calls around (even using the . periods and tab key).

Is the a setting / preference to change this?

PacificNW_Lover
  • 4,746
  • 31
  • 90
  • 144
  • 1
    Starting lines with periods is more useful because the developer easily comments that line. Your request is meaningful for you. However, IDE just sees only sequential methods that follow each other. – Ismail Durmaz Dec 15 '20 at 22:47
  • @İsmailDurmaz - thank you for the prompt response, but the starting lines with periods doesn't work also. For example, when I prepend a period before ```when()``` it automatically places it right after the ```given().``` method, on the same line, like this: ```given().when().``` It seems like IntelliJ IDEA is very controlling when it comes to formatting method chaining. Whether starting lines with periods is more useful than having the periods append to the end of each method, it still doesn't allow me to format correctly. What I seek is how to put spaces and tabs around the methods. – PacificNW_Lover Dec 15 '20 at 22:55
  • How does your `Preferences -> Code Style -> Java -> Chained method calls` look? Do you have all the options unchecked there? – Laksitha Ranasingha Dec 15 '20 at 23:12
  • 1
    i fear (since your problem seams pretty unsolvable/tricky to me), you will end up: [How to disable code formatting for some part of the code using comments?](https://stackoverflow.com/q/3375307/592355) ..to format them as you wish. – xerx593 Dec 15 '20 at 23:36
  • 1
    and "just as opinion", i prefer the default to what you want to achieve ..in terms of readability, syntax and (visual) design. – xerx593 Dec 15 '20 at 23:41

0 Answers0