package io.cloudevents.format;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.HashMap;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

/**
 * 
 * @author fabiojose
 *
 */
public class WireTest {
	
	@Rule
	public ExpectedException expectedEx = ExpectedException.none();

	@Test
	public void throws_error_when_null_headers() {
		
		// setup
		expectedEx.expect(NullPointerException.class);
		
		new Wire<String, String, Object>("payload", null);
	}
	
	@Test
	public void should_ok_when_null_payload() {
		Wire<String, String, Object> expected = 
				new Wire<>(null, new HashMap<>());
		
		assertFalse(expected.getPayload().isPresent());
	}
	
	@Test
	public void should_ok_when_payload_not_null() {
		Wire<String, String, Object> actual = 
				new Wire<>("payload", new HashMap<>());
		
		assertTrue(actual.getPayload().isPresent());
		assertEquals("payload", actual.getPayload().get());
	}
	
}

@@ -183,16 +183,38 @@
 HashMap;
+%0Aimport java.util.Map;
 %0A%0Aimport
@@ -609,32 +609,406 @@
 l);%0A%09%7D%0A%09%0A%09@Test%0A
+%09public void throws_when_try_to_change_headers() %7B%0A%09%09// setup%0A%09%09expectedEx.expect(UnsupportedOperationException.class);%0A%09%09%0A%09%09Map%3CString, Object%3E headers = new HashMap%3C%3E();%0A%09%09headers.put(%22contenttype%22, %22application/json%22);%0A%09%09%0A%09%09// act%0A%09%09Wire%3CString, String, Object%3E wire = new Wire%3C%3E(%22payload%22, headers);%0A%09%09%0A%09%09wire.getHeaders().put(%22my-header%22, %22my-header-val%22);%0A%09%7D%0A%09%0A%09@Test%0A
 %09public void sho

Test for the immutable result