01: package org.bouncycastle.asn1.test;
02:
03: import org.bouncycastle.asn1.ASN1InputStream;
04: import org.bouncycastle.asn1.ASN1Sequence;
05: import org.bouncycastle.asn1.isismtt.x509.MonetaryLimit;
06:
07: import java.io.IOException;
08:
09: public class MonetaryLimitUnitTest extends ASN1UnitTest {
10: public String getName() {
11: return "MonetaryLimit";
12: }
13:
14: public void performTest() throws Exception {
15: String currency = "AUD";
16: int amount = 1;
17: int exponent = 2;
18:
19: MonetaryLimit limit = new MonetaryLimit(currency, amount,
20: exponent);
21:
22: checkConstruction(limit, currency, amount, exponent);
23:
24: limit = MonetaryLimit.getInstance(null);
25:
26: if (limit != null) {
27: fail("null getInstance() failed.");
28: }
29:
30: try {
31: MonetaryLimit.getInstance(new Object());
32:
33: fail("getInstance() failed to detect bad object.");
34: } catch (IllegalArgumentException e) {
35: // expected
36: }
37: }
38:
39: private void checkConstruction(MonetaryLimit limit,
40: String currency, int amount, int exponent)
41: throws IOException {
42: checkValues(limit, currency, amount, exponent);
43:
44: limit = MonetaryLimit.getInstance(limit);
45:
46: checkValues(limit, currency, amount, exponent);
47:
48: ASN1InputStream aIn = new ASN1InputStream(limit.toASN1Object()
49: .getEncoded());
50:
51: ASN1Sequence seq = (ASN1Sequence) aIn.readObject();
52:
53: limit = MonetaryLimit.getInstance(seq);
54:
55: checkValues(limit, currency, amount, exponent);
56: }
57:
58: private void checkValues(MonetaryLimit limit, String currency,
59: int amount, int exponent) {
60: checkMandatoryField("currency", currency, limit.getCurrency());
61: checkMandatoryField("amount", amount, limit.getAmount()
62: .intValue());
63: checkMandatoryField("exponent", exponent, limit.getExponent()
64: .intValue());
65: }
66:
67: public static void main(String[] args) {
68: runTest(new MonetaryLimitUnitTest());
69: }
70: }
|