/*
 * DISCLAIMER
 *
 * Copyright 2016 ArangoDB GmbH, Cologne, Germany
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Copyright holder is ArangoDB GmbH, Cologne, Germany
 */

package com.arangodb.internal;

import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.junit.Test;

/**
 * @author Mark Vollmary
 *
 */
public class DefaultHostHandlerTest {

	@Test
	public void singleHost() {
		final Host h1 = new Host("127.0.0.1", 8529);
		final List<Host> hosts = Collections.<Host> singletonList(h1);
		final HostHandler hh = new DefaultHostHandler(hosts);
		assertThat(hh.get(), is(h1));
	}

	@Test
	public void multipleHosts() {
		final Host h1 = new Host("127.0.0.1", 8529);
		final Host h2 = new Host("127.0.0.2", 8529);
		final List<Host> hosts = new ArrayList<Host>();
		hosts.add(h1);
		hosts.add(h2);

		final HostHandler hh = new DefaultHostHandler(hosts);
		assertThat(hh.get(), is(h1));
		assertThat(hh.change(), is(h2));
		assertThat(hh.get(), is(h2));
		assertThat(hh.change(), is(nullValue()));
	}

}

@@ -1587,32 +1587,66 @@
 andler(hosts);%0D%0A
+%09%09for (int i = 0; i %3C 3; i++) %7B%0D%0A%09
 %09%09assertThat(hh.
@@ -1660,24 +1660,25 @@
 is(h1));%0D%0A%09%09
+%09
 assertThat(h
@@ -1691,32 +1691,33 @@
 ge(), is(h2));%0D%0A
+%09
 %09%09assertThat(hh.
@@ -1729,24 +1729,94 @@
 , is(h2));%0D%0A
+%09%09%09if (i %3C 2) %7B%0D%0A%09%09%09%09assertThat(hh.change(), is(h1));%0D%0A%09%09%09%7D else %7B%0D%0A%09%09
 %09%09assertThat
@@ -1844,21 +1844,32 @@
 Value()));%0D%0A
+%09%09%09%7D%0D%0A%09%09%7D%0D%0A
 %09%7D%0D%0A%0D%0A%7D%0D%0A

Fix test