package kz.arta.synergy.workflow.mobile.android.offline;

import org.json.JSONArray;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;

import java.util.ArrayList;
import java.util.List;

import kz.arta.synergy.workflow.mobile.android.files.models.Node;
import kz.arta.synergy.workflow.mobile.android.files.offline.FilesFiltersTable;
import kz.arta.synergy.workflow.mobile.android.files.offline.FilesListTable;
import kz.arta.synergy.workflow.mobile.android.files.offline.actions.FilesAddFileTable;
import kz.arta.synergy.workflow.mobile.android.files.offline.actions.FilesMoveTable;
import kz.arta.synergy.workflow.mobile.android.files.offline.actions.FilesNewFolderTable;
import kz.arta.synergy.workflow.mobile.android.files.offline.actions.FilesRemoveTable;
import kz.arta.synergy.workflow.mobile.android.files.offline.actions.FilesRenameTable;

/**
 * Created by neox on 12.10.16.
 */
public class FilesOfflineUnitTest {

    @Test
    public void getNewFilesByNodeID() {
        Node node = new Node();
        node.setName("node");
        List<Node> result = new ArrayList<>();
        result.add(node);
        FilesAddFileTable db = Mockito.mock(FilesAddFileTable.class);
        Mockito.when(db.get("nodeID")).thenReturn(result);
        Assert.assertEquals(db.get("nodeID").size(), 1);
        Assert.assertEquals(db.get("nodeID"), result);
    }

    @Test
    public void getNewFiles() {
        JSONArray jsonArray = new JSONArray();
        jsonArray.put("123");
        FilesAddFileTable db = Mockito.mock(FilesAddFileTable.class);
        Mockito.when(db.get()).thenReturn(jsonArray);
        Assert.assertEquals(db.get().length(), 1);
        Assert.assertEquals(db.get(), jsonArray);
    }

    @Test
    public void getMoveFiles() {
        JSONArray jsonArray = new JSONArray();
        jsonArray.put("123");
        FilesMoveTable db = Mockito.mock(FilesMoveTable.class);
        Mockito.when(db.get()).thenReturn(jsonArray);
        Assert.assertEquals(db.get().length(), 1);
        Assert.assertEquals(db.get(), jsonArray);
    }

    @Test
    public void getNewFolders() {
        Node node = new Node();
        node.setName("node");
        List<Node> result = new ArrayList<>();
        result.add(node);
        FilesNewFolderTable db = Mockito.mock(FilesNewFolderTable.class);
        Mockito.when(db.get("nodeID")).thenReturn(result);
        Assert.assertEquals(db.get("nodeID").size(), 1);
        Assert.assertEquals(db.get("nodeID"), result);
    }

    @Test
    public void getAllNewFolders() {
        JSONArray jsonArray = new JSONArray();
        jsonArray.put("123");
        FilesNewFolderTable db = Mockito.mock(FilesNewFolderTable.class);
        Mockito.when(db.get()).thenReturn(jsonArray);
        Assert.assertEquals(db.get().length(), 1);
        Assert.assertEquals(db.get(), jsonArray);
    }

    @Test
    public void getFilesRemove() {
        JSONArray jsonArray = new JSONArray();
        jsonArray.put("123");
        FilesRemoveTable db = Mockito.mock(FilesRemoveTable.class);
        Mockito.when(db.get()).thenReturn(jsonArray);
        Assert.assertEquals(db.get().length(), 1);
        Assert.assertEquals(db.get(), jsonArray);
    }

    @Test
    public void getFilesRename() {
        JSONArray jsonArray = new JSONArray();
        jsonArray.put("123");
        FilesRenameTable db = Mockito.mock(FilesRenameTable.class);
        Mockito.when(db.get()).thenReturn(jsonArray);
        Assert.assertEquals(db.get().length(), 1);
        Assert.assertEquals(db.get(), jsonArray);
    }

    @Test
    public void getFilesTree() {
        String result = "[]";
        FilesFiltersTable db = Mockito.mock(FilesFiltersTable.class);
        Mockito.when(db.get("nodeID")).thenReturn(result);
        Assert.assertEquals(db.get("nodeID"), result);
    }

    @Test
    public void getFilesList() {
        String result = "[]";
        FilesListTable db = Mockito.mock(FilesListTable.class);
        Mockito.when(db.get("nodeID")).thenReturn(result);
        Assert.assertEquals(db.get("nodeID"), result);
    }

}
