CharWidthConverter { public String convert(String input) { if (StringUtils.isEmpty(input)) { return StringUtils.EMPTY; } String result = null; switch (config.getMode()) { case NFKC: result = Normalizer.normalize(input, Normalizer.Form.NFKC); break; case HALF_TO_FULL: result = halfwidthToFullwidth(input); break; case FULL_TO_HALF: result = fullwidthToHalfwidth(input); break; default: break; } return result; } CharWidthConverter(ConversionConfig config); String convert(String input);  }
@Test public void testConvertNFKCNull() { ConversionConfig config = new ConversionConfig.Builder().nfkc().build(); CharWidthConverter converter = new CharWidthConverter(config); assertEquals(StringUtils.EMPTY, converter.convert(null)); }
@Test public void testConvertToFullForNull() { ConversionConfig config = new ConversionConfig.Builder().halfToFull().build(); CharWidthConverter converter = new CharWidthConverter(config); assertEquals(StringUtils.EMPTY, converter.convert(null)); }
@Test public void testConvertToHalfForNull() { ConversionConfig config = new ConversionConfig.Builder().fullToHalf().build(); CharWidthConverter converter = new CharWidthConverter(config); assertEquals(StringUtils.EMPTY, converter.convert(null)); }
@Test public void testConvertNFKC() { ConversionConfig config = new ConversionConfig.Builder().nfkc().build(); CharWidthConverter converter = new CharWidthConverter(config); for (String k : EXPECTED_NFKC.keySet()) { assertEquals(EXPECTED_NFKC.get(k), converter.convert(k)); } }
@Test public void testConvertHalfToFullDigit() { ConversionConfig config = new ConversionConfig.Builder() .halfToFull() .withDigit(true) .withLetter(false) .withKatanana(false) .withOtherChars(false) .build(); CharWidthConverter converter = new CharWidthConverter(config); assertEquals(FULL_DIGIT, converter.convert(HALF_DIGIT)); }
@Test public void testConvertHalfToFullLetter() { ConversionConfig config = new ConversionConfig.Builder() .halfToFull() .withDigit(false) .withLetter(true) .withKatanana(false) .withOtherChars(false) .build(); CharWidthConverter converter = new CharWidthConverter(config); assertEquals(FULL_LETTER, converter.convert(HALF_LETTER)); }
@Test public void testConvertHalfToFullKatakana() { ConversionConfig config = new ConversionConfig.Builder() .halfToFull() .withDigit(false) .withLetter(false) .withKatanana(true) .withOtherChars(false) .build(); CharWidthConverter converter = new CharWidthConverter(config); assertEquals(FULL_KATAKANA, converter.convert(HALF_KATAKANA)); }
@Test public void testConvertHalfToFullKatakanaWithSoundMark() { ConversionConfig config = new ConversionConfig.Builder() .halfToFull() .withDigit(false) .withLetter(false) .withKatanana(true) .withOtherChars(false) .build(); CharWidthConverter converter = new CharWidthConverter(config); assertEquals(FULL_KATAKANA_WITH_SOUND_MARK, converter.convert(HALF_KATAKANA_WITH_SOUND_MARK)); }
@Test public void testConvertHalfToFullSymbol() { ConversionConfig config = new ConversionConfig.Builder() .halfToFull() .withDigit(false) .withLetter(false) .withKatanana(false) .withOtherChars(true) .build(); CharWidthConverter converter = new CharWidthConverter(config); assertEquals(HALF_DIGIT + HALF_LETTER + FULL_SYMBOL, converter.convert(HALF_DIGIT + HALF_LETTER + HALF_SYMBOL)); }
@Test public void testConvertHalfToFullAllMixed() { ConversionConfig config = new ConversionConfig.Builder() .halfToFull() .withDigit(true) .withLetter(true) .withKatanana(true) .withOtherChars(true) .build(); CharWidthConverter converter = new CharWidthConverter(config); assertEquals(FULL_MIXED, converter.convert(HALF_MIXED)); }
@Test public void testConvertHalfToHalfAllMixedWithNBSP() { ConversionConfig config = new ConversionConfig.Builder() .halfToFull() .withDigit(true) .withLetter(true) .withKatanana(true) .withOtherChars(true) .build(); CharWidthConverter converter = new CharWidthConverter(config); assertEquals(FULL_MIXED, converter.convert(HALF_MIXED_WITH_NBSP)); }
@Test public void testConvertFullToHalfDigit() { ConversionConfig config = new ConversionConfig.Builder() .fullToHalf() .withDigit(true) .withLetter(false) .withKatanana(false) .withOtherChars(false) .build(); CharWidthConverter converter = new CharWidthConverter(config); assertEquals(HALF_DIGIT, converter.convert(FULL_DIGIT)); }
@Test public void testConvertFullToHalfLetter() { ConversionConfig config = new ConversionConfig.Builder() .fullToHalf() .withDigit(false) .withLetter(true) .withKatanana(false) .withOtherChars(false) .build(); CharWidthConverter converter = new CharWidthConverter(config); assertEquals(HALF_LETTER, converter.convert(FULL_LETTER)); }
@Test public void testConvertFullToHalfKatakana() { ConversionConfig config = new ConversionConfig.Builder() .fullToHalf() .withDigit(false) .withLetter(false) .withKatanana(true) .withOtherChars(false) .build(); CharWidthConverter converter = new CharWidthConverter(config); assertEquals(HALF_KATAKANA, converter.convert(FULL_KATAKANA)); }
@Test public void testConvertFullToHalfKatakanaWithSoundMark() { ConversionConfig config = new ConversionConfig.Builder() .fullToHalf() .withDigit(false) .withLetter(false) .withKatanana(true) .withOtherChars(false) .build(); CharWidthConverter converter = new CharWidthConverter(config); assertEquals(HALF_KATAKANA_WITH_SOUND_MARK, converter.convert(FULL_KATAKANA_WITH_SOUND_MARK)); }
@Test public void testConvertFullToHalfSymbol() { ConversionConfig config = new ConversionConfig.Builder() .fullToHalf() .withDigit(false) .withLetter(false) .withKatanana(false) .withOtherChars(true) .build(); CharWidthConverter converter = new CharWidthConverter(config); assertEquals(FULL_DIGIT + " " + FULL_LETTER + " " + HALF_SYMBOL, converter.convert(FULL_DIGIT + " " + FULL_LETTER + " " + FULL_SYMBOL)); }
@Test public void testConvertFullToHalfAllMixed() { ConversionConfig config = new ConversionConfig.Builder() .fullToHalf() .withDigit(true) .withLetter(true) .withKatanana(true) .withOtherChars(true) .build(); CharWidthConverter converter = new CharWidthConverter(config); assertEquals(HALF_MIXED, converter.convert(FULL_MIXED)); }