Skip to content

Commit 14891ab

Browse files
committed
updated tests
1 parent cd8abba commit 14891ab

File tree

2 files changed

+99
-36
lines changed

2 files changed

+99
-36
lines changed

sources/net.sf.j2s.java.core/src/test/Test_JAXB_NONE.java

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,49 +33,57 @@ public class Test_JAXB_NONE extends Test_ {
3333
}
3434

3535
public static void main(String[] args) {
36-
JAXBContext jc;
36+
JAXBContext jc;
3737
try {
3838
jc = JAXBContext.newInstance(Root_NONE.class);
39-
40-
Root_NONE root = new Root_NONE("test");
41-
root.setPropertyAng("?");
39+
40+
Root_NONE root = new Root_NONE("test");
41+
root.setPropertyAng("?");
42+
System.out.println("ang=" + root.getPropertyAng());
4243
System.out.println("getPropertyC is " + root.getproPERtyC());
43-
Marshaller marshaller = jc.createMarshaller();
44-
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
45-
ByteArrayOutputStream bos = new ByteArrayOutputStream();
46-
marshaller.marshal(root, bos);
47-
String s = null;
44+
Marshaller marshaller = jc.createMarshaller();
45+
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
46+
ByteArrayOutputStream bos = new ByteArrayOutputStream();
47+
marshaller.marshal(root, bos);
48+
String s = null;
49+
System.out.println("marshalled:");
4850
try {
4951
s = new String(bos.toByteArray(), "UTF-8");
50-
System.out.println(s);
51-
52-
Unmarshaller unmarshaller = jc.createUnmarshaller();
53-
54-
// Class<?> c = Test_JAXB_NONE.class;
52+
System.out.println(s);
53+
54+
Unmarshaller unmarshaller = jc.createUnmarshaller();
55+
56+
// Class<?> c = Test_JAXB_NONE.class;
5557
// InputStream ris = c.getResourceAsStream("jaxb/Root_NONE.xml");
56-
// s = Rdr.streamToUTF8String(new BufferedInputStream(ris));
57-
//ByteArrayInputStream ris = new ByteArrayInputStream(s.getBytes("UTF-8"));
58+
// s = Rdr.streamToUTF8String(new BufferedInputStream(ris));
59+
// ByteArrayInputStream ris = new ByteArrayInputStream(s.getBytes("UTF-8"));
5860

59-
System.out.println(s);
60-
61-
ByteArrayInputStream is = new ByteArrayInputStream(s.getBytes("UTF-8"));
62-
63-
64-
65-
61+
ByteArrayInputStream is = new ByteArrayInputStream(s.getBytes("UTF-8"));
6662
Root_NONE r = (Root_NONE) unmarshaller.unmarshal(is);
67-
assert(r.getPropertyAng().equals("?"));
63+
64+
65+
System.out.println("unmarshalled:");
66+
System.out.println("ang=" + r.getPropertyAng());
67+
bos = new ByteArrayOutputStream();
68+
marshaller.marshal(r, bos);
69+
System.out.println("remarshalled:");
70+
s = new String(bos.toByteArray(), "UTF-8");
71+
System.out.println(s);
72+
73+
System.out.println("ang=" + r.getPropertyAng());
74+
75+
assert (r.getPropertyAng().equals("?"));
6876
System.out.println("getPropertyAng[].length is " + r.getPropertyAng().getBytes("utf-8").length);
6977
} catch (UnsupportedEncodingException e) {
7078
// TODO Auto-generated catch block
7179
e.printStackTrace();
7280
}
73-
74-
System.out.println("Test_JAXB_NONE OK");
81+
82+
System.out.println("Test_JAXB_NONE OK");
7583
} catch (JAXBException e) {
7684
// TODO Auto-generated catch block
7785
e.printStackTrace();
7886
}
79-
80-
}
87+
88+
}
8189
}

sources/net.sf.j2s.java.core/src/test/Test_Map.java

Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,49 @@
5252
class Test_Map extends Test_ {
5353

5454
public static void main(String[] args) {
55-
56-
testSets();
55+
56+
System.out.println("Equivalence tests asserted");
57+
assert(new Integer(3) == 3);
58+
assert(new Integer(3) != new Integer(3));
59+
60+
String a = "x";
61+
assert("xxx" == "xx" + "x");
62+
assert("xxx" == ("xx" + a).intern());
63+
64+
try {
65+
assert("xxx" != "xx" + a);
66+
} catch (AssertionError e) {
67+
System.out.println("Known assertion error for a=\"x\";\"xxx\" != \"xx\" + a ");
68+
}
69+
try {
70+
assert(new String("xxx").toString() != ("xx" + a).intern());
71+
} catch (AssertionError e) {
72+
System.out.println("Known assertion error for a=\"x\"; new String(\"xxx\").toString() != (\"xx\" + a).intern()");
73+
}
74+
assert(new String("xxx").intern() == "xxx");
75+
assert(!(new String("xxx") == "xxx"));
76+
assert(new String("xxx") != "xxx");
77+
assert(new String("xxx") != new String("xxx"));
78+
assert(new String("xxx") != new String("xxx").intern());
79+
80+
81+
82+
System.out.println("The identityHashCode for these three are all different in Java, but not in Java:");
83+
System.out.println(System.identityHashCode("test"));
84+
String s = "";
85+
System.out.println(System.identityHashCode("test" + s));
86+
s = "st";
87+
System.out.println(System.identityHashCode("te" + s));
88+
System.out.println(System.identityHashCode("te" + s));
89+
90+
System.out.println("The identityHashCode for an interned string is the same as its literal");
91+
System.out.println(System.identityHashCode(("te" + s).intern()));
92+
93+
System.out.println("The identityHashCode for these three are all different in Java and JavaScript:");
94+
System.out.println(System.identityHashCode(new String("test")));
95+
System.out.println(System.identityHashCode(new String("test")));
96+
System.out.println(System.identityHashCode(new String("test")));
97+
testSets();
5798

5899
testIdentity();
59100

@@ -75,18 +116,25 @@ public boolean equals(Object o) {
75116

76117
private static void testSets() {
77118
Set<Object> hs = new HashSet<>();
119+
System.out.println("HashSet should have 6 members:");
78120
hs.add(null);
79121
hs.add(new int[] {1,2,3});
80122
hs.add(new int[] {1,2,3});
81123
hs.add(new int[] {1,2,3});
82124
hs.add(Integer.valueOf(3)); // identical
83125
hs.add(Integer.valueOf(3)); // identical
84126
hs.add(Integer.valueOf(3)); // identical
127+
128+
hs.add(new String("testing")); // different
129+
String ing = "ing";
130+
hs.add("test" + ing); // different from above
131+
hs.add("testing"); // different from above
132+
85133
for (Object o : hs) {
86134
System.out.println(o);
87135
}
88136
System.out.println(hs.size());
89-
assert(hs.size() == 5);
137+
assert(hs.size() == 6);
90138

91139
Iterator<Object> it;
92140
it = hs.iterator();
@@ -114,9 +162,13 @@ private static void testIdentity() {
114162
IdentityHashMap<Object, Object> hmi = new IdentityHashMap<>();
115163

116164
hmi.put(new String("testing"), "testing1"); // different
165+
117166

118-
hmi.put("testing", "testing2"); // different from above
119-
hmi.put("testing", "testing3"); // same as above
167+
// String ing = "ing";
168+
// hmi.put("test" + ing, "testing2"); // different from above
169+
170+
hmi.put("testing", "testing3"); // different from above
171+
hmi.put("testing", "testing4"); // same as above
120172

121173

122174
try {
@@ -164,9 +216,12 @@ private static void testIdentity() {
164216
System.out.println("HashMap should have 9 members:");
165217
HashMap<Object, Object> hm = new HashMap<>();
166218

167-
hm.put("testing", "testing2"); // identical
168-
hm.put("testing", "testing3"); // identical
169-
hm.put(new String("testing"), "testing1"); // identical
219+
hm.put(new String("testing"), "testing1"); // same
220+
hm.put("testing", "testing2"); // same
221+
String ing = "ing";
222+
hmi.put("test" + ing, "testing3"); // same
223+
hm.put("testing", "testing4"); // same
224+
170225

171226
try {
172227
hm.put(new Integer(null), "126new"); // unique

0 commit comments

Comments
 (0)