package nl.sikken.bertrik.hab.habitat;

import java.util.Arrays;
import java.util.Date;

import org.junit.Test;
import org.mockito.Mockito;

import nl.sikken.bertrik.hab.Sentence;

/**
 * @author bertrik
 *
 */
public final class HabitatUploaderTest {
	
	/**
	 * Happy flow scenario.
	 * 
	 * Verifies that a request to upload results in an actual upload.
	 * 
	 * @throws InterruptedException
	 */
	@Test
	public void testMockedHappyFlow() throws InterruptedException {
		// create a mocked rest client
		final IHabitatRestApi restClient = Mockito.mock(IHabitatRestApi.class);
		Mockito.when(restClient.updateListener(Mockito.anyString(), Mockito.anyString())).thenReturn("OK");
		final HabitatUploader uploader = new HabitatUploader(restClient);
		
		// test it
		uploader.start();
		try {
			final IHabReceiver receiver = createReceiver();
			final Date date = new Date();
			final Sentence sentence = new Sentence("NOTAFLIGHT", 1, date, 52.0182307, 4.695772, 1000);
			uploader.upload(sentence.format(), Arrays.asList(receiver), date);
			
			Mockito.verify(restClient, Mockito.timeout(3000)).updateListener(Mockito.anyString(), Mockito.anyString());
		} finally {
			uploader.stop();
		}
	}

	private IHabReceiver createReceiver() {
		final IHabReceiver receiver = new IHabReceiver() {
			@Override
			public Location getLocation() {
				return new Location(52.0182307, 4.695772, 4);
			}
			@Override
			public String getCallsign() {
				return "BERTRIK";
			}
		};
		return receiver;
	}

}

@@ -866,16 +866,64 @@
 eceiver(
+%22BERTRIK%22, new Location(52.0182307, 4.695772, 4)
 );%0D%0A%09%09%09f
@@ -1315,24 +1315,58 @@
 ateReceiver(
+String callSign, Location location
 ) %7B%0D%0A%09%09final
@@ -1477,45 +1477,16 @@
 urn 
-new L
+l
 ocation
-(52.0182307, 4.695772, 4)
 ;%0D%0A%09
@@ -1549,25 +1549,24 @@
 %09return 
-%22BERTRIK%22
+callSign
 ;%0D%0A%09%09%09%7D%0D

Make createReceiver method more flexible.