package com.coronaide.test.ui;

import java.io.IOException;
import java.util.stream.Collectors;

import javax.inject.Inject;

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

import com.coronaide.core.model.Project;
import com.coronaide.core.service.IProjectService;
import com.coronaide.ui.CoronaUIApplication;

public class CreateProjectTest extends CoronaUITest {

    @Inject
    private IProjectService projectService;

    private final String TEST_PROJECT_NAME = "test_project";

    @Before
    public void setup() throws Exception {
        launch(CoronaUIApplication.class);
    }

    @Test
    public void createProjectTest() {
        clickOn("#menu-file").clickOn("#menu-file-new-project");
        write(TEST_PROJECT_NAME);
        clickOn("OK");
        Assert.assertTrue("Expected newly created project to be found in project list.",
                projectService.getAll().stream().map(Project::getName).collect(Collectors.toList())
                        .contains(TEST_PROJECT_NAME));
    }

    @After
    public void teardown() {
        projectService.getAll().stream()
                .filter(p -> TEST_PROJECT_NAME.equals(p.getName()))
                .forEach(p -> {
                    try {
                        projectService.delete(p);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                });
    }

}

@@ -53,16 +53,82 @@
 eption;%0A
+import java.util.Collection;%0Aimport java.util.function.Predicate;%0A
 import j
@@ -870,24 +870,25 @@
 (%22OK%22);%0A
+%0A
         
 Assert.a
@@ -883,104 +883,41 @@
     
-Assert.assertTrue(%22Expected newly created project to be found in project list.%22,%0A               
+Collection%3CString%3E projectNames =
  pro
@@ -945,16 +945,33 @@
 stream()
+%0A                
 .map(Pro
@@ -984,16 +984,33 @@
 getName)
+%0A                
 .collect
@@ -1030,16 +1030,18 @@
 oList())
+;%0A
 %0A       
@@ -1045,52 +1045,282 @@
     
-                .contains(TEST_PROJECT_NAME)
+boolean found = projectNames.stream()%0A                .filter(Predicate.isEqual(TEST_PROJECT_NAME))%0A                .findAny()%0A                .isPresent();%0A%0A        Assert.assertTrue(%22Expected newly created project to be found in project list (%22 + projectNames + %22)%22, found
 );%0A 
@@ -1402,32 +1402,24 @@
 ().stream()%0A
-        
         .fil
@@ -1474,24 +1474,16 @@
         
-  
-      
 .forEach
@@ -1490,24 +1490,16 @@
 (p -%3E %7B%0A
-        
         
@@ -1524,24 +1524,16 @@
         
-        
 projectS
@@ -1562,24 +1562,16 @@
         
-     
-   
 %7D catch 
@@ -1604,24 +1604,16 @@
         
-        
 e.printS
@@ -1641,26 +1641,10 @@
     
-   
-     %7D%0A        
+%7D%0A
     

Add more information to failure message