Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Konafets/0991a9891bc00dc9734f to your computer and use it in GitHub Desktop.
Save Konafets/0991a9891bc00dc9734f to your computer and use it in GitHub Desktop.
JUnit Example
public class AdresseTest {
Adresse subject;
@Before
public void setUp() {
this.subject = new Adresse();
}
@After
public void tearDown() {
this.subject = null;
}
@Test
public void toStringReturnsGivenStreet() {
this.subject.setStrasse("Teststrasse");
org.junit.Assert.assertEquals("failure - strings are not equal", this.subject.toString(), "Teststrasse");
}
@Test
public void toStringReturnsGivenStreetWithNumber() {
this.subject.setStrasse("Teststrasse");
this.subject.setHausnummer(42);
org.junit.Assert.assertEquals("failure - strings are not equal", this.subject.toString(), "Teststrasse 42");
}
@Test
public void toStringReturnsGivenStreetWithNumberAndZip() {
this.subject.setStrasse("Teststrasse");
this.subject.setHausnummer(42);
this.subject.setPlz(24941);
org.junit.Assert.assertEquals("failure - strings are not equal", this.subject.toString(), "Teststrasse 42, (24941)");
}
@Test
public void toStringReturnsGivenStreetWithNumberAndCity() {
this.subject.setStrasse("Teststrasse");
this.subject.setHausnummer(42);
this.subject.setOrt("Testhausen");
org.junit.Assert.assertEquals("failure - strings are not equal", this.subject.toString(), "Teststrasse 42, Testhausen");
}
@Test
public void toStringReturnsGivenStreetWithNumberAndZipAndCity() {
this.subject.setStrasse("Teststrasse");
this.subject.setHausnummer(42);
this.subject.setPlz(24941);
this.subject.setOrt("Testhausen");
org.junit.Assert.assertEquals("failure - strings are not equal", this.subject.toString(), "Teststrasse 42, (24941) Testhausen");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment