package de.qabel.ackack;

import org.junit.Assert;
import org.junit.Test;

public class ActorTest {
    Actor actor = new Actor();

    @Test
    public void isNotRunningTest() {
        Assert.assertFalse(actor.isRunning());
    }

    @Test
    public void sendReceiveTest() {
        Actor actor = new Actor() {
            @Override
            protected void react(MessageInfo info, Object... data) {
                Assert.assertEquals(data[0], "Hello World");
                stop();
            }
        };
        actor.post("Hello World");
        actor.run();
    }

    @Test
    public void threadedSendReceiveTest() throws InterruptedException {
        final Object result[] = { null };
        Actor actor = new Actor() {
            @Override
            protected void react(MessageInfo info, Object... data) {
                result[0] = data[0];
                stop();
            }
        };
        Thread bg = new Thread(actor);
        bg.start();
        actor.post("Hello World");
        bg.join();
        Assert.assertEquals(result[0], "Hello World");
    }

    @Test
    public void threadedSendReceiveTestMessageInfo() throws InterruptedException {
    	MessageInfo messageInfo;
        Actor actor, actor2;
        final Object result[] = { null };
        Thread actorThread, actor2Thread;

        actor = new Actor() {
            @Override
            protected void react(MessageInfo info, Object... data) {
                result[0] = data[0];

                info.answer("Answer");
                stop();
            }
        };

        actor2 = new Actor() {
            @Override
            protected void react(MessageInfo info, Object... data) {
                Assert.assertEquals(data[0], "Answer");
                
                stop();
            }
        };
        
        messageInfo = new MessageInfo();
        messageInfo.setSender(actor2);
        
        actor2Thread = new Thread(actor2);
        actor2Thread.start();

        actorThread = new Thread(actor);
        actorThread.start();
        actor.post(messageInfo, "Hello World");
        actorThread.join();

        actor2Thread.join();
        Assert.assertEquals(result[0], "Hello World");
    }



}

@@ -1205,16 +1205,17 @@
 sageInfo
+2
 ;%0A      
@@ -1227,16 +1227,17 @@
 or actor
+1
 , actor2
@@ -1296,24 +1296,25 @@
 Thread actor
+1
 Thread, acto
@@ -1333,24 +1333,25 @@
        actor
+1
  = new Actor
@@ -1845,16 +1845,17 @@
 sageInfo
+2
  = new M
@@ -1887,16 +1887,17 @@
 sageInfo
+2
 .setSend
@@ -2000,24 +2000,25 @@
        actor
+1
 Thread = new
@@ -2022,32 +2022,33 @@
 new Thread(actor
+1
 );%0A        actor
@@ -2043,24 +2043,25 @@
        actor
+1
 Thread.start
@@ -2073,24 +2073,25 @@
        actor
+1
 .post(messag
@@ -2095,16 +2095,17 @@
 sageInfo
+2
 , %22Hello
@@ -2127,16 +2127,17 @@
    actor
+1
 Thread.j
@@ -2234,13 +2234,10 @@
 ;%0A    %7D%0A
-%0A%0A%0A
 %7D%0A

Rename variable