Commit 648100a8 authored by Hallvard Trætteberg's avatar Hallvard Trætteberg
Browse files

Teste observerbarhet

parent 5d2a94e1
......@@ -48,6 +48,13 @@
<version>5.4.2</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-core -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.5.10</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
......
......@@ -2,6 +2,9 @@ package todolist.core;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.junit.jupiter.api.Assertions.assertSame;
import java.util.Collection;
......@@ -157,4 +160,39 @@ public class TodoListTest {
newList.removeTodoItem(item3);
checkIterator(newList.iterator());
}
private int receivedNotificationCount = 0;
@Test
public void testFireTodoListChanged_addItemAndReceiveNotification() {
newList.addTodoListListener(list -> {
receivedNotificationCount++;
});
assertEquals(0, receivedNotificationCount);
TodoItem item = newList.createTodoItem();
newList.addTodoItem(item);
assertEquals(1, receivedNotificationCount);
newList.removeTodoItem(item);
assertEquals(2, receivedNotificationCount);
item.setText("endret verdi");
assertEquals(3, receivedNotificationCount);
item.setChecked(true);
assertEquals(4, receivedNotificationCount);
}
@Test
public void testFireTodoListChanged_addItemAndMockReceiveNotification() {
TodoListListener listener = mock(TodoListListener.class);
newList.addTodoListListener(listener);
verify(listener, times(0)).todoListChanged(newList);
TodoItem item = newList.createTodoItem();
newList.addTodoItem(item);
verify(listener, times(1)).todoListChanged(newList);
newList.removeTodoItem(item);
verify(listener, times(2)).todoListChanged(newList);
item.setText("endret verdi");
verify(listener, times(3)).todoListChanged(newList);
item.setChecked(true);
verify(listener, times(4)).todoListChanged(newList);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment