// Path: Source/src/de/tum/in/www1/jReto/routing/algorithm/Tree.java
// public class Tree<T> {
//     /** The tree's associated value */
// 	public final T value;
//     /** The tree's subtrees */
// 	public final Set<Tree<T>> children;
// 	
//     /** Constructs a new tree given a value and a set of subtrees. */
// 	public Tree(T value, Set<Tree<T>> children) {
// 		this.value = value;
// 		this.children = children;
// 	}
// 	@SafeVarargs
// 	public Tree(T value, Tree<T>... children) {
// 		this.value = value;
// 		this.children = new HashSet<>(Arrays.asList(children));
// 	}
// 	
// 	public int size() {
// 		int result = 1;
// 		
// 		if (this.children == null) return result;
// 		
// 		for (Tree<T> child : this.children) {
// 			result += child.size();
// 		}
// 		
// 		return result;
// 	}
//     /** Whether the tree is a leaf */
// 	public boolean isLeaf() {
// 		return this.children.size() == 0;
// 	}
// 	public String toString() {
// 		return "{value: "+this.value+"; children: "+this.children+"}";
// 	}
// 	@Override
// 	public int hashCode() {
// 		return this.value.hashCode() ^ this.children.hashCode();
// 	}
// 	/** Two trees are equal if their values and subtrees are equal.*/
// 	@Override
// 	public boolean equals(Object obj) {
// 		if (!obj.getClass().equals(this.getClass())) return false;
// 		
// 		@SuppressWarnings("unchecked")
// 		Tree<T> other = (Tree<T>) obj;
// 		
// 		if (!this.value.equals(other.value)) return false;
// 		return this.children.equals(other.children);
// 	}
// }
// 
// Path: Source/src/de/tum/in/www1/jReto/routing/packets/MulticastHandshake.java
// public class MulticastHandshake implements Packet {
// 	public final static PacketType TYPE = PacketType.ROUTING_HANDSHAKE;
// 	public final static int MINIMUM_LENGTH = Constants.PACKET_TYPE_SIZE + Constants.UUID_SIZE;
// 	
// 	public final UUID sourcePeerIdentifier;
// 	public final Set<UUID> destinationIdentifiers;
// 	public final Tree<UUID> nextHopsTree;
// 	
// 	public MulticastHandshake(UUID sourcePeerIdentifier, Set<UUID> destinationIdentifiers, Tree<UUID> nextHopsTree) {
// 		if (destinationIdentifiers.size() == 0) throw new IllegalArgumentException("At least one destination is required.");
// 		
// 		this.sourcePeerIdentifier = sourcePeerIdentifier;
// 		this.destinationIdentifiers = destinationIdentifiers;
// 		this.nextHopsTree = nextHopsTree;
// 	}
// 	
// 	public static MulticastHandshake deserialize(ByteBuffer data) {
// 		DataReader reader = new DataReader(data);
// 		if (!DataChecker.check(reader, TYPE, MINIMUM_LENGTH)) return null;
// 		
// 		UUID sourcePeerIdentifier = reader.getUUID();
// 		int destinationsCount = reader.getInt();
// 		
// 		if (destinationsCount == 0) {
// 			System.err.println("Invalid MulticastHandshake: No destinations specified.");
// 			return null;
// 		}
// 		if (!reader.checkRemaining(destinationsCount * Constants.UUID_SIZE)) {
// 			System.err.println("Invalid MulticastHandshake: Not enough data remaining to read destinations.");
// 			return null;
// 		}
// 		
// 		Set<UUID> destinations = new HashSet<>();
// 		for (int i=0; i<destinationsCount; i++) {
// 			destinations.add(reader.getUUID());
// 		}
// 		
// 		Tree<UUID> nextHopsTree = deserializeNextHopTree(reader);
// 		
// 		return new MulticastHandshake(sourcePeerIdentifier, destinations, nextHopsTree);
// 	}
// 	public ByteBuffer serialize() {
// 		DataWriter data = new DataWriter(MINIMUM_LENGTH + Constants.INT_SIZE + destinationIdentifiers.size() * Constants.UUID_SIZE + nextHopsTree.size() * (Constants.INT_SIZE + Constants.UUID_SIZE));
// 		data.add(TYPE);
// 		data.add(this.sourcePeerIdentifier);
// 		data.add(destinationIdentifiers.size());
// 		for (UUID destinationIdentifier : destinationIdentifiers) data.add(destinationIdentifier);
// 		
// 		serializeNextHopTree(data, nextHopsTree);
// 		
// 		return data.getData();
// 	}
// 	
// 	private static Tree<UUID> deserializeNextHopTree(DataReader reader) {
// 		if (!reader.checkRemaining(Constants.UUID_SIZE + Constants.INT_SIZE)) {
// 			System.err.println("Invalid MulticastHandshake: Not enough data remaining to read hop tree.");
// 			return null;
// 		}
// 		
// 		UUID value = reader.getUUID();
// 		int childrenCount = reader.getInt();
// 		Set<Tree<UUID>> children = new HashSet<>();
// 		
// 		for (int i=0; i<childrenCount; i++) {
// 			Tree<UUID> child = deserializeNextHopTree(reader);
// 			if (child == null) return null;
// 			
// 			children.add(child);
// 		}
// 		
// 		return new Tree<>(value, children);
// 	}
// 	private void serializeNextHopTree(DataWriter data, Tree<UUID> tree) {
// 		data.add(tree.value);
// 		data.add(tree.children.size());
// 		
// 		for (Tree<UUID> child : tree.children) {
// 			serializeNextHopTree(data, child);
// 		}
// 	}
// }


