From c3a9cfffcac02af262a9e42a4d60168fd7504c4b Mon Sep 17 00:00:00 2001 From: "L. Dolio Durant" Date: Tue, 1 Dec 2020 18:17:36 -0500 Subject: [PATCH 1/2] Setting up GitHub Classroom Feedback From 2ffe3564b9fd58195a0325b21688319121c17d9d Mon Sep 17 00:00:00 2001 From: christine Date: Tue, 1 Dec 2020 21:10:58 -0500 Subject: [PATCH 2/2] nearly done --- .idea/.gitignore | 3 + .idea/compiler.xml | 6 + .idea/lambdas-cmmsnow.iml | 22 +++ .idea/misc.xml | 6 + .idea/modules.xml | 8 + .idea/uiDesigner.xml | 124 +++++++++++++++ .idea/vcs.xml | 6 + README.md | 28 ++-- .../lambdas-cmmsnow/CheckPerson.class | Bin 0 -> 132 bytes .../lambdas-cmmsnow/Person$Sex.class | Bin 0 -> 919 bytes out/production/lambdas-cmmsnow/Person.class | Bin 0 -> 2408 bytes out/production/lambdas-cmmsnow/Search.class | Bin 0 -> 1150 bytes .../lambdas-cmmsnow/SocialNetworks.class | Bin 0 -> 717 bytes out/test/lambdas-cmmsnow/PersonTest.class | Bin 0 -> 4366 bytes out/test/lambdas-cmmsnow/SearchTest.class | Bin 0 -> 663 bytes src/main/java/CheckPerson.java | 5 + src/main/java/Person.java | 93 +++++++++++ src/main/java/Search.java | 19 +++ src/main/java/SocialNetworks.java | 18 +++ src/test/java/PersonTest.java | 150 ++++++++++++++++++ src/test/java/SearchTest.java | 11 ++ 21 files changed, 485 insertions(+), 14 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/compiler.xml create mode 100644 .idea/lambdas-cmmsnow.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/uiDesigner.xml create mode 100644 .idea/vcs.xml create mode 100644 out/production/lambdas-cmmsnow/CheckPerson.class create mode 100644 out/production/lambdas-cmmsnow/Person$Sex.class create mode 100644 out/production/lambdas-cmmsnow/Person.class create mode 100644 out/production/lambdas-cmmsnow/Search.class create mode 100644 out/production/lambdas-cmmsnow/SocialNetworks.class create mode 100644 out/test/lambdas-cmmsnow/PersonTest.class create mode 100644 out/test/lambdas-cmmsnow/SearchTest.class create mode 100644 src/main/java/CheckPerson.java create mode 100644 src/main/java/Person.java create mode 100644 src/main/java/Search.java create mode 100644 src/main/java/SocialNetworks.java create mode 100644 src/test/java/PersonTest.java create mode 100644 src/test/java/SearchTest.java diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..38d573b --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/lambdas-cmmsnow.iml b/.idea/lambdas-cmmsnow.iml new file mode 100644 index 0000000..f84d483 --- /dev/null +++ b/.idea/lambdas-cmmsnow.iml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..a3d1909 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..18e6728 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index aed6d4d..6c97c61 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # Lambdas Exercise Suppose that you are creating a social networking application. You want to create a feature that enables an administrator to perform any kind of action, such as sending a message, on members of the social networking application that satisfy certain criteria. The following table describes this use case in detail: -Suppose that members of this social networking application are represented by the following Person class: +Suppose that members of this social networking application are represented by the following java.Person class: ``` -public class Person { +public class java.Person { public enum Sex { MALE, FEMALE @@ -25,14 +25,14 @@ public class Person { } ``` -Suppose that the members of your social networking application are stored in a `List` instance. +Suppose that the members of your social networking application are stored in a `List` instance. ### Approach 1: Create Methods That Search for Members That Match One Characteristic One simplistic approach is to create several methods; each method searches for members that match one characteristic, such as gender or age. The following method prints members that are older than a specified age: ``` -public static void printPersonsOlderThan(List roster, int age) { - for (Person p : roster) { +public static void printPersonsOlderThan(List roster, int age) { + for (java.Person p : roster) { if (p.getAge() >= age) { p.printPerson(); } @@ -44,15 +44,15 @@ The following method is more generic than printPersonsOlderThan; it prints membe ``` public static void printPersonsWithinAgeRange( - List roster, int low, int high) { - for (Person p : roster) { + List roster, int low, int high) { + for (java.Person p : roster) { if (low <= p.getAge() && p.getAge() < high) { p.printPerson(); } } } ``` -What if you want to print members of a specified sex, or a combination of a specified gender and age range? What if you decide to change the Person class and add other attributes such as relationship status or geographical location? Although this method is more generic than printPersonsOlderThan, trying to create a separate method for each possible search query can still lead to brittle code. You can instead separate the code that specifies the criteria for which you want to search in a different class. +What if you want to print members of a specified sex, or a combination of a specified gender and age range? What if you decide to change the java.Person class and add other attributes such as relationship status or geographical location? Although this method is more generic than printPersonsOlderThan, trying to create a separate method for each possible search query can still lead to brittle code. You can instead separate the code that specifies the criteria for which you want to search in a different class. ### Approach 3: Specify Search Criteria Code in a Local Class @@ -60,8 +60,8 @@ The following method prints members that match search criteria that you specify: ``` public static void printPersons( - List roster, CheckPerson tester) { - for (Person p : roster) { + List roster, java.CheckPerson tester) { + for (java.Person p : roster) { if (tester.test(p)) { p.printPerson(); } @@ -69,13 +69,13 @@ public static void printPersons( } ``` -This method checks each Person instance contained in the List parameter roster whether it satisfies the search criteria specified in the CheckPerson parameter tester by invoking the method tester.test. If the method tester.test returns a true value, then the method printPersons is invoked on the Person instance. +This method checks each java.Person instance contained in the List parameter roster whether it satisfies the search criteria specified in the java.CheckPerson parameter tester by invoking the method tester.test. If the method tester.test returns a true value, then the method printPersons is invoked on the java.Person instance. -To specify the search criteria, you implement the CheckPerson interface: +To specify the search criteria, you implement the java.CheckPerson interface: ``` -interface CheckPerson { - boolean test(Person p); +interface java.CheckPerson { + boolean test(java.Person p); } ``` diff --git a/out/production/lambdas-cmmsnow/CheckPerson.class b/out/production/lambdas-cmmsnow/CheckPerson.class new file mode 100644 index 0000000000000000000000000000000000000000..faa13df84e6e266a5a95bd1b850df64c7e64f3e8 GIT binary patch literal 132 zcmX^0Z`VEs1_l!bPId-%b_Nbc29}c4;u1y%ZVjJ+)S}}2JZsG;Mh33n{L-T2RJY8W zR7M5?=Zw_kY>2F0R$^HqP&JYePyt9#KPNFSUEe<`D>b=3}9oGN= literal 0 HcmV?d00001 diff --git a/out/production/lambdas-cmmsnow/Person$Sex.class b/out/production/lambdas-cmmsnow/Person$Sex.class new file mode 100644 index 0000000000000000000000000000000000000000..d7f44aa5e2cc051ac09f5a4066013c24bb704012 GIT binary patch literal 919 zcmZuvVQ&&a5Pi!nT{w=G(y9e(rHTr)f+&81G&BuO+ML$pl%(;~fhS&bEXe_lKTBz1 zjYiYY{wU+@LFB0JB|A6!-pst2-Cw`I{RB`$Ee?){Iv$}QuqIH_VPHpXyD=nn0(TYT zaSW@Q$hY^+H!X`H z`Su#+-1f#Qbfr+d2JwTzJBI+%mCnm?zvK9??T$w$B8WM8&yXvaXZE>W@od?vSR>z+ zy?Sx6K-wI1ZLe+nt_q%I;L`3>qV&JfB)Z{BceKZF^FPUtifx*}=z~j&FdoZJqCkbkk-s76#!Wh0;IA^JRux$tm6h~isaoRtCl_i`+~?7v`^$Q+@gIczy$F( zkeTsohyX>%Jz6ztV~Y-~lojZGY4uq?|~Ach>i;vnl$S% zY$R|G_Y-)4hth0Dv6VmqD=~a3{kAlZV%U-XaSXdLd?v#uaqQt~f*4N{_#FFDd=bT$ zQ5#Aay<<(-brs~WRSu`!vUe@q1 z)1Al{x)rW_%k(~(uUCs?-n(sDYUiXC!4mr1Q9853M6i0OJIF;OW{!xHe_u zL}@PeW?I)|YcIFnYm>g0@$ECLnY~(~P*h-(lGs(Z;ylSQD{s5$G$i(_C$&R$-xN`k z?(Ce{M8`E`b&O$L$GfG3&2k*3WWXF7>n|##m;(+r;O~ZE)`K7yd84MXbG7bz4=a zMD>J{dC!4a&F_k1=pSWNnBP^eeVQUUwklh=%4cbqFJFj%x`!>qKu%8&IX!K}{t`5r zY?AH!{Q3m}gxQZ~-$2XGoFb6Tog$c>Jw+%x5;{frcdiETfy5xfHpLv55l0$5=;N;+ zBN)IGSLR(LWH8Myi5DhxE=R&8;EaS#&>0Dzki#bHv3bTAi63{^q$5J-Euun56GAf6 zMQDg1!+f7dNNW^>c!z1n974Ja<`L2`gPfNr&t4LRv#$~OjRW_D5ohvB%jWRe=2^^n zo0l0aXNfp^o$HfuX0K6&Ne5xjjXKjK;_0CwkLw;*E0JI)kttsyAL1iFBEe1~GbEC` zfQXbs6u7~nxkhLu66z$9_a*W%KJgLhZ5MCLCbB5n{OH+@SJ?j&;4m&h&u(zH0m zEzJUnEM7oF%qT=|;|^Q78n;+J@kkFn5~K^?BGy3s*ABC+v@q&9GYelz55@LSw*Erm z;0=;#y@5;OI(Dh4271!H?nJPGRQj?z4#_y}j>FBs)X$7=ps!PtjTQ!5XABn6yi~V6 q2FX9rpKV~Efx*rSJ>vD*X@N<4Faaz%$6e;70%J5@vLTG#9r+If#J61l literal 0 HcmV?d00001 diff --git a/out/production/lambdas-cmmsnow/Search.class b/out/production/lambdas-cmmsnow/Search.class new file mode 100644 index 0000000000000000000000000000000000000000..04f10ae9b4aac26abac49156db9b64a950ba6379 GIT binary patch literal 1150 zcmZ8gO-~b16g{sqWoSFlidX~{i=y@mii)2_1S%Mkf+RI8+?b)fv;%e8Os58aiZO9x zA{#dvgTaMy?Vs>}7^9vyZKW`acfapF@4P!d{(SugU>1+VFmWw{BvKJ1kXA>=KsJH_ zOob7|bcjbTgc)2{<_!Zk4a^$2CD1o#JGM73pe0kA0(zmoEd`=Q+mY+77hBSOYHii% z87kJxR&CRAZDn_yx>vQE0{z93wA^wvFJLxY+wnG}+pIf`B$CA)>!p=zd3G&Vw3}YO zSg6YKZaX2bCW?k?&~XrtTW@;O6^NazWXzN8*ub$a0`cSEUNyP^$4)ev>kgVH)`5~| zm3P;yhJPCaw*^8ayW&`0%jJ#JC$aYwADi#h=E1~eOq!TS)Wkz987P=|ge4QpSYcAT6Djh!tyxYb z_hf5FmKA^=diiKa%&gJ=o|!sCUw}Si>Hx<6-=AuR?$3y`r4VjJ&Z==;#M56sbexQP0=)XiDj;X-K&q3~x1 Z5g1<(Ot`|70Ip(@GR)u%FS@WW`VU3f>RkW; literal 0 HcmV?d00001 diff --git a/out/production/lambdas-cmmsnow/SocialNetworks.class b/out/production/lambdas-cmmsnow/SocialNetworks.class new file mode 100644 index 0000000000000000000000000000000000000000..6b98f6cb59ad66095b3c21b28aa88888e60a382e GIT binary patch literal 717 zcmZWnU2hUW6g{&n-2z*nRj5{KrPTy5kr&?}ByEjP8#KYt)VE>T;Lz=^Sr(1|N)t_^ zCjJ0_RMRsHgpWS#?7er+IrrR|`G5Q8AAr|*k%fhdg~KciR5IAY(;SZQ%tF<|v49nL z@z*fA5-2)j`9(ITvGSXan#3)EOizsh8BZfm;9z6B?Y#G*Nf@*`1a7repyG}|s#fm{ znCIb;l!BuIuRFaSc+m$r@LAb&LRb2I87ZC5i)Q>uO?3ZW=ql-VXND$}&5pcyo|0Ru zZ&)Cra<91NDdu~k3QbsEXlxnl7R#2__M^t%J7H?4SV-x7MDvPnh2s7$kvabkSZRr|0CEtrGXk*ypN6-jHQzycT)+8)*X|9TGd4$JQ;+rGRz>_=Om5KfU literal 0 HcmV?d00001 diff --git a/out/test/lambdas-cmmsnow/PersonTest.class b/out/test/lambdas-cmmsnow/PersonTest.class new file mode 100644 index 0000000000000000000000000000000000000000..4111f2fa3ba6074ae5e24371d7b7ee93f20ea0ab GIT binary patch literal 4366 zcmcIoX?GLn6@JE>#?si5W$=ax#<*BE4kDpV+JcD}42TFrZO4?QkdZYuGP2~1MieJa zo05=Fn!Qc8v`zPY3r!4ddh)R!+H-pPi+cLpnO8HiY?^%O2fy@#ip-xE#WhVbtMrGxoy_A){jW8wXwF_rE|=*$IbkgpZHri<4h>B5+_B3GPSKXg0x@O1LxiTw z`MhbbZIC4$!kdPONF2AEX>*0Zb?f@7wcuD;aq9AvHw#P2S;x*5mV^Lv!6}=0r8Zkp zbFt9KM9y}uWX&}V+dXZGDCv@M)O38*)C(kA6oBJaA#2$oyh3(ot?MKzRVY~YWZo>5 ztSa6Hct|9!8Vz}BlvZY@R?Hmnxl10aWmuh#FEPl_qIuPFXIhHROxbhg=ZapSirg~{ z+VPT#wsGw=-&ik4(C=8m4=!y;3E zyvz%TES1;B_~#uQ#6ux`)4*H!RtVoV@Ev^D!1wUBf$!r7Oys#@Hf!LAc*nqx@M8l% z!A}kR3_myU3;fc+ukf~p*5%@rLSZd{^=lFT4Ss9jclf=A&f0vLDChFLQl^re?DxWb zrocoS9W?L<{85HK5$Z@^MkUUuY`x2h9O+wf^I??CkMvn`spHwKZIw!*dq?nu1I8&7 zI6s|PW(xb~k}s8e*qDwQ>WYi3_(Up|8oE!uHk=wyPiZ)j*jx=;YN+CNlXSC+G>xWX zQ=ZM%AT=Z_Boni&yY1DkyjTtmoo9qWagVbiY$~)!Y1qzm(Jk@&sM2Lwdrk-MLGqDG^fKU}o1(aAWRV;6St@?$88=>!@*gGr!H{Jy6IYLW;T$e&nBPIr$ zX|PiCtu*Ilf$9p)v{E^YCaTXwHA+>tA*fW65~|&4qKw-c*y7n8qCUkHavBpSPrCPL zuC6jgH9T0&RweQ(y1Xq_42-llF}e8?g5wS5DpdaubGoCt7IyPRPV$9s;2*mMM}Qr{ z{jveLUv?g7c!cvhJc=0SY*QRR%bg^@8o!OhccH!OiX7tD{a-GLr&zKihth&(gnsnYzzFzuPLCHJnXEpr`On< zbnPAW?WL$CdM(1$UA~+9HW+P1Jr8#?gnp90$2HvHDJa7_e-2IYb~TJqQXqRSj`=Pw zP+qLG#hcQCdL137_Kn;_XMjEKCe0wl669%!i81WD>hlzpt9rEJI8M+-gpN|2)zvsX z={t3l)Bbpu>vZ2bx;HqNMZAf-0g4`41(Ud*sTg4jw==9RrtoeYtU}Z8quHgtTkc zIIF#-X&>7~bxU!UredUbYer5miWF1uBrEChDz9rsf5jyjbP5O*#GO0(ruB8WhN`3I}~22geJ6&W=-X)E4EjWwM^Gf>I+0JoRU(-m=`^Y|2$&&p5d)Occ;-6T@ zUXQ2_&SHb>7>pj?A6?|HKtskk?gjFqG#R$_otT zCPR6Vq1<*u@Sc;ieh8ZCs$&EfJSP`F5_pvFN`>Cag>bL>Lb$BH5H2@gNG1-ypB)3{MNa|h5KZlv;_)D9`Flq1te67CsPoqBJt>$RkEqOuIzRBE~J(s zkoW*T3USsBDj;jeb7p7GobmYQuWvs9Jj1}p3bsAm^Wk8-10VN2?D$w}z^)DNS@^)i zLl2JxJT1+qyf_i)#iKk`Np{o($^(IRDU%|d2`tB>+Ox6eN-OhHpw%CY1>D2@qZ9~Z zrR7m|I+4Y3GRYWOi}N(e#z~8$#pgWeOA*J86u}EO^eWi^$m19*Z7QWIt zH;GZXW?e7Ni)l2kC?NV%JIbpfm9LfU88#~I)zf)$o&@M&RiOLtU;zT$;2=$MfG)xS z`*amxN6u2U+bvM5&dJi%F^w0S3svR1v@ z|34)@oXPa0NjMmcvByQNaDfgFwb8<=qIEzGSfyPfdV>}{U~6~k-%+IJ2mx-x)l%(FW`Q`GGE?Tbgt>_uLE>Q W>;FX+E~xJCu1&(tn)WWOgRS4y-iHSO literal 0 HcmV?d00001 diff --git a/src/main/java/CheckPerson.java b/src/main/java/CheckPerson.java new file mode 100644 index 0000000..492d16f --- /dev/null +++ b/src/main/java/CheckPerson.java @@ -0,0 +1,5 @@ +public interface CheckPerson { + + boolean test(Person p); + +} diff --git a/src/main/java/Person.java b/src/main/java/Person.java new file mode 100644 index 0000000..a46f0fa --- /dev/null +++ b/src/main/java/Person.java @@ -0,0 +1,93 @@ +import java.time.LocalDate; +import java.time.Period; +import java.util.List; + +public class Person /*implements CheckPerson*/ { + + public enum Sex { + MALE, FEMALE + } + + String name; + LocalDate birthday; + Sex gender; + String emailAddress; + + public Person(String name, LocalDate birthday, Sex gender, String emailAddress) { + this.name = name; + this.birthday = birthday; + this.gender = gender; + this.emailAddress = emailAddress; + } + + public Person() { + this.name = ""; + this.birthday = LocalDate.now(); + this.gender = null; + this.emailAddress = ""; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public LocalDate getBirthday() { + return birthday; + } + + public void setBirthday(LocalDate birthday) { + this.birthday = birthday; + } + + public Sex getGender() { + return gender; + } + + public void setGender(Sex gender) { + this.gender = gender; + } + + public String getEmailAddress() { + return emailAddress; + } + + public void setEmailAddress(String emailAddress) { + this.emailAddress = emailAddress; + } + + public int getAge() { + return Period.between(birthday, LocalDate.now()).getYears(); + } + + @Override + public String toString() { + return "java.Person{" + + "name='" + name + '\'' + + ", birthday=" + birthday + + ", gender=" + gender + + ", emailAddress='" + emailAddress + '\'' + + '}'; + } + + public void printPerson() { + System.out.println(toString()); + } + +// @Override +// public boolean test(Person p) { +// return p.gender == Person.Sex.FEMALE && p.getAge() >= 0 && p.getAge() <= 80; +// } +// +// public static String printPersons(List roster, CheckPerson tester) { +// for (Person p : roster) { +// if (tester.test(p)) { +// p.printPerson(); +// } +// } +// } + +} diff --git a/src/main/java/Search.java b/src/main/java/Search.java new file mode 100644 index 0000000..220e6e1 --- /dev/null +++ b/src/main/java/Search.java @@ -0,0 +1,19 @@ +import java.util.List; + +public class Search implements CheckPerson{ + + public static void printPersons(List roster, CheckPerson tester) { + for (Person p : roster) { + if (tester.test(p)) { + p.printPerson(); + } + } + } + + @Override + public boolean test(Person p) { + return p.gender == Person.Sex.FEMALE && p.getAge() >= 0 && p.getAge() <= 80; + } + + +} diff --git a/src/main/java/SocialNetworks.java b/src/main/java/SocialNetworks.java new file mode 100644 index 0000000..8a299b0 --- /dev/null +++ b/src/main/java/SocialNetworks.java @@ -0,0 +1,18 @@ +import java.util.ArrayList; +import java.util.List; + +public class SocialNetworks { + List network; + + public SocialNetworks(){ + this.network = new ArrayList<>(); + } + + public List getNetwork(){ + return network; + } + + public void add(Person p){ + network.add(p); + } +} diff --git a/src/test/java/PersonTest.java b/src/test/java/PersonTest.java new file mode 100644 index 0000000..485a4bb --- /dev/null +++ b/src/test/java/PersonTest.java @@ -0,0 +1,150 @@ +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.List; + +public class PersonTest { + Person person1; + Person person2; + Person person3; + List people; + + @Before + public void setup(){ + people = new ArrayList<>(); + person1 = new Person("Bob", LocalDate.of(1980, 1, 25), Person.Sex.MALE, "bob@bob.com"); + person2 = new Person("Sally", LocalDate.of(2000, 10, 5), Person.Sex.FEMALE, "sally@sally.com"); + person3 = new Person("Guy", LocalDate.of(1995, 6, 13), Person.Sex.MALE, "guy@guy.com"); + people.add(person1); + people.add(person2); + people.add(person3); + } + + @Test + public void testConstructor(){ + Assert.assertNotNull(person1); + } + + @Test + public void testNullaryConstructor(){ + Person person = new Person(); + Assert.assertNotNull(person); + } + + @Test + public void testGetName(){ + String expected = "Bob"; + String actual = person1.getName(); + Assert.assertEquals(expected, actual); + } + + @Test + public void testSetName(){ + String expected = "Todd"; + person1.setName(expected); + String actual = person1.getName(); + Assert.assertEquals(expected, actual); + person1.setName("Bob"); + } + + @Test + public void testGetBirthday(){ + LocalDate expected = LocalDate.of(1980, 1, 25); + LocalDate actual = person1.getBirthday(); + Assert.assertEquals(expected, actual); + } + + @Test + public void testSetBirthday(){ + LocalDate expected = LocalDate.of(1990, 2, 15); + person1.setBirthday(expected); + LocalDate actual = person1.getBirthday(); + Assert.assertEquals(expected, actual); + + person1.setBirthday(LocalDate.of(1980, 1, 25)); + } + + @Test + public void testGetGender(){ + Person.Sex expected = Person.Sex.MALE; + Person.Sex actual = person1.getGender(); + Assert.assertEquals(expected, actual); + } + + @Test + public void testSetGender(){ + Person.Sex expected = Person.Sex.FEMALE; + person1.setGender(expected); + Person.Sex actual = person1.getGender(); + Assert.assertEquals(expected, actual); + + person1.setGender(Person.Sex.MALE); + } + + @Test + public void testGetEmail(){ + String expected = "bob@bob.com"; + String actual = person1.getEmailAddress(); + Assert.assertEquals(expected, actual); + } + + @Test + public void testSetEmail(){ + String expected = "johnny@bob.com"; + person1.setEmailAddress(expected); + String actual = person1.getEmailAddress(); + Assert.assertEquals(expected, actual); + + person1.setEmailAddress("bob@bob.com"); + } + + @Test + public void testGetAge(){ + Person person1 = new Person("Bob", LocalDate.of(1980, 1, 25), Person.Sex.MALE, "bob@bob.com"); + int fakeAge = 10; + int age = person1.getAge(); + Assert.assertNotEquals(fakeAge, age); + } + + @Test + public void testToString(){ + String expected = "java.Person{" + + "name='" + person1.getName() + '\'' + + ", birthday=" + person1.getBirthday() + + ", gender=" + person1.getGender() + + ", emailAddress='" + person1.getEmailAddress() + '\'' + + '}'; + String actual = person1.toString(); + Assert.assertEquals(expected, actual); + } + + @Test + public void testPrintPerson(){ +// Person kyle = new Person(); +// kyle.printPerson(); +// Assert.assertNotNull(kyle); + + String expected = "java.Person{" + + "name='" + person1.getName() + '\'' + + ", birthday=" + person1.getBirthday() + + ", gender=" + person1.getGender() + + ", emailAddress='" + person1.getEmailAddress() + '\'' + + '}'; +// String actual = person1.printPerson(); +// Assert.assertEquals(expected, actual); + } + + @Test + public void testPrintPersons(){ + String expected = "java.Person{" + + "name='" + person2.getName() + '\'' + + ", birthday=" + person2.getBirthday() + + ", gender=" + person2.getGender() + + ", emailAddress='" + person2.getEmailAddress() + '\'' + + '}'; + //String actual = person1.printPersons(people, person1.test()); + } +} diff --git a/src/test/java/SearchTest.java b/src/test/java/SearchTest.java new file mode 100644 index 0000000..af77319 --- /dev/null +++ b/src/test/java/SearchTest.java @@ -0,0 +1,11 @@ +import org.junit.Test; + +public class SearchTest { + SocialNetworks network = new SocialNetworks(); + Search search = new Search(); + + @Test + public void searchTest(){ + Search.printPersons(network.getNetwork(), search); + } +}