package fi.helsinki.cs.tmc.cli;

import static org.junit.Assert.assertEquals;

import fi.helsinki.cs.tmc.cli.io.Io;
import fi.helsinki.cs.tmc.cli.io.TerminalIo;
import fi.helsinki.cs.tmc.cli.io.TestIo;
import fi.helsinki.cs.tmc.cli.tmcstuff.WorkDir;
import static org.junit.Assert.assertNull;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

public class CliContextTest {

    @Before
    public void setUp() {
    }

    @Test
    public void getIoAfterItsSetInConstructor() {
        Io io = new TestIo();
        CliContext ctx = new CliContext(io);
        assertEquals(io, ctx.getIo());
    }

    @Test
    public void getIoWhenItsNotGiven() {
        CliContext ctx = new CliContext(null);
        assertEquals(TerminalIo.class, ctx.getIo().getClass());
    }

    @Test
    public void setAppAndGetIt() {
        CliContext ctx = new CliContext(null);
        Application app = new Application(ctx);
        ctx.setApp(app);
        assertEquals(app, ctx.getApp());
    }

    @Test(expected=RuntimeException.class)
    public void getAppWithoutSettingIt() {
        CliContext ctx = new CliContext(null);
        assertNull(ctx.getApp());
    }

    @Test
    public void setGetWorkDir() {
        WorkDir workDir = new WorkDir();
        CliContext ctx = new CliContext(null, null, workDir);
        assertEquals(workDir, ctx.getWorkDir());
    }


    @Ignore
    @Test
    public void backendInitWithoutCourse() {
    }

    @Ignore
    @Test
    public void backendInitWithCourse() {
    }
}

@@ -70,16 +70,59 @@
 tEquals;
+%0Aimport static org.junit.Assert.assertNull;
 %0A%0Aimport
@@ -316,35 +316,81 @@
 t.Assert.assertN
-ull
+otSame;%0Aimport static org.junit.Assert.assertTrue
 ;%0A%0Aimport org.ju
@@ -1107,17 +1107,19 @@
 expected
-=
+ = 
 RuntimeE
@@ -1544,74 +1544,767 @@
     
-%7D%0A%0A    @Ignore%0A    @Test%0A    public void backendInitWithCourse() %7B
+    CliContext ctx = new CliContext(null);%0A        assertTrue(ctx.loadBackend());%0A        assertEquals(null, ctx.getCourseInfo());%0A    %7D%0A%0A    @Ignore%0A    @Test%0A    public void backendInitWithCourse() %7B%0A        CliContext ctx = new CliContext(null);%0A        assertTrue(ctx.loadBackend());%0A        assertNotSame(null, ctx.getCourseInfo());%0A    %7D%0A%0A    @Ignore%0A    @Test%0A    public void backendInitWithInternet() %7B%0A        CliContext ctx = new CliContext(null);%0A        assertTrue(ctx.loadBackend());%0A        assertEquals(true, ctx.hasLogin());%0A    %7D%0A%0A    @Ignore%0A    @Test%0A    public void backendInitWithoutInternet() %7B%0A        CliContext ctx = new CliContext(null);%0A        assertTrue(ctx.loadBackendWithoutLogin());%0A        assertEquals(false, ctx.hasLogin());
 %0A   

Add some todo unit tests for cli context.