|  | @@ -0,0 +1,112 @@
 | 
		
	
		
			
			|  | 1 | +package com.uqac.rthoni.java_rmi.common;
 | 
		
	
		
			
			|  | 2 | +
 | 
		
	
		
			
			|  | 3 | +import com.sun.corba.se.impl.orbutil.ObjectWriter;
 | 
		
	
		
			
			|  | 4 | +import org.junit.Test;
 | 
		
	
		
			
			|  | 5 | +
 | 
		
	
		
			
			|  | 6 | +import java.io.ByteArrayOutputStream;
 | 
		
	
		
			
			|  | 7 | +import java.io.ObjectOutputStream;
 | 
		
	
		
			
			|  | 8 | +
 | 
		
	
		
			
			|  | 9 | +import static org.junit.Assert.*;
 | 
		
	
		
			
			|  | 10 | +
 | 
		
	
		
			
			|  | 11 | +/**
 | 
		
	
		
			
			|  | 12 | + * Created by robin on 9/15/16.
 | 
		
	
		
			
			|  | 13 | + */
 | 
		
	
		
			
			|  | 14 | +public class CommandTest {
 | 
		
	
		
			
			|  | 15 | +
 | 
		
	
		
			
			|  | 16 | +    private String commandToString(Command command) throws Exception
 | 
		
	
		
			
			|  | 17 | +    {
 | 
		
	
		
			
			|  | 18 | +//        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
 | 
		
	
		
			
			|  | 19 | +//        ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
 | 
		
	
		
			
			|  | 20 | +//        objectOutputStream.writeObject(command);
 | 
		
	
		
			
			|  | 21 | +//        objectOutputStream.close();
 | 
		
	
		
			
			|  | 22 | +//        return byteArrayOutputStream.toString("UTF-8");
 | 
		
	
		
			
			|  | 23 | +        return command.toString();
 | 
		
	
		
			
			|  | 24 | +    }
 | 
		
	
		
			
			|  | 25 | +
 | 
		
	
		
			
			|  | 26 | +    @Test
 | 
		
	
		
			
			|  | 27 | +    public void testCommandSerializeNull() throws Exception
 | 
		
	
		
			
			|  | 28 | +    {
 | 
		
	
		
			
			|  | 29 | +        Command c = new Command(null);
 | 
		
	
		
			
			|  | 30 | +        String result = commandToString(c);
 | 
		
	
		
			
			|  | 31 | +        assertEquals(result, "Unknown");
 | 
		
	
		
			
			|  | 32 | +    }
 | 
		
	
		
			
			|  | 33 | +
 | 
		
	
		
			
			|  | 34 | +    @Test
 | 
		
	
		
			
			|  | 35 | +    public void testCommandSerializeEmpty() throws Exception
 | 
		
	
		
			
			|  | 36 | +    {
 | 
		
	
		
			
			|  | 37 | +        Command c = new Command("");
 | 
		
	
		
			
			|  | 38 | +        String result = commandToString(c);
 | 
		
	
		
			
			|  | 39 | +        assertEquals(result, "Unknown");
 | 
		
	
		
			
			|  | 40 | +    }
 | 
		
	
		
			
			|  | 41 | +
 | 
		
	
		
			
			|  | 42 | +    @Test
 | 
		
	
		
			
			|  | 43 | +    public void testCommandSerializeName() throws Exception
 | 
		
	
		
			
			|  | 44 | +    {
 | 
		
	
		
			
			|  | 45 | +        Command c = new Command("Test");
 | 
		
	
		
			
			|  | 46 | +        String result = commandToString(c);
 | 
		
	
		
			
			|  | 47 | +        assertEquals(result, "Test");
 | 
		
	
		
			
			|  | 48 | +    }
 | 
		
	
		
			
			|  | 49 | +
 | 
		
	
		
			
			|  | 50 | +    @Test
 | 
		
	
		
			
			|  | 51 | +    public void testCommandSerializeArgument() throws Exception
 | 
		
	
		
			
			|  | 52 | +    {
 | 
		
	
		
			
			|  | 53 | +        Command c = new Command("Test");
 | 
		
	
		
			
			|  | 54 | +        c.addArgument("an_argument");
 | 
		
	
		
			
			|  | 55 | +        String result = commandToString(c);
 | 
		
	
		
			
			|  | 56 | +        assertEquals(result, "Test#an_argument");
 | 
		
	
		
			
			|  | 57 | +    }
 | 
		
	
		
			
			|  | 58 | +
 | 
		
	
		
			
			|  | 59 | +    @Test
 | 
		
	
		
			
			|  | 60 | +    public void testCommandSerializeArguments() throws Exception
 | 
		
	
		
			
			|  | 61 | +    {
 | 
		
	
		
			
			|  | 62 | +        Command c = new Command("Test");
 | 
		
	
		
			
			|  | 63 | +        c.addArgument("an_argument");
 | 
		
	
		
			
			|  | 64 | +        c.addArgument("an_argument2");
 | 
		
	
		
			
			|  | 65 | +        String result = commandToString(c);
 | 
		
	
		
			
			|  | 66 | +        assertEquals(result, "Test#an_argument#an_argument2");
 | 
		
	
		
			
			|  | 67 | +    }
 | 
		
	
		
			
			|  | 68 | +
 | 
		
	
		
			
			|  | 69 | +    @Test
 | 
		
	
		
			
			|  | 70 | +    public void testCommandDeserializeNull() throws Exception
 | 
		
	
		
			
			|  | 71 | +    {
 | 
		
	
		
			
			|  | 72 | +        Command c = Command.fromString(null);
 | 
		
	
		
			
			|  | 73 | +        assertNull(c);
 | 
		
	
		
			
			|  | 74 | +    }
 | 
		
	
		
			
			|  | 75 | +
 | 
		
	
		
			
			|  | 76 | +    @Test
 | 
		
	
		
			
			|  | 77 | +    public void testCommandDeserializeEmpty() throws Exception
 | 
		
	
		
			
			|  | 78 | +    {
 | 
		
	
		
			
			|  | 79 | +        Command c = Command.fromString("");
 | 
		
	
		
			
			|  | 80 | +        assertNull(c);
 | 
		
	
		
			
			|  | 81 | +    }
 | 
		
	
		
			
			|  | 82 | +
 | 
		
	
		
			
			|  | 83 | +    @Test
 | 
		
	
		
			
			|  | 84 | +    public void testCommandDeserializeName() throws Exception
 | 
		
	
		
			
			|  | 85 | +    {
 | 
		
	
		
			
			|  | 86 | +        Command c = Command.fromString("Test");
 | 
		
	
		
			
			|  | 87 | +        assertNotNull(c);
 | 
		
	
		
			
			|  | 88 | +        assertEquals(c.getCommandName(), "Test");
 | 
		
	
		
			
			|  | 89 | +        assertEquals(c.getArgumentCount(), 0);
 | 
		
	
		
			
			|  | 90 | +    }
 | 
		
	
		
			
			|  | 91 | +
 | 
		
	
		
			
			|  | 92 | +    @Test
 | 
		
	
		
			
			|  | 93 | +    public void testCommandDeserializeArgument() throws Exception
 | 
		
	
		
			
			|  | 94 | +    {
 | 
		
	
		
			
			|  | 95 | +        Command c = Command.fromString("Test#an_argument");
 | 
		
	
		
			
			|  | 96 | +        assertNotNull(c);
 | 
		
	
		
			
			|  | 97 | +        assertEquals(c.getCommandName(), "Test");
 | 
		
	
		
			
			|  | 98 | +        assertEquals(c.getArgumentCount(), 1);
 | 
		
	
		
			
			|  | 99 | +        assertEquals(c.getArgument(0), "an_argument");
 | 
		
	
		
			
			|  | 100 | +    }
 | 
		
	
		
			
			|  | 101 | +
 | 
		
	
		
			
			|  | 102 | +    @Test
 | 
		
	
		
			
			|  | 103 | +    public void testCommandDeserializeArguments() throws Exception
 | 
		
	
		
			
			|  | 104 | +    {
 | 
		
	
		
			
			|  | 105 | +        Command c = Command.fromString("Test#an_argument#an_argument2");
 | 
		
	
		
			
			|  | 106 | +        assertNotNull(c);
 | 
		
	
		
			
			|  | 107 | +        assertEquals(c.getCommandName(), "Test");
 | 
		
	
		
			
			|  | 108 | +        assertEquals(c.getArgumentCount(), 2);
 | 
		
	
		
			
			|  | 109 | +        assertEquals(c.getArgument(0), "an_argument");
 | 
		
	
		
			
			|  | 110 | +        assertEquals(c.getArgument(1), "an_argument2");
 | 
		
	
		
			
			|  | 111 | +    }
 | 
		
	
		
			
			|  | 112 | +}
 |