Package br.com.caelum.stella.formatter

Source Code of br.com.caelum.stella.formatter.CPFFormatterTest

package br.com.caelum.stella.formatter;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Before;
import org.junit.Test;

import br.com.caelum.stella.format.CPFFormatter;
import br.com.caelum.stella.format.Formatter;

public class CPFFormatterTest {

    private Formatter formatter;

    @Before
    public void before() {
        formatter = new CPFFormatter();
    }

    @Test
    public void testFormat() {
        String unformattedValue = "11122233344";
        String formattedValue = formatter.format(unformattedValue);
        assertEquals(formattedValue, "111.222.333-44");
    }

    @Test
    public void testUnformat() {
        String formattedValue = "111.222.333-44";
        String unformattedValue = formatter.unformat(formattedValue);
        assertEquals(unformattedValue, "11122233344");
    }

    @Test
  public void shouldDetectIfAValueIsFormattedOrNot() throws Exception {
    assertTrue(formatter.isFormatted("111.222.333-44"));
    assertFalse(formatter.isFormatted("11122233344"));
    assertFalse(formatter.isFormatted("1.1a1.1-2"));
  }

    @Test
  public void shouldDetectIfAValueCanBeFormattedOrNot() throws Exception {
      assertFalse(formatter.canBeFormatted("111.222.333-44"));
    assertTrue(formatter.canBeFormatted("11122233344"));
    assertFalse(formatter.canBeFormatted("1.1a1.1-2"));
  }

}
TOP

Related Classes of br.com.caelum.stella.formatter.CPFFormatterTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.