package fi.helsinki.cs.tmc.cli.command;

import static junit.framework.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;

import fi.helsinki.cs.tmc.cli.Application;
import fi.helsinki.cs.tmc.cli.io.TestIo;
import fi.helsinki.cs.tmc.core.TmcCore;

import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import java.nio.file.Path;
import java.nio.file.Paths;

public class SubmitCommandTest {

    static Path pathToDummyCourse;
    static Path pathToDummyExercise;

    Application app;
    TestIo io;
    TmcCore mockCore;

    @BeforeClass
    public static void setUpClass() {
        pathToDummyCourse = Paths.get(SubmitCommandTest.class.getClassLoader()
                .getResource("dummy-courses/2016-aalto-c")
                .getPath());

        pathToDummyExercise = Paths.get(SubmitCommandTest.class.getClassLoader()
                .getResource("dummy-courses/2016-aalto-c/Module_1-02_intro")
                .getPath());

        assertNotNull(pathToDummyCourse);
        assertNotNull(pathToDummyExercise);
    }

    @Before
    public void setUp() {
        io = new TestIo();
        app = new Application(io);
        mockCore = mock(TmcCore.class);
        app.setTmcCore(mockCore);
    }

    @Test
    public void stub() {
        assertTrue(true);
    }
}

@@ -128,346 +128,1165 @@
 ertT
-rue;%0Aimport static org.mockito.Mockito.mock;%0A%0Aimport fi.helsinki.cs.tmc.cli.Application;%0Aimport fi.helsinki.cs.tmc.cli.io.TestIo;%0Aimport fi.helsinki.cs.tmc.core.TmcCore;%0A%0Aimport org.junit.Before;%0Aimport org.junit.BeforeClass;%0Aimport org.junit.Test;%0A%0Aimport java.nio.file.Path;%0Aimport java.nio.file.Paths;%0A%0Apublic class SubmitCommandTest %7B
+hat;%0Aimport static org.junit.Assert.assertTrue;%0Aimport static org.junit.matchers.JUnitMatchers.containsString;%0Aimport static org.mockito.Mockito.mock;%0Aimport static org.mockito.Mockito.when;%0A%0Aimport fi.helsinki.cs.tmc.cli.Application;%0Aimport fi.helsinki.cs.tmc.cli.io.TestIo;%0Aimport fi.helsinki.cs.tmc.cli.tmcstuff.TmcUtil;%0Aimport fi.helsinki.cs.tmc.cli.tmcstuff.WorkDir;%0Aimport fi.helsinki.cs.tmc.core.TmcCore;%0Aimport fi.helsinki.cs.tmc.core.domain.Course;%0Aimport fi.helsinki.cs.tmc.core.domain.submission.SubmissionResult;%0A%0Aimport org.junit.Before;%0Aimport org.junit.BeforeClass;%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.powermock.api.mockito.PowerMockito;%0Aimport org.powermock.core.classloader.annotations.PrepareForTest;%0Aimport org.powermock.modules.junit4.PowerMockRunner;%0A%0Aimport java.nio.file.Path;%0Aimport java.nio.file.Paths;%0A%0A@RunWith(PowerMockRunner.class)%0A@PrepareForTest(TmcUtil.class)%0Apublic class SubmitCommandTest %7B%0A%0A    private static final String COURSE_NAME = %222016-aalto-c%22;%0A    private static final String EXERCISE1_NAME = %22Module_1-02_intro%22;%0A    private static final String EXERCISE2_NAME = %22Module_1-04_func%22;
 %0A%0A  
@@ -1597,39 +1597,24 @@
 ses/
-2016-aalto-c%22)%0A                
+%22 + COURSE_NAME)
 .get
@@ -1622,25 +1622,24 @@
 ath());%0A
-%0A
         
 pathToDu
@@ -1634,227 +1634,113 @@
     
-pathToDummyExercise = Paths.get(SubmitCommandTest.class.getClassLoader()%0A                .getResource(%22d
+assertNotNull(pathToD
 ummy
--c
+C
 ourse
-s/2016-aalto-c/Module_1-02_intro%22)%0A                .getPath());%0A%0A        assertNotNull(pathToDummyCourse
+);%0A%0A        pathToDummyExercise = pathToDummyCourse.resolve(EXERCISE1_NAME
 );%0A 
@@ -1959,24 +1959,72 @@
 (mockCore);%0A
+        PowerMockito.mockStatic(TmcUtil.class);%0A
     %7D%0A%0A    @
@@ -2084,11 +2084,527 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void testSuccessInExerciseRoot() %7B%0A        Course course = new Course(COURSE_NAME);%0A        SubmissionResult result = new SubmissionResult();%0A        when(TmcUtil.findCourse(mockCore, COURSE_NAME)).thenReturn(course);%0A        when(TmcUtil.submitExercise(mockCore, course, EXERCISE1_NAME)).thenReturn(result);%0A%0A        app.setWorkdir(new WorkDir(pathToDummyExercise));%0A        app.run(new String%5B%5D%7B%22submit%22%7D);%0A        assertThat(io.out(), containsString(%22Submitting: %22 + EXERCISE1_NAME));%0A    %7D
 %0A%7D%0A

Add test