Permalink
Browse files

Added test classes for Person, Address and State and added a test for…

… going to java and back. Going from Java to clojure is currently broken
  • Loading branch information...
1 parent 4657c4a commit 716c07030b3dc453bfeccee245440d0bb6459551 @cosmin committed Sep 9, 2010
@@ -0,0 +1,27 @@
+(ns offbytwo.beanhelpers.beanhelperstest
+ (:use offbytwo.beanhelpers)
+ (:use clojure.test)
+ (:import (offbytwo.beanhelpers.test Person Address State)))
+
+(deftest clojure-to-java
+ (let [person (to-java Person {:name "Bob"
+ :age 30
+ :address {:line1 "123 Main St"
+ :city "Dallas"
+ :state "TX"
+ :zip "75432"}})]
+ (is (= "Bob" (.getName person)))
+ (is (= 30 (.getAge person)))
+ (is (= "123 Main St" (.. person getAddress getLine1)))
+ (is (= "Dallas" (.. person getAddress getCity)))
+ (is (= State/TX (.. person getAddress getState)))
+ (is (= "75432" (.. person getAddress getZip)))))
+
+(deftest java-to-clojure
+ (let [address (new Address "123 Main St" "Dallas" State/TX "75432")
+ person (Person. "Bob" 30 address)
+ person-info (from-java person)]
+ (is (= "Bob" (:name person)))
+ (is (= 30 (:age person)))
+ (is (= "123 Main St" (:line1 (:address person))))
+ (is (= "TX" (:state (:address person))))))
@@ -0,0 +1,50 @@
+package offbytwo.beanhelpers.test;
+
+public class Address {
+ private String line1;
+ private String city;
+ private State state;
+ private String zip;
+
+ public Address() {
+ }
+
+ public Address(String line1, String city, State state, String zip) {
+ this.line1 = line1;
+ this.city = city;
+ this.state = state;
+ this.zip = zip;
+ }
+
+ public String getLine1() {
+ return line1;
+ }
+
+ public void setLine1(String line1) {
+ this.line1 = line1;
+ }
+
+ public String getCity() {
+ return city;
+ }
+
+ public void setCity(String city) {
+ this.city = city;
+ }
+
+ public State getState() {
+ return state;
+ }
+
+ public void setState(State state) {
+ this.state = state;
+ }
+
+ public String getZip() {
+ return zip;
+ }
+
+ public void setZip(String zip) {
+ this.zip = zip;
+ }
+}
@@ -0,0 +1,40 @@
+package offbytwo.beanhelpers.test;
+
+public class Person {
+ private String name;
+ private int age;
+ private Address address;
+
+ public Person() {
+ }
+
+ public Person(String name, int age, Address address) {
+ this.name = name;
+ this.age = age;
+ this.address = address;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setAge(int age) {
+ this.age = age;
+ }
+
+ public Address getAddress() {
+ return address;
+ }
+
+ public void setAddress(Address address) {
+ this.address = address;
+ }
+}
@@ -0,0 +1,55 @@
+package offbytwo.beanhelpers.test;
+
+public enum State {
+ AL,
+ AK,
+ AZ,
+ AR,
+ CA,
+ CO,
+ CT,
+ DE,
+ DC,
+ FL,
+ GA,
+ HI,
+ ID,
+ IL,
+ IN,
+ IA,
+ KS,
+ KY,
+ LA,
+ ME,
+ MD,
+ MA,
+ MI,
+ MN,
+ MS,
+ MO,
+ MT,
+ NE,
+ NV,
+ NH,
+ NJ,
+ NM,
+ NY,
+ NC,
+ ND,
+ OH,
+ OK,
+ OR,
+ PA,
+ RI,
+ SC,
+ SD,
+ TN,
+ TX,
+ UT,
+ VT,
+ VA,
+ WA,
+ WV,
+ WI,
+ WY
+}

0 comments on commit 716c070

Please sign in to comment.