// Path: contrib/grpc-spring/src/main/java/com/salesforce/grpc/contrib/spring/GrpcServerHost.java
// static final int MAX_PORT = 65535;
// 
// Path: contrib/grpc-spring/src/main/java/com/salesforce/grpc/contrib/spring/GrpcServerHost.java
// static final int MIN_PORT = 0;


import com.google.common.collect.ImmutableMap;
import io.grpc.BindableService;
import io.grpc.Server;
import org.assertj.core.api.Condition;
import org.junit.Test;
import org.mockito.internal.stubbing.defaultanswers.TriesToReturnSelf;
import org.springframework.context.ApplicationContext;
import java.io.IOException;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import static com.salesforce.grpc.contrib.spring.GrpcServerHost.MAX_PORT;
import static com.salesforce.grpc.contrib.spring.GrpcServerHost.MIN_PORT;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*;
/*
 *  Copyright (c) 2019, Salesforce.com, Inc.
 *  All rights reserved.
 *  Licensed under the BSD 3-Clause license.
 *  For full license text, see LICENSE.txt file in the repo root  or https://opensource.org/licenses/BSD-3-Clause
 */

package com.salesforce.grpc.contrib.spring;/*
 * Copyright, 1999-2017, SALESFORCE.com
 * All Rights Reserved
 * Company Confidential
 */




public class GrpcServerHostTest {

    @Test
    public void constructorThrowsForPortLessThanMin() {
        final int port = ThreadLocalRandom.current().nextInt(Integer.MIN_VALUE, MIN_PORT);
        final long shutdownWaitTimeInMillis = ThreadLocalRandom.current().nextLong(1000, 10000);

        assertThatThrownBy(() -> new GrpcServerHost(port, shutdownWaitTimeInMillis))
                .isInstanceOf(IllegalArgumentException.class)
                .hasMessageContaining("port");
    }

    @Test
    public void constructorThrowsForPortGreaterThanMax() {
// Path: contrib/grpc-spring/src/main/java/com/salesforce/grpc/contrib/spring/GrpcServerHost.java
// static final int MAX_PORT = 65535;
// 
// Path: contrib/grpc-spring/src/main/java/com/salesforce/grpc/contrib/spring/GrpcServerHost.java
// static final int MIN_PORT = 0;


// Path: contrib/grpc-spring/src/test/java/com/salesforce/grpc/contrib/spring/GrpcServerHostTest.java
import com.google.common.collect.ImmutableMap;
import io.grpc.BindableService;
import io.grpc.Server;
import org.assertj.core.api.Condition;
import org.junit.Test;
import org.mockito.internal.stubbing.defaultanswers.TriesToReturnSelf;
import org.springframework.context.ApplicationContext;
import java.io.IOException;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import static com.salesforce.grpc.contrib.spring.GrpcServerHost.MAX_PORT;
import static com.salesforce.grpc.contrib.spring.GrpcServerHost.MIN_PORT;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*;

/*
 *  Copyright (c) 2019, Salesforce.com, Inc.
 *  All rights reserved.
 *  Licensed under the BSD 3-Clause license.
 *  For full license text, see LICENSE.txt file in the repo root  or https://opensource.org/licenses/BSD-3-Clause
 */

package com.salesforce.grpc.contrib.spring;/*
 * Copyright, 1999-2017, SALESFORCE.com
 * All Rights Reserved
 * Company Confidential
 */




public class GrpcServerHostTest {

    @Test
    public void constructorThrowsForPortLessThanMin() {
        final int port = ThreadLocalRandom.current().nextInt(Integer.MIN_VALUE, MIN_PORT);
        final long shutdownWaitTimeInMillis = ThreadLocalRandom.current().nextLong(1000, 10000);

        assertThatThrownBy(() -> new GrpcServerHost(port, shutdownWaitTimeInMillis))
                .isInstanceOf(IllegalArgumentException.class)
                .hasMessageContaining("port");
    }

    @Test
    public void constructorThrowsForPortGreaterThanMax() {
        final int port = ThreadLocalRandom.current().nextInt(MAX_PORT, Integer.MAX_VALUE);