package es.sidelab.webchat;



import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import org.junit.Test;

import es.codeurjc.webchat.Chat;
import es.codeurjc.webchat.ChatManager;

public class Mejora1 {
	
	ChatManager chatManager = new ChatManager(50);
	
	ExecutorService executor = Executors.newSingleThreadExecutor();
	ExecutorService executor2 = Executors.newSingleThreadExecutor();
	ExecutorService executor3 = Executors.newSingleThreadExecutor();
	ExecutorService executor4 = Executors.newSingleThreadExecutor();
	
	@Test
	public void newUserInChat() throws Throwable {
		
		Runnable tarea = ()-> {
			try {
				mejoras("user0");
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (TimeoutException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		};
		executor.execute(tarea);
		
		Runnable tareaUser1 = ()-> {
			
			try {
				mejoras("user1");
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (TimeoutException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		};
		executor2.execute(tareaUser1);
		
		Runnable tareaUser2 = ()-> {
			
			try {
				mejoras("user2");
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (TimeoutException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		};
		executor3.execute(tareaUser2);
		
		Runnable tareaUser3 = ()-> {
			
			try {
				mejoras("user3");
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (TimeoutException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		};
		executor4.execute(tareaUser3);
		
	}
	
	public void mejoras (String stringhilo) throws InterruptedException, TimeoutException {
		TestUser user = new TestUser(stringhilo);
		chatManager.newUser(user);
		for (int j = 0; j<5; j++ ){
			Chat chat = chatManager.newChat("Chat"+j, 5, TimeUnit.SECONDS);
			chat.addUser(user);
			
		}
		
		
	}	
}

@@ -24,16 +24,45 @@
 hat;%0A%0A%0A%0A
+import java.util.Collection;%0A
 import j
@@ -318,16 +318,49 @@
 Manager;
+%0Aimport es.codeurjc.webchat.User;
 %0A%0Apublic
@@ -2832,16 +2832,175 @@
 (user);%0A
+%09%09%09Collection%3CUser%3E usuarios = chat.getUsers();%0A%09%09%09   for(User user1: usuarios)%7B%0A%09%09%09%09   System.out.println(user1.getName() + %22 in %22 + chat.getName());%0A%09%09%09   %7D%0A
 %09%09%09%0A%09%09%7D%0A

mejora 1 corregida