package com.googlecode.jslint4java.cli;

import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;

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

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import com.beust.jcommander.ParameterException;

public class CharsetConverterTest {

    private static final String UNKNOWN_CHARSET_NAME = "bob";
    private final CharsetConverter cc = new CharsetConverter();

    @Rule
    public final ExpectedException thrown = ExpectedException.none();

    @Test
    public void testConvert() throws Exception {
        assertThat(cc.convert("UTF-8"), is(Charset.forName("UTF-8")));
    }

    @Test
    public void testIllegalCharsetName() throws Exception {
        thrown.expect(ParameterException.class);
        thrown.expectMessage("unknown encoding");
        cc.convert("!@#$%^&*(");
    }

    @Test
    public void testUnknownCharset() throws Exception {
        // We only want to run this test if we can guarantee that the charset _doesn't_ exist in the
        // system first. Otherwise, we'll just have to ignore this test.
        try {
            Charset.forName(UNKNOWN_CHARSET_NAME);
        } catch (UnsupportedCharsetException e) {
            // We're good to run the test.
            thrown.expect(ParameterException.class);
            thrown.expectMessage("unknown encoding");
            cc.convert(UNKNOWN_CHARSET_NAME);
        }
    }

}

@@ -115,93 +115,74 @@
 .*;%0A
-%0A
 import 
-java.nio.charset.Charset;%0Aimport java.nio.charset.UnsupportedCharsetException
+static org.junit.Assume.*;%0A%0Aimport java.nio.charset.Charset
 ;%0A%0Ai
@@ -1161,119 +1161,75 @@
     
-try %7B%0A            Charset.forName(UNKNOWN_CHARSET_NAME);%0A        %7D catch (UnsupportedCharsetException e) %7B%0A    
+assumeThat(Charset.isSupported(UNKNOWN_CHARSET_NAME), is(false));%0A%0A
     
@@ -1263,36 +1263,32 @@
 e test.%0A        
- 
-   
 thrown.expect(Pa
@@ -1308,28 +1308,24 @@
 ion.class);%0A
-    
         thro
@@ -1366,28 +1366,24 @@
 %22);%0A        
-    
 cc.convert(U
@@ -1408,18 +1408,8 @@
 E);%0A
-        %7D%0A
     

Use assumption to simplify test.