package org.gnode.nix;

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

import java.util.ArrayList;

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

public class TestFile {

    private File file_open;
    private File file_other;
    private File file_null;

    private long statup_time;

    @Before
    public void setUp() {
        statup_time = System.currentTimeMillis() / 1000;
        file_open = File.open("test_file.h5", FileMode.Overwrite);
        file_other = File.open("test_file_other.h5", FileMode.Overwrite);
        file_null = null;
    }

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

    @Test
    public void testFormat() {
        assertEquals(file_open.getFormat(), "nix");
    }

    @Test
    public void testLocation() {
        assertEquals(file_open.getLocation(), "test_file.h5");
        assertEquals(file_other.getLocation(), "test_file_other.h5");
    }

    @Test
    public void testVersion() {
        ArrayList<Integer> version = file_open.getVersion();
        assertEquals(version.get(0), Integer.valueOf(1));
        assertEquals(version.get(1), Integer.valueOf(0));
        assertEquals(version.get(2), Integer.valueOf(0));
    }

    @Test
    public void testCreatedAt() {
        assertTrue(file_open.createdAt() >= statup_time);
        long past_time = (System.currentTimeMillis() / 1000) - 10000000;
        file_open.forceCreatedAt(past_time);
        assertEquals(file_open.createdAt(), past_time);
    }

    @Test
    public void testUpdatedAt() {
        assertTrue(file_open.updatedAt() >= statup_time);
    }
}

@@ -117,16 +117,39 @@
 rayList;
+%0Aimport java.util.Date;
 %0A%0Aimport
@@ -354,20 +354,20 @@
 private 
-long
+Date
  statup_
@@ -433,16 +433,25 @@
 _time = 
+new Date(
 System.c
@@ -475,16 +475,17 @@
 ) / 1000
+)
 ;%0A      
@@ -1386,33 +1386,36 @@
 tTrue(file_open.
-c
+getC
 reatedAt() %3E= st
@@ -1400,36 +1400,43 @@
 n.getCreatedAt()
- %3E= 
+.compareTo(
 statup_time);%0A  
@@ -1427,24 +1427,30 @@
 statup_time)
+ %3E= 0)
 ;%0A        lo
@@ -1451,12 +1451,12 @@
     
-long
+Date
  pas
@@ -1464,16 +1464,24 @@
 _time = 
+new Date
 (System.
@@ -1506,17 +1506,16 @@
 ) / 1000
-)
  - 10000
@@ -1517,16 +1517,17 @@
 10000000
+)
 ;%0A      
@@ -1571,38 +1571,36 @@
 ;%0A        assert
-Equals
+True
 (file_open.creat
@@ -1594,17 +1594,20 @@
 le_open.
-c
+getC
 reatedAt
@@ -1612,19 +1612,35 @@
 At()
-, past_time
+.compareTo(statup_time) %3C 0
 );%0A 
@@ -1718,17 +1718,20 @@
 le_open.
-u
+getU
 pdatedAt
@@ -1732,20 +1732,27 @@
 atedAt()
- %3E= 
+.compareTo(
 statup_t
@@ -1751,22 +1751,28 @@
 statup_time)
+ %3E= 0)
 ;%0A    %7D%0A%7D%0A

update test