Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
at.spardat.enterprise.fmt.test.ABooleanFmtTest Maven / Gradle / Ivy
/**
* @(\#) $Id\: $
*
* Copyright 2008/2009 by sIT Solutions AT SPARDAT G.m.b.H.,
* A-1110 Wien, Geiselbergstr.21-25.
* All rights reserved.
*/
package at.spardat.enterprise.fmt.test;
import java.util.Locale;
import at.spardat.enterprise.fmt.AParseException;
import at.spardat.enterprise.fmt.ABooleanFmt;
import at.spardat.enterprise.fmt.IFmt;
import at.spardat.enterprise.util.Types;
import junit.framework.TestCase;
/**
*
*
* @author s2877
* @since version_number
*/
public class ABooleanFmtTest extends TestCase {
/**
* Test method for {@link at.spardat.enterprise.fmt.ABooleanFmt#parse(java.lang.String)}.
*/
public void testParse() {
IFmt fmt = ABooleanFmt.getInstance(ABooleanFmt.LONG, Locale.GERMAN);
assertEquals("J", fmt.parse("ja"));
assertEquals("J", fmt.parse("j"));
assertEquals("J", fmt.parse("JA"));
assertEquals("J", fmt.parse("J"));
assertEquals("N", fmt.parse("nein"));
assertEquals("N", fmt.parse("ne"));
assertEquals("N", fmt.parse("NEI"));
assertEquals("N", fmt.parse("n"));
assertEquals("N", fmt.parse("N"));
assertEquals("", fmt.parse(""));
try {
fmt.parse("yes");
assertFalse(true);
} catch(AParseException exc) {
assertEquals("Bitte geben Sie ja oder nein ein.",exc.getUIMessage(Locale.GERMAN));
}
fmt.setMandatory(true);
try {
fmt.parse("");
assertFalse(true);
} catch(AParseException exc) {
assertEquals("Eingabe erforderlich.",exc.getUIMessage(Locale.GERMAN));
}
fmt = ABooleanFmt.getInstance(ABooleanFmt.SHORT, Locale.GERMAN);
assertEquals("J", fmt.parse("ja"));
assertEquals("J", fmt.parse("j"));
assertEquals("J", fmt.parse("JA"));
assertEquals("J", fmt.parse("J"));
assertEquals("N", fmt.parse("nein"));
assertEquals("N", fmt.parse("ne"));
assertEquals("N", fmt.parse("NEI"));
assertEquals("N", fmt.parse("n"));
assertEquals("N", fmt.parse("N"));
assertEquals("", fmt.parse(""));
try {
fmt.parse("yes");
assertFalse(true);
} catch(AParseException exc) {
assertEquals("Bitte geben Sie J oder N ein.",exc.getUIMessage(Locale.GERMAN));
}
fmt = ABooleanFmt.getInstance(ABooleanFmt.LONG, new Locale("ru"));
assertEquals("J", fmt.parse("да"));
assertEquals("J", fmt.parse("д"));
assertEquals("J", fmt.parse("Д"));
assertEquals("N", fmt.parse("нет"));
assertEquals("N", fmt.parse("Нет"));
assertEquals("N", fmt.parse("н"));
assertEquals("N", fmt.parse("Н"));
assertEquals("", fmt.parse(""));
try {
fmt.parse("yes");
assertFalse(true);
} catch(AParseException exc) {
assertEquals("Пожалуйста, введите либо да или нет.",exc.getUIMessage(new Locale("ru")));
}
}
/**
* Test method for {@link at.spardat.enterprise.fmt.ABooleanFmt#format(java.lang.String)}.
*/
public void testFormat() {
IFmt fmt = ABooleanFmt.getInstance(ABooleanFmt.SHORT, Locale.GERMAN);
assertEquals("J",fmt.format("J"));
assertEquals("N",fmt.format("N"));
fmt = ABooleanFmt.getInstance(ABooleanFmt.LONG, Locale.GERMAN);
assertEquals("ja",fmt.format("J"));
assertEquals("nein",fmt.format("N"));
fmt = ABooleanFmt.getInstance(ABooleanFmt.SHORT, Locale.ENGLISH);
assertEquals("Y",fmt.format("J"));
assertEquals("N",fmt.format("N"));
fmt = ABooleanFmt.getInstance(ABooleanFmt.LONG, Locale.ENGLISH);
assertEquals("yes",fmt.format("J"));
assertEquals("no",fmt.format("N"));
fmt = ABooleanFmt.getInstance(ABooleanFmt.SHORT, new Locale("ru"));
assertEquals("Д",fmt.format("J"));
assertEquals("Н",fmt.format("N"));
fmt = ABooleanFmt.getInstance(ABooleanFmt.LONG, new Locale("ru"));
assertEquals("да",fmt.format("J"));
assertEquals("нет",fmt.format("N"));
fmt = ABooleanFmt.getInstance(ABooleanFmt.SHORT, new Locale("sk"));
assertEquals("Á",fmt.format("J"));
assertEquals("N",fmt.format("N"));
fmt = ABooleanFmt.getInstance(ABooleanFmt.LONG, new Locale("sk"));
assertEquals("áno",fmt.format("J"));
assertEquals("nie",fmt.format("N"));
}
/**
* Test method for {@link at.spardat.enterprise.fmt.ABooleanFmt#maxLenOfExternal()}.
*/
public void testMaxLenOfExternal() {
IFmt fmt = ABooleanFmt.getInstance(ABooleanFmt.SHORT, Locale.GERMAN);
assertEquals(4, fmt.maxLenOfExternal());
fmt = ABooleanFmt.getInstance(ABooleanFmt.LONG, Locale.GERMAN);
assertEquals(4, fmt.maxLenOfExternal());
}
/**
* Test method for {@link at.spardat.enterprise.fmt.ABooleanFmt#isLegalInternal(java.lang.String)}.
*/
public void testIsLegalInternal() {
IFmt fmt = ABooleanFmt.getInstance(ABooleanFmt.SHORT, Locale.GERMAN);
assertTrue(fmt.isLegalInternal(""));
assertTrue(fmt.isLegalInternal("J"));
assertTrue(fmt.isLegalInternal("N"));
assertFalse(fmt.isLegalInternal(" "));
assertFalse(fmt.isLegalInternal("0"));
assertFalse(fmt.isLegalInternal("1"));
// internal for all locals the same
fmt = ABooleanFmt.getInstance(ABooleanFmt.SHORT, new Locale("CS"));
assertTrue(fmt.isLegalInternal(""));
assertTrue(fmt.isLegalInternal("J"));
assertTrue(fmt.isLegalInternal("N"));
assertFalse(fmt.isLegalInternal(" "));
assertFalse(fmt.isLegalInternal("0"));
assertFalse(fmt.isLegalInternal("1"));
}
/**
* Test method for {@link at.spardat.enterprise.fmt.ABooleanFmt#isOneWay()}.
*/
public void testIsOneWay() {
IFmt fmt = ABooleanFmt.getInstance(ABooleanFmt.SHORT, Locale.GERMAN);
assertFalse(fmt.isOneWay());
}
/**
* Test method for {@link at.spardat.enterprise.fmt.ABooleanFmt#mayBeAppliedTo(byte)}.
*/
public void testMayBeAppliedTo() {
IFmt fmt = ABooleanFmt.getInstance(ABooleanFmt.SHORT, Locale.GERMAN);
assertTrue(fmt.mayBeAppliedTo(Types.T_BOOLEAN));
assertFalse(fmt.mayBeAppliedTo(Types.T_BCD));
assertFalse(fmt.mayBeAppliedTo(Types.T_DATE));
assertFalse(fmt.mayBeAppliedTo(Types.T_DOM));
assertFalse(fmt.mayBeAppliedTo(Types.T_STRING));
assertFalse(fmt.mayBeAppliedTo(Types.T_TIMESTAMP));
}
}