Skip to content

Yea :)#24

Open
MitjaPerko wants to merge 3 commits intoibwgr:masterfrom
MitjaPerko:master
Open

Yea :)#24
MitjaPerko wants to merge 3 commits intoibwgr:masterfrom
MitjaPerko:master

Conversation

@MitjaPerko
Copy link

No description provided.

// --- getAge

@Test
void getAgeReturns10YearsIfBornIn2009() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Der Testinhalt stimmt nicht mit dem Testnamen überein :)


// TODO implement
throw new IllegalArgumentException("you should implement code here");
Assertions.assertEquals(1, age.getDays());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was wenn age.getMonths() == 1 ... würde dein Test das bemerken?

Copy link
Contributor

@ideadapt ideadapt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sieht schon ganz gut aus! Einige Dinge hab ich trotzdem noch gefunden ;)

void returnsTrueIfSameNameInDBButWithDifferentLetterCasing() {
// -> implement test
/* ARRANGE */
UserValidator uv = new UserValidator();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damit dein Test wiederholbar und isoliert läuft müsstest du hier eine MockDatabase injecten.

void returnsTrueIfUsernameInDB__FAKE() {
// -> implementiere / ergänze den Test hier, so dass dieser kompiliert und grün ist.
/* ARRANGE */
FakeUserValidator uv = new FakeUserValidator();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deine SUT (getestete Klasse) sollte niemals ein Fake sein ;)


doReturn(true).when(uv).isValidUsername(anyString());
// eigentlich müsste untenstehende anweisung rein, ergibt jedoch einen error... keine ahnung wieso.
//doReturn(true).when(uv).doesUsernameExist(anyString());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Es wäre dann aber gemäss Testname "doReturn(false)" :). Was ist die Fehlermeldung?

User user = new User("kalua");
/* ACT */
Message result = uc.create(user);
boolean result2 = uv.doesUsernameExist(user, db);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In allen Tests dieser Klasse ist das SUT der UserController.
Es ist also nicht nötig hier auf dem FakeUserValidator eine Methode aufzurufen. Du könntest aber prüfen ob db.getUsers() den gewünschten User retourniert.

/* ARRANGE */
UserValidator uv = mock(UserValidator.class);
FileDatabase db = mock(FileDatabase.class);
UserController uc = new UserController(uv, db);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Du solltest hier noch definieren was isValidUsername und doesUsernameExists retournieren sollen. Denn by default retournieren gemockte boolean Methoden ja false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants