Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (C) 2009 The Guava Authors
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   * http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package com.google.common.escape.testing;
 
 import static com.google.common.escape.Escapers.computeReplacement;
 
 
 
Extra assert methods for testing Escaper implementations.

Author(s):
David Beaumont
Since:
15.0
 
 public final class EscaperAsserts {
   private EscaperAsserts() {}

  
Asserts that an escaper behaves correctly with respect to null inputs.

Parameters:
escaper the non-null escaper to test
Throws:
java.io.IOException
 
   public static void assertBasic(Escaper escaperthrows IOException {
     // Escapers operate on characters: no characters, no escaping.
     Assert.assertEquals(""escaper.escape(""));
     // Assert that escapers throw null pointer exceptions.
     try {
       escaper.escape((Stringnull);
       Assert.fail("exception not thrown when escaping a null string");
     } catch (NullPointerException e) {
       // pass
     }
   }

  
Asserts that an escaper escapes the given character into the expected string.

Parameters:
escaper the non-null escaper to test
expected the expected output string
c the character to escape
 
   public static void assertEscaping(CharEscaper escaperString expected,
       char c) {
 
     String escaped = computeReplacement(escaperc);
     Assert.assertNotNull(escaped);
     Assert.assertEquals(expectedescaped);
   }

  
Asserts that an escaper does not escape the given character.

Parameters:
escaper the non-null escaper to test
c the character to test
 
   public static void assertUnescaped(CharEscaper escaperchar c) {
     Assert.assertNull(computeReplacement(escaperc));
   }

  
Asserts that a Unicode escaper escapes the given code point into the expected string.

Parameters:
escaper the non-null escaper to test
expected the expected output string
cp the Unicode code point to escape
 
   public static void assertEscaping(UnicodeEscaper escaperString expected,
       int cp) {
 
     String escaped = computeReplacement(escapercp);
     Assert.assertNotNull(escaped);
     Assert.assertEquals(expectedescaped);
  }

  
Asserts that a Unicode escaper does not escape the given character.

Parameters:
escaper the non-null escaper to test
cp the Unicode code point to test
  public static void assertUnescaped(UnicodeEscaper escaperint cp) {
    Assert.assertNull(computeReplacement(escapercp));
  }

  
Asserts that a Unicode escaper escapes the given hi/lo surrogate pair into the expected string.

Parameters:
escaper the non-null escaper to test
expected the expected output string
hi the high surrogate pair character
lo the low surrogate pair character
  public static void assertUnicodeEscaping(UnicodeEscaper escaper,
      String expectedchar hichar lo) {
    int cp = Character.toCodePoint(hilo);
    String escaped = computeReplacement(escapercp);
    Assert.assertNotNull(escaped);
    Assert.assertEquals(expectedescaped);
  }
New to GrepCode? Check out our FAQ X