Files
spring-boot-rest/java-strings/src/test/java/com/baeldung/string/tostring/CustomerWrapperCollectionToStringTest.java
Rajesh Bhojwani 65b9909fed username:rajeshbhojwani "Java toString() method" (#6047)
* Check in code for Java toString method

* fix formatting issues

* Fix formatting issues

* Fix formatting issues

* Fix formatting issues

* Fix formatting issues

* Fix formatting issues

* replacing orders with order

* Update formatting

* Fix formatting

* Fix formatting

* Fix formatting

* Fix formatting

* Fix formatting
2019-01-07 10:31:13 +02:00

34 lines
1.1 KiB
Java

package com.baeldung.string.tostring;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.Test;
public class CustomerWrapperCollectionToStringTest {
private static final String CUSTOMER_WRAPPER_COLLECTION_TO_STRING
= "Customer [score=8, orders=[Book, Pen], fullname=Bhojwani, Rajesh, getFirstName()=Rajesh, getLastName()=Bhojwani]";
@Test
public void givenWrapperCollectionStrBuffer_whenToString_thenCustomerDetails() {
CustomerWrapperCollectionToString customer = new CustomerWrapperCollectionToString();
customer.setFirstName("Rajesh");
customer.setLastName("Bhojwani");
customer.setScore(8);
List<String> orders = new ArrayList<String>();
orders.add("Book");
orders.add("Pen");
customer.setOrders(orders);
StringBuffer fullname = new StringBuffer();
fullname.append(customer.getLastName()+", "+ customer.getFirstName());
customer.setFullname(fullname);
assertEquals(CUSTOMER_WRAPPER_COLLECTION_TO_STRING, customer.toString());
}
}