1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.fatwire.gst.foundation.facade.assetapi;
18
19 import com.fatwire.assetapi.data.AssetId;
20
21 import junit.framework.Assert;
22 import junit.framework.TestCase;
23
24
25
26
27
28
29
30 public final class AssetIdUtilsTest extends TestCase {
31 public void testFromString() {
32 AssetId id = AssetIdUtils.fromString("article:123");
33 Assert.assertEquals("123", Long.toString(id.getId()));
34 Assert.assertEquals("article", id.getType());
35
36 try {
37 AssetIdUtils.fromString(null);
38 Assert.fail("Successfully parsed garbage");
39 } catch (IllegalArgumentException e) {
40 Assert.assertTrue(true);
41 } catch (Throwable t) {
42 Assert.fail("bad data did not return the right exception for null input: " + t);
43 }
44
45 try {
46 AssetIdUtils.fromString("foo");
47 Assert.fail("Successfully parsed garbage");
48 } catch (IllegalArgumentException e) {
49 Assert.assertTrue(true);
50 } catch (Throwable t) {
51 Assert.fail("bad data did not return the right exception for foo input: " + t);
52 }
53
54 try {
55 AssetIdUtils.fromString("foo:");
56 Assert.fail("Successfully parsed garbage");
57 } catch (IllegalArgumentException e) {
58 Assert.assertTrue(true);
59 } catch (Throwable t) {
60 Assert.fail("bad data did not return the right exception for foo: input: " + t);
61 }
62
63 try {
64 AssetIdUtils.fromString("foo:bar");
65 Assert.fail("Successfully parsed garbage");
66 } catch (IllegalArgumentException e) {
67 Assert.assertTrue(true);
68 } catch (Throwable t) {
69 Assert.fail("bad data did not return the right exception for foo:bar input: " + t);
70 }
71
72 try {
73 AssetIdUtils.fromString("foo:");
74 Assert.fail("Successfully parsed garbage");
75 } catch (IllegalArgumentException e) {
76 Assert.assertTrue(true);
77 } catch (Throwable t) {
78 Assert.fail("bad data did not return the right exception for foo: input: " + t);
79 }
80
81 try {
82 AssetIdUtils.fromString(":123");
83 Assert.fail("Successfully parsed garbage");
84 } catch (IllegalArgumentException e) {
85 Assert.assertTrue(true);
86 } catch (Throwable t) {
87 Assert.fail("bad data did not return the right exception for :123 input: " + t);
88 }
89
90 try {
91 AssetIdUtils.fromString(":");
92 Assert.fail("Successfully parsed garbage");
93 } catch (IllegalArgumentException e) {
94 Assert.assertTrue(true);
95 } catch (Throwable t) {
96 Assert.fail("bad data did not return the right exception for : input: " + t);
97 }
98
99 }
100
101 }