by Guest » 05 Jan 2025, 12:16
Ich möchte die ShipmentEntityBO-Methode mit „asserThat & Contains jeder Bestellung testen. Die folgende Testfunktion funktioniert nicht, da die Liste das Objekt zurückgegeben hat. Bitte informieren Sie mich.
Code: Select all
public class ShipmentEntityBO {
public void addShipmentEntityToList(List shipmentEntityList,String shipmentDetails) {
String splited[] = shipmentDetails.split(",");
shipmentEntityList.add(new ShipmentEntity(new Integer(splited[0]), splited[1],
splited[2], new Long(splited[3]), splited[4]));
}
}
Junit-Code
Code: Select all
import java.util.ArrayList;
import java.util.Arrays;
import org.junit.Before;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
public class Junit {
ShipmentEntityBO shipmentEntityBO;
@Before
public void createObjectForShipmentEntity() {
shipmentEntityBO = new ShipmentEntityBO();
}
@Test
public void testListofShipmentEntity() {
ArrayList list = new ArrayList();
String details = "101,pavi,12345,8500,Toronto";
shipmentEntityBO.addShipmentEntityToList(list, details);
assertThat(list,containsInAnyOrder("Toronto","pavi",101,"12345",8500));
}
}
Ich möchte die ShipmentEntityBO-Methode mit „asserThat & Contains jeder Bestellung testen. Die folgende Testfunktion funktioniert nicht, da die Liste das Objekt zurückgegeben hat. Bitte informieren Sie mich.
[code]public class ShipmentEntityBO {
public void addShipmentEntityToList(List shipmentEntityList,String shipmentDetails) {
String splited[] = shipmentDetails.split(",");
shipmentEntityList.add(new ShipmentEntity(new Integer(splited[0]), splited[1],
splited[2], new Long(splited[3]), splited[4]));
}
}
[/code]
[b]Junit-Code[/b]
[code]import java.util.ArrayList;
import java.util.Arrays;
import org.junit.Before;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
public class Junit {
ShipmentEntityBO shipmentEntityBO;
@Before
public void createObjectForShipmentEntity() {
shipmentEntityBO = new ShipmentEntityBO();
}
@Test
public void testListofShipmentEntity() {
ArrayList list = new ArrayList();
String details = "101,pavi,12345,8500,Toronto";
shipmentEntityBO.addShipmentEntityToList(list, details);
assertThat(list,containsInAnyOrder("Toronto","pavi",101,"12345",8500));
}
}
[/code]