import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.HashSet;
import java.util.UUID;
import org.junit.Test;
import de.tum.in.www1.jReto.routing.algorithm.Tree;
import de.tum.in.www1.jReto.routing.packets.MulticastHandshake;
package jReto.unit;





public class MulticastPacketTests {
	@Test
	public void testMulticastPacketSimple() {
		Tree<UUID> testTree = new Tree<>(UUID.randomUUID());
				
// Path: Source/src/de/tum/in/www1/jReto/routing/algorithm/Tree.java
// public class Tree<T> {
//     /** The tree's associated value */
// 	public final T value;
//     /** The tree's subtrees */
// 	public final Set<Tree<T>> children;
// 	
//     /** Constructs a new tree given a value and a set of subtrees. */
// 	public Tree(T value, Set<Tree<T>> children) {
// 		this.value = value;
// 		this.children = children;
// 	}
// 	@SafeVarargs
// 	public Tree(T value, Tree<T>... children) {
// 		this.value = value;
// 		this.children = new HashSet<>(Arrays.asList(children));
// 	}
// 	
// 	public int size() {
// 		int result = 1;
// 		
// 		if (this.children == null) return result;
// 		
// 		for (Tree<T> child : this.children) {
// 			result += child.size();
// 		}
// 		
// 		return result;
// 	}
//     /** Whether the tree is a leaf */
// 	public boolean isLeaf() {
// 		return this.children.size() == 0;
// 	}
// 	public String toString() {
// 		return "{value: "+this.value+"; children: "+this.children+"}";
// 	}
// 	@Override
// 	public int hashCode() {
// 		return this.value.hashCode() ^ this.children.hashCode();
// 	}
// 	/** Two trees are equal if their values and subtrees are equal.*/
// 	@Override
// 	public boolean equals(Object obj) {
// 		if (!obj.getClass().equals(this.getClass())) return false;
// 		
// 		@SuppressWarnings("unchecked")
// 		Tree<T> other = (Tree<T>) obj;
// 		
// 		if (!this.value.equals(other.value)) return false;
// 		return this.children.equals(other.children);
// 	}
// }
// 
// Path: Source/src/de/tum/in/www1/jReto/routing/packets/MulticastHandshake.java
// public class MulticastHandshake implements Packet {
// 	public final static PacketType TYPE = PacketType.ROUTING_HANDSHAKE;
// 	public final static int MINIMUM_LENGTH = Constants.PACKET_TYPE_SIZE + Constants.UUID_SIZE;
// 	
// 	public final UUID sourcePeerIdentifier;
// 	public final Set<UUID> destinationIdentifiers;
// 	public final Tree<UUID> nextHopsTree;
// 	
// 	public MulticastHandshake(UUID sourcePeerIdentifier, Set<UUID> destinationIdentifiers, Tree<UUID> nextHopsTree) {
// 		if (destinationIdentifiers.size() == 0) throw new IllegalArgumentException("At least one destination is required.");
// 		
// 		this.sourcePeerIdentifier = sourcePeerIdentifier;
// 		this.destinationIdentifiers = destinationIdentifiers;
// 		this.nextHopsTree = nextHopsTree;
// 	}
// 	
// 	public static MulticastHandshake deserialize(ByteBuffer data) {
// 		DataReader reader = new DataReader(data);
// 		if (!DataChecker.check(reader, TYPE, MINIMUM_LENGTH)) return null;
// 		
// 		UUID sourcePeerIdentifier = reader.getUUID();
// 		int destinationsCount = reader.getInt();
// 		
// 		if (destinationsCount == 0) {
// 			System.err.println("Invalid MulticastHandshake: No destinations specified.");
// 			return null;
// 		}
// 		if (!reader.checkRemaining(destinationsCount * Constants.UUID_SIZE)) {
// 			System.err.println("Invalid MulticastHandshake: Not enough data remaining to read destinations.");
// 			return null;
// 		}
// 		
// 		Set<UUID> destinations = new HashSet<>();
// 		for (int i=0; i<destinationsCount; i++) {
// 			destinations.add(reader.getUUID());
// 		}
// 		
// 		Tree<UUID> nextHopsTree = deserializeNextHopTree(reader);
// 		
// 		return new MulticastHandshake(sourcePeerIdentifier, destinations, nextHopsTree);
// 	}
// 	public ByteBuffer serialize() {
// 		DataWriter data = new DataWriter(MINIMUM_LENGTH + Constants.INT_SIZE + destinationIdentifiers.size() * Constants.UUID_SIZE + nextHopsTree.size() * (Constants.INT_SIZE + Constants.UUID_SIZE));
// 		data.add(TYPE);
// 		data.add(this.sourcePeerIdentifier);
// 		data.add(destinationIdentifiers.size());
// 		for (UUID destinationIdentifier : destinationIdentifiers) data.add(destinationIdentifier);
// 		
// 		serializeNextHopTree(data, nextHopsTree);
// 		
// 		return data.getData();
// 	}
// 	
// 	private static Tree<UUID> deserializeNextHopTree(DataReader reader) {
// 		if (!reader.checkRemaining(Constants.UUID_SIZE + Constants.INT_SIZE)) {
// 			System.err.println("Invalid MulticastHandshake: Not enough data remaining to read hop tree.");
// 			return null;
// 		}
// 		
// 		UUID value = reader.getUUID();
// 		int childrenCount = reader.getInt();
// 		Set<Tree<UUID>> children = new HashSet<>();
// 		
// 		for (int i=0; i<childrenCount; i++) {
// 			Tree<UUID> child = deserializeNextHopTree(reader);
// 			if (child == null) return null;
// 			
// 			children.add(child);
// 		}
// 		
// 		return new Tree<>(value, children);
// 	}
// 	private void serializeNextHopTree(DataWriter data, Tree<UUID> tree) {
// 		data.add(tree.value);
// 		data.add(tree.children.size());
// 		
// 		for (Tree<UUID> child : tree.children) {
// 			serializeNextHopTree(data, child);
// 		}
// 	}
// }


// Path: Source/test/jReto/unit/MulticastPacketTests.java
import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.HashSet;
import java.util.UUID;
import org.junit.Test;
import de.tum.in.www1.jReto.routing.algorithm.Tree;
import de.tum.in.www1.jReto.routing.packets.MulticastHandshake;

package jReto.unit;





public class MulticastPacketTests {
	@Test
	public void testMulticastPacketSimple() {
		Tree<UUID> testTree = new Tree<>(UUID.randomUUID());
				
		MulticastHandshake handshake = new MulticastHandshake(UUID.randomUUID(), new HashSet<UUID>(Arrays.asList(UUID.randomUUID())), testTree);