package org.apache.commons.io;

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

import java.nio.charset.Charset;
import java.nio.charset.UnsupportedCharsetException;

import org.junit.jupiter.api.Test;

public class CharsetsTest {
	
	@Test
	public void testToCharset1() {
		Charset charset0 = Charsets.UTF_16BE;
		Charset charset1 = Charsets.toCharset(charset0);
		Charset charset2 = Charsets.toCharset(charset0);
		Charset charset3 = Charsets.toCharset(charset2);
		Charset charset4 = Charsets.toCharset(charset2);
		Charset charset5 = Charsets.toCharset(charset2);
		Charset charset6 = Charsets.toCharset(charset5);
		Charset charset7 = Charsets.toCharset(charset6);
		Charset charset8 = Charsets.toCharset(charset6);
		Charset charset9 = Charsets.toCharset(charset6);
		Charset charset10 = Charsets.toCharset(charset9);
		Charset charset11 = Charsets.toCharset(charset9);
		Charset charset12 = Charsets.toCharset(charset9);
		Charset charset13 = Charsets.toCharset(charset9);
		Charset charset14 = Charsets.toCharset(charset13);
		Charset charset15 = Charsets.toCharset(charset13);
		Class<?> wildcardClass = charset15.getClass();
		assertNotNull(charset0);
		assertNotNull(charset1);
		assertNotNull(charset2);
		assertNotNull(charset3);
		assertNotNull(charset4);
		assertNotNull(charset5);
		assertNotNull(charset6);
		assertNotNull(charset7);
		assertNotNull(charset8);
		assertNotNull(charset9);
		assertNotNull(charset10);
		assertNotNull(charset11);
		assertNotNull(charset12);
		assertNotNull(charset13);
		assertNotNull(charset14);
		assertNotNull(charset15);
		assertNotNull(wildcardClass);
	}
	
	@Test
	public void testAssertThrowsMessage_toCharset_charsetUnsupported() {
		final UnsupportedCharsetException thrown = assertThrows(UnsupportedCharsetException.class,
				() -> Charsets.toCharset("unsupported"));
		assertEquals("unsupported", thrown.getMessage());
	}
	
	@Test
	public void testToCharset2() {
		Charset charset0 = Charsets.ISO_8859_1;
		Charset charset1 = Charsets.toCharset(charset0);
		Charset charset2 = Charsets.toCharset(charset1);
		Charset charset3 = Charsets.toCharset(charset1);
		Charset charset4 = Charsets.toCharset(charset3);
		Charset charset5 = Charsets.toCharset(charset3);
		Charset charset6 = Charsets.toCharset(charset5);
		Class<?> wildcardClass7 = charset5.getClass();
		assertNotNull(charset0);
		assertNotNull(charset1);
		assertNotNull(charset2);
		assertNotNull(charset3);
		assertNotNull(charset4);
		assertNotNull(charset5);
		assertNotNull(charset6);
		assertNotNull(wildcardClass7);
	}
}
