java/nekurak.net-lib/test/cz/frantovo/nekurak/util/HashTest.java
author František Kučera <franta-hg@frantovo.cz>
Tue, 25 May 2010 17:16:36 +0200
changeset 124 e720890878ac
parent 123 9135d52e8b0a
child 126 d47f6a75d20e
permissions -rw-r--r--
Testování NullPointerException.
franta-hg@123
     1
package cz.frantovo.nekurak.util;
franta-hg@123
     2
franta-hg@124
     3
import java.lang.NullPointerException;
franta-hg@123
     4
import org.junit.Test;
franta-hg@123
     5
import static org.junit.Assert.*;
franta-hg@123
     6
franta-hg@123
     7
/**
franta-hg@123
     8
 * Kromě Hashe otestujeme i to, zda správně fungují i názvy metod napsané česky :-)
franta-hg@123
     9
 *
franta-hg@123
    10
 * <blockquote>
franta-hg@123
    11
 * „Letters and digits may be drawn from the entire Unicode character set,
franta-hg@123
    12
 * which supports most writing scripts in use in the world today,
franta-hg@123
    13
 * including the large sets for Chinese, Japanese, and Korean.
franta-hg@123
    14
 * This allows programmers to use identifiers in their programs that are written in their native languages.“
franta-hg@123
    15
 * </blockquote>
franta-hg@123
    16
 *
franta-hg@123
    17
 * @see <a href="http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#40625">Java Language Specification – 3.8 Identifiers</a>
franta-hg@123
    18
 * @author fiki
franta-hg@123
    19
 */
franta-hg@123
    20
public class HashTest {
franta-hg@123
    21
franta-hg@123
    22
    String 外滩 = "Bund";
franta-hg@123
    23
    String 南京东路 = "Nanjing Road East";
franta-hg@123
    24
franta-hg@123
    25
    @Test
franta-hg@123
    26
    public void prázdnýŘetězec() throws Exception {
franta-hg@123
    27
	testuj("", "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e");
franta-hg@123
    28
    }
franta-hg@123
    29
franta-hg@123
    30
    @Test
franta-hg@123
    31
    public void prázdnýŘádek() throws Exception {
franta-hg@123
    32
	testuj("\n", "be688838ca8686e5c90689bf2ab585cef1137c999b48c70b92f67a5c34dc15697b5d11c982ed6d71be1e1e7f7b4e0733884aa97c3f7a339a8ed03577cf74be09");
franta-hg@123
    33
    }
franta-hg@123
    34
franta-hg@124
    35
    @Test(expected = NullPointerException.class)
franta-hg@123
    36
    public void nullHodnota() throws Exception {
franta-hg@124
    37
	testuj(null, "Při null vstupu má být vyhozena NullPointerException.");
franta-hg@123
    38
    }
franta-hg@123
    39
franta-hg@123
    40
    @Test
franta-hg@123
    41
    public void něco() throws Exception {
franta-hg@123
    42
	testuj("Ahoj, jak to jde? :-)", "87e6e3c6487dc5ffee93d05cdc71a196f21181e357e61e1820d652ed9b601e179db92c1aaafc9cf57384498c1a52b89c82714dabdfd30b9eb8c7fd8d3fe53685");
franta-hg@123
    43
    }
franta-hg@123
    44
franta-hg@123
    45
    @Test
franta-hg@123
    46
    public void čeština() throws Exception {
franta-hg@123
    47
	testuj("čeština a další unicode – → | @{#@$%${*&…˙×ׄ东方明珠塔“‚&‘‚“‚", "f9750a7f3fa04356510285af61bbdd40b108e04c2abad69130c5929561fa2765e263707147f779ac5f4be348005ce0fc810334822ba0a50f1d5c41719413277e");
franta-hg@123
    48
    }
franta-hg@123
    49
franta-hg@123
    50
    private void testuj(String vstup, String pozadovanyVystup) throws Exception {
franta-hg@123
    51
	String vystup = Hash.hashuj(vstup);
franta-hg@123
    52
	assertEquals(pozadovanyVystup, vystup);
franta-hg@123
    53
    }
franta-hg@123
    54
}