package bakatxt.test;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.LinkedList;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import bakatxt.core.Database;
import bakatxt.core.Task;

public class DatabaseTest {

    private Database database;

    @Before
    public void setUp() throws Exception {
        database = new Database("mytestfile.txt");
        Task task = new Task("beforeTask");
        database.add(task);
    }

    @After
    public void tearDown() {
        database.close();
    }

    // @Test
    // public void testSetFile() {
    // String expected =
    // "File changed. Current filename is \"mytestfile2.txt\".";
    // String output = database.setFile("mytestfile2.txt");
    // assertEquals(expected, output);
    // }

    @Test
    public void testAddAndDeleteTask() {
        Task task = new Task("helloWorld!");
        task.setDate("2014-05-02");
        task.setTime("2230");
        task.setDone(true);
        assertTrue(database.add(task));
        assertTrue(database.delete(task));
    }

    @Test
    public void testDeleteTaskFalse() {
        Task task = new Task("helloWorld!    ");
        task.setDate("2014-05-02");
        task.setTime("2230");
        task.setDone(true);
        assertFalse(database.delete(task));
    }

    @Test
    public void testSetTaskDone() {
        Task task = new Task("set done!");
        database.add(task);
        assertTrue(database.setDone(task, true));
    }

    @Test
    public void testAddFloating() {
        Task task = new Task("This is floating!");
        task.setFloating(true);
        assertTrue(database.add(task));
    }

    @Test
    public void testGetTasks() {
        Task task1 = new Task("task1");
        task1.setDate("2014-03-02");
        database.add(task1);
        Task task2 = new Task("task2");
        task2.setDate("2014-12-14");
        database.add(task2);
        Task task3 = new Task("task3");
        task3.setDone(true);
        task3.setFloating(true);
        database.add(task3);
        LinkedList<Task> result = database.getTasksWithDate("2014-03-02");
        assertTrue(result.contains(task1));
        result = database.getTasksWithDate("2014-12-14");
        assertFalse(result.contains(task1));
        result = database.getAllUndoneTasks();
        assertFalse(result.contains(task3));
        result = database.getAllTasks();
        assertTrue(result.contains(task2));
        result = database.getTasksWithDate(null);
        assertTrue(result.contains(task3));
    }

    @Test
    public void testDatabaseOverflow() {
        for (int year = 2014; year < 3014; year++) {
            for (int month = 1; month <= 12; month++) {
                for (int day = 1; day <= 31; day++) {
                    String date = year
                            + ((month < 10) ? "-0" + month : "-" + month)
                            + ((day < 10) ? "-0" + day : "-" + day);
                    Task task = new Task(date);
                    task.setDate(date);
                    database.add(task);
                }
            }
        }
    }
}

@@ -2585,32 +2585,35 @@
 k3));%0A    %7D%0A%0A   
+ //
  @Test%0A    publi
@@ -2598,32 +2598,35 @@
     // @Test%0A   
+ //
  public void tes
@@ -2647,27 +2647,26 @@
 low() %7B%0A    
-   
+//
  for (int ye
@@ -2699,31 +2699,26 @@
 ar++) %7B%0A    
-       
+//
  for (int mo
@@ -2754,27 +2754,18 @@
 ) %7B%0A    
-   
-        
+//
  for (in
@@ -2799,31 +2799,18 @@
 ) %7B%0A    
-               
+//
  String 
@@ -2825,39 +2825,18 @@
 ear%0A    
-                       
+//
  + ((mon
@@ -2878,39 +2878,18 @@
 th)%0A    
-                       
+//
  + ((day
@@ -2926,31 +2926,18 @@
 y);%0A    
-               
+//
  Task ta
@@ -2961,31 +2961,18 @@
 e);%0A    
-               
+//
  task.se
@@ -2988,31 +2988,18 @@
 e);%0A    
-  
-             
+//
  databas
@@ -3019,49 +3019,37 @@
     
-            %7D%0A           
+// %7D%0A    //
  %7D%0A    
-   
+//
  %7D%0A   
+ //
  %7D%0A%7D

Comment out overflow test