I'm making an address class, and trying to figure out how to tell if one or two addresses are in a class. this is the code I have for the class:
public class Address { private String address; private String address2; private String city; private String state; private String postalCode; public Address() { super(); // TODO Auto-generated constructor stub } public Address(String address, String address2, String city, String state, String postalCode) { super(); this.address = address; this.address2 = address2; this.city = city; this.state = state; this.postalCode = postalCode; } public Address(String address, String city, String state, String postalCode) { super(); this.address = address; this.city = city; this.state = state; this.postalCode = postalCode; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public String getAddress2() { return address2; } public void setAddress2(String address2) { this.address2 = address2; } public String getCity() { return city; } public void setCity(String city) { this.city = city; } public String getState() { return state; } public void setState(String state) { this.state = state; } public String getPostalCode() { return postalCode; } public void setPostalCode(String postalCode) { this.postalCode = postalCode; } public Object print() { return null; } } and then this is the code for the tester:
import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.Test; class AddressTest { Address home = new Address("123 Main Street","Des Moines", "IA","50321"); Address condo = new Address("5643 Hideaway Mountain", "Apt 3C","Nashville", "TN", "37115"); @Test void testInstanceVariables() { assertNull(home.getAddress2()); assertNotNull(condo.getAddress2()); assertEquals("IA", home.getState()); assertEquals("37115", condo.getPostalCode()); } @Test void testPrint() { assertEquals("123 Main Street Des Moines, IA 50321", home.print()); assertEquals("5643 Hideaway Mountain Apt 3C Nashville, TN 37115", condo.print()); } } What I am struggling with at the moment is figuring out how to find if the class has both address and address2 or just address. The method doesn't accept any input and the tester gets mad if I try to get it to accept input, but I dont know how to make it run the "home" and "condo" address's if there is no input
https://stackoverflow.com/questions/66881390/how-can-i-test-to-see-if-all-variables-are-in-a-class-if-one-of-the-variables-is March 31, 2021 at 11:50AM
没有评论:
发表评论