File tree Expand file tree Collapse file tree
main/java/com/baeldung/packages
test/java/com/baeldung/packages Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package com .baeldung .packages ;
2+
3+ import java .time .LocalDate ;
4+
5+ import com .baeldung .packages .domain .TodoItem ;
6+
7+ public class TodoApp {
8+
9+ public static void main (String [] args ) {
10+ TodoList todoList = new TodoList ();
11+ for (int i = 0 ; i < 3 ; i ++) {
12+ TodoItem item = new TodoItem ();
13+ item .setId (Long .valueOf ((long )i ));
14+ item .setDescription ("Todo item " + (i + 1 ));
15+ item .setDueDate (LocalDate .now ().plusDays ((long )(i + 1 )));
16+ todoList .addTodoItem (item );
17+ }
18+
19+ todoList .getTodoItems ().forEach ((TodoItem todoItem ) -> System .out .println (todoItem .toString ()));
20+ }
21+
22+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .packages ;
2+
3+ import java .util .ArrayList ;
4+ import java .util .List ;
5+
6+ import com .baeldung .packages .domain .TodoItem ;
7+
8+ public class TodoList {
9+ private List <TodoItem > todoItems ;
10+
11+ public void addTodoItem (TodoItem todoItem ) {
12+ if (todoItems == null ) {
13+ todoItems = new ArrayList <TodoItem >();
14+ }
15+
16+ todoItems .add (todoItem );
17+ }
18+
19+ public List <TodoItem > getTodoItems () {
20+ return todoItems ;
21+ }
22+
23+ public void setTodoItems (List <TodoItem > todoItems ) {
24+ this .todoItems = todoItems ;
25+ }
26+
27+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .packages .domain ;
2+
3+ import java .time .LocalDate ;
4+
5+ public class TodoItem {
6+ private Long id ;
7+ private String description ;
8+ private LocalDate dueDate ;
9+
10+ public Long getId () {
11+ return id ;
12+ }
13+
14+ public void setId (Long id ) {
15+ this .id = id ;
16+ }
17+
18+ public String getDescription () {
19+ return description ;
20+ }
21+
22+ public void setDescription (String description ) {
23+ this .description = description ;
24+ }
25+
26+ public LocalDate getDueDate () {
27+ return dueDate ;
28+ }
29+
30+ public void setDueDate (LocalDate dueDate ) {
31+ this .dueDate = dueDate ;
32+ }
33+
34+ @ Override
35+ public String toString () {
36+ return "TodoItem [id=" + id + ", description=" + description + ", dueDate=" + dueDate + "]" ;
37+ }
38+
39+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .packages ;
2+
3+ import static org .junit .Assert .assertEquals ;
4+
5+ import java .time .LocalDate ;
6+
7+ import org .junit .Test ;
8+
9+ import com .baeldung .packages .domain .TodoItem ;
10+
11+ public class PackagesUnitTest {
12+
13+ @ Test
14+ public void whenTodoItemAdded_ThenSizeIncreases () {
15+ TodoItem todoItem = new TodoItem ();
16+ todoItem .setId (1L );
17+ todoItem .setDescription ("Test the Todo List" );
18+ todoItem .setDueDate (LocalDate .now ());
19+ TodoList todoList = new TodoList ();
20+ todoList .addTodoItem (todoItem );
21+ assertEquals (1 , todoList .getTodoItems ().size ());
22+ }
23+ }
You can’t perform that action at this time.
0 commit comments