/**
 * AET
 *
 * Copyright (C) 2013 Cognifide Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package com.cognifide.aet.runner.processing.data.RunIndexWrappers;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.when;

import com.cognifide.aet.communication.api.metadata.Suite;
import com.cognifide.aet.communication.api.wrappers.Run;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class RunIndexWrapperTest {

  private RunIndexWrapper runIndexWrapper;

  @Mock
  private Run objectToRunWrapper;

  @Mock
  private Suite suite;

  @Mock
  private com.cognifide.aet.communication.api.metadata.Test test;

  @Before
  public void setUp(){
    when(suite.getTest(any(String.class))).thenReturn(null);
    when(objectToRunWrapper.getRealSuite()).thenReturn(suite);
    when(test.getName()).thenReturn("testName");
    runIndexWrapper = new SuiteRunIndexWrapper(objectToRunWrapper);
  }

  @Test
  public void cleanUrlFromExecutionData_expectClearedData(){
    //TODO
  }

  @Test
  public void getTest_whenSuiteHasNotTest_expectNull() {
    //TODO
    //assertThat(runIndexWrapper.getTest("testName"), null);
  }
  @Test
  public void getTest_whenSuiteHasTest_expectTest() {
    com.cognifide.aet.communication.api.metadata.Test returnedTest;
    when(suite.getTest("testName")).thenReturn(test);
    returnedTest = runIndexWrapper.getTest("testName");
    assertThat(returnedTest, is(test));
  }

  @Test
  public void getTestUrl_whenSuiteHasNotTest_expectNull() {
    //TODO
  }

  @Test
  public void getTestUrl_whenTestHasNotUrl_expectNull() {
    //TODO
  }

  @Test
  public void getTestUrl_whenTestHasUrl_expectUrl() {
    //TODO
  }

}
@@ -941,20 +941,104 @@
 api.
-wrappers.Run
+metadata.Url;%0Aimport com.cognifide.aet.communication.api.wrappers.Run;%0Aimport java.util.Optional
 ;%0Aim
@@ -1454,16 +1454,44 @@
  test;%0A%0A
+  @Mock%0A  private Url url;%0A%0A
   @Befor
@@ -1919,21 +1919,132 @@
     
-//TODO
+when(suite.getTest(any(String.class))).thenReturn(null);%0A    when(objectToRunWrapper.getRealSuite()).thenReturn(suite);
 %0A    
-//
 asse
@@ -2164,76 +2164,8 @@
 ) %7B%0A
-    com.cognifide.aet.communication.api.metadata.Test returnedTest;%0A
     
@@ -2222,23 +2222,19 @@
     
-returnedTest = 
+assertThat(
 runI
@@ -2268,37 +2268,8 @@
 me%22)
-;%0A    assertThat(returnedTest
 , is
@@ -2346,34 +2346,219 @@
 ectNull() %7B%0A
+%0A//
     
-//TODO
+when(suite.getTest(%22testName%22)).thenReturn(null);%0A//    when(objectToRunWrapper.getRealSuite()).thenReturn(suite);%0A//    assertThat(runIndexWrapper.getTestUrl(%22testName%22,%22urlName%22), null);
 %0A  %7D%0A%0A  @Tes
@@ -2613,34 +2613,271 @@
 ectNull() %7B%0A
+//
     
-//TODO
+when(test.getUrl(%22urlName%22)).thenReturn(null);%0A//    when(suite.getTest(%22testName%22)).thenReturn(test);%0A//    when(objectToRunWrapper.getRealSuite()).thenReturn(suite);%0A//    assertThat(runIndexWrapper.getTestUrl(%22testName%22,%22urlName%22), null);
 %0A  %7D%0A%0A  @Tes
@@ -2924,16 +2924,26 @@
 l_expect
+OptionalOf
 Url() %7B%0A
@@ -2942,25 +2942,199 @@
 Url() %7B%0A    
-//TODO
+when(test.getUrl(%22urlName%22)).thenReturn(url);%0A    when(suite.getTest(%22testName%22)).thenReturn(test);%0A    assertThat(runIndexWrapper.getTestUrl(%22testName%22,%22urlName%22).get(), is(url));
 %0A  %7D%0A%0A%7D

add tests for run index wrapper