package io.ljunggren.sendgrid.api.service;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.NullAndEmptySource;
import org.junit.jupiter.params.provider.ValueSource;

class BaseServiceTest {

	/** Concrete subclass used purely so we can exercise the protected constructor. */
	private static class TestService extends BaseService {
		TestService(String apiKey) {
			super(apiKey);
		}
	}

	@ParameterizedTest
	@NullAndEmptySource
	@ValueSource(strings = { "  ", "\t" })
	void apiKeyConstructor_rejectsNullOrBlank(String apiKey) {
		assertThrows(IllegalArgumentException.class, () -> new TestService(apiKey));
	}

	@Test
	void apiKeyConstructor_acceptsNonBlank() {
		TestService service = new TestService("sg-key");
		assertNotNull(service.sendGrid);
	}

}
