Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/java/assertions/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ public String getFullName(){
public Period getAge(){
return Period.between(birthDate, LocalDate.now());
}

public String getAgeToString() {
Period p = getAge();
return "Age: " + p.getYears() + " Years, " + p.getMonths() + " Months, " + p.getDays() + " Days.";
}
}
42 changes: 28 additions & 14 deletions src/test/java/assertions/PersonTest.java
Original file line number Diff line number Diff line change
@@ -1,39 +1,53 @@
package assertions;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;

import java.time.LocalDate;
import java.time.Period;

class PersonTest {

// getFullName

@Test
void getFullNameReturnsFirstnameSpaceLastname(){
// TODO implement
throw new NotImplementedException();
Person p1 = new Person("Gion", "Baptista", LocalDate.of(1987, 1,1));
String fullName = p1.getFullName();

Assertions.assertEquals(fullName, "Gion Baptista");
}

// TODO some more useful tests
@Test
void getAgeReturns10YearsIfBorn10y5m12dAgo() {
Person p = new Person("", "",LocalDate.now().minusYears(10).minusMonths(5).minusDays(12));

Period age = p.getAge();
System.out.println(age);

// getAge
Assertions.assertEquals(10, age.getYears());
Assertions.assertEquals(5, age.getMonths());
Assertions.assertEquals(12,age.getDays());

}

// TODO verbessern. Hinweis: Repeatable (wiederholbar) zu jeder Zeit.
@Test
void getAgeReturns10YearsIfBornIn2009() throws Exception {
Person p = new Person("", "", LocalDate.of(2009, 1, 1));
void getAgeReturns1DayIfYesterday() {
Person p = new Person("", "", LocalDate.now().minusDays(1));

Period age = p.getAge();

throw new NotImplementedException();
Assertions.assertEquals(0, age.getYears());
Assertions.assertEquals(0, age.getMonths());
Assertions.assertEquals(1,age.getDays());
}

@Test
void getAgeReturns1DayIfYesterday() throws Exception {
Person p = new Person("", "", LocalDate.now().minusDays(1));
void getAgeToStringReturnsAgeAsString() {
Person p = new Person("", "",LocalDate.now().minusYears(10).minusMonths(5).minusDays(12));
System.out.println(p.getAgeToString());

// TODO implement
throw new NotImplementedException();
Assertions.assertEquals("Age: 10 Years, 5 Months, 12 Days.", p.getAgeToString());
}
// TODO some more useful tests

}
14 changes: 7 additions & 7 deletions src/test/java/fakes/UserValidatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;


class UserValidatorTest {

Expand All @@ -11,35 +11,35 @@ class isValidUsername{

@Test
void returnsTrueIfOnlyLetters(){
throw new NotImplementedException();

}

@Test
void returnsFalseIfStartsWithNumber(){
throw new NotImplementedException();

}

@Test
void returnsTrueIfContainsNumberButNotAsFirstChar(){
throw new NotImplementedException();

}

@Test
void returnsFalseIfContainsAnyNonAlphanumericChar(){
throw new NotImplementedException();

}
}

static class doesUsernameExist{

@Test
void returnsTrueIfUsernameNotInDBYet(){
throw new NotImplementedException();

}

@Test
void returnsFalseIfUsernameInDB(){
throw new NotImplementedException();

}
}
}