From ef34cb74c74cfd46c89ca4a3b2e1fe55ac212395 Mon Sep 17 00:00:00 2001 From: sampelto Date: Thu, 8 Sep 2016 16:15:20 +0300 Subject: [PATCH 1/2] Project finished --- bin/.gitignore | 1 + bin/fi/oulu/tol/sqat/GildedRose.class | Bin 2380 -> 2131 bytes bin/fi/oulu/tol/sqat/Item.class | Bin 1034 -> 1034 bytes .../oulu/tol/sqat/tests/GildedRoseTest.class | Bin 504 -> 4316 bytes .../oulu/tol/sqat/tests/GildedRoseTest.java | 148 +++++++++++++++++- 5 files changed, 146 insertions(+), 3 deletions(-) create mode 100644 bin/.gitignore diff --git a/bin/.gitignore b/bin/.gitignore new file mode 100644 index 0000000..76b3e7b --- /dev/null +++ b/bin/.gitignore @@ -0,0 +1 @@ +/fi/ diff --git a/bin/fi/oulu/tol/sqat/GildedRose.class b/bin/fi/oulu/tol/sqat/GildedRose.class index f244eba73874c91f18244a292b7f88cc3b4b5f80..b904cd2a2f60ff47b023e9e0b84ddbe56eddc526 100644 GIT binary patch literal 2131 zcmbVMOK%%h6#nkmi60qa*C}amn|9Jbu$vHv7D7{p7RPxuu0!g`sD(vu?6Es#Vkh$e zr9wgic3q&h3q*w~5fUv69~hLv6^Zw z!ISZ;q=)9k*i~4gBU|X#spp`g$N?cH>hie zpEkfj$ytV0DJO$8k8k?$M$@>}d@?45I^F7)&2`g{vou&UyzrrE@v^FHa??~z#i}Y? zSxe0?r!r?J=GM|mp;{@Z25of==VT-?%@8CCtAwFh+s=?J`9aeb&Dna%Hn=&aEb>ZG zsg{(>oJQEFnj-lf87a(Avgu0pk`j60os}^spaTS*Q+0i*BCHEC7DY~ga%xr~=0zFH zBGzkaH%SJj(X&M3owH~&m-uFVeuKHHZ4}gbO-y*GF=gYTkr<)_;i1z@gv6}1L{Kl*T({M3E))4wR2CM=2GJ(N4Tha(c+YZMPUt}t;tLkNGv~>qNor&CX7jmx~-MQ{IyVn%b@>y%=bLssBSd`HAKzG2me}62FiN`sk zH|Y?7?u#x&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a/bin/fi/oulu/tol/sqat/Item.class b/bin/fi/oulu/tol/sqat/Item.class index 478a73984862181a0a6b22a57fca5a1788d6a3f6..86c608e1a130d3506ba1bc783f500e2d34d0181d 100644 GIT binary patch delta 30 gcmeC;=;GLLiBXV&ft7)c0R-3?I6&0q$BgPs08#Y>lK=n! delta 30 jcmeC;=;GLLiBXV|ft7)cfq{XMft`T^L~nk~sLlicQXd4C diff --git a/bin/fi/oulu/tol/sqat/tests/GildedRoseTest.class b/bin/fi/oulu/tol/sqat/tests/GildedRoseTest.class index e44e81ce2b232358b6069c215dc740c0984c2b8c..f3ef10f3478f830d36401877cd7e78dc15b5f928 100644 GIT binary patch literal 4316 zcmb`I*-sl+6vof6d2pP@AI90;%S&=xm9;{AY<8Yy zErA*a6iu-P1*&anoffEWSkJLA)ly@G>Zw7XZD~bgqxQX7W=zSmDif$Ft!HI*S~e8^ z?*3S3%_*ipC)3ZBOus;_Jjt62IoV?`uWWp4qy}TIv1lrw_E>&>SG8C=QKQhuf%|jlD&_OyRP)N?@co>29 zwXClOAL(~KkRo)1SNH{cO%-^oV-aem;{u5VX7Mk;+0@eNtZiG08c!=A-9jg+HAF24 zQOwF8iBKE0Ls5JU$d(cJ%QD^jMd}o&*@u)Cor+6}mNl4cGX9_&1}st!tMR`ryb#F< zrKn4wFhaW`6`eB@rfxbNq8)3eD{n!>@Jqb zjIsjOn*iRr^(~-4tm?pk8m>w|`dFq**4J%#x6sEakkYZh97iOT7uN z_T#WM*TRcax&Gd0#w|%Vw?Rgr!`^`87RD(-jyYQpo22!5$a@nR&O2Mi>+_Vw8mth@ z^P%rlXjN3h&D8Z{rZ>|g65N&Y4C==%8B|@C?km<@Nl+(-S1L5R^Zz4*Tg=eCED{-D z&ZEP4S$dcP4O9s2pC(Qs!zxZfgS!K#iWia}Fe#DHtouAPoGo4#M0=OqF39QTnC2;^ zGSifbW=Q&GhzQiVQ5x<7LsoYpQ~Vdnz}e=l>vdk(bcq>Kw;wl!b~~xtMwVSt`1!k| z)CH$-;GN>VA14X=aIsHE@Pv~a*AU+0xC^+~x2=-+3m$4Hj4K}|+Dcn+>b+JZ9RR+OtCYAJO6V6*_voqxKIv zQA2-IY_zE(MyEPgDDmzidXX<)TU`85G2lKDX+Q0uL%1FxiH=e`9m7%4TuiFXS$Up6%ZqV5LYWgJaCmbU5ygg!a%rQNrzq_^Z{W22xozC4hTckg9>tUI69p6 zb%^^q?DlnttkZ#yIXaA2L!;LbCJ|Ci5 zGu^BPVmcHZ2sYCzF}f9GrWruo0>o`V+yR6Ph*>~ntAKbl&`h_hf)JzQ!4R)GJEEeU z<^Z7pLIs2lhy_3_0>ao7h&!7HA#b3>eL%bph&KT7CLrDd#M^*)XHy`u6(N4aue`yY zS-Y)=qfeq@uoSr%<%9h69w^>Nzx;p>(1+-;A5jN=jJ^Iz8O0fYQ>5ITeZ=pu9q6!Y zo0BuoW3qYcvf>-iy%>{Io+*@ z5Fo^^sJKygQe&hAQG5f6Z&B9oAjJ0&;sJ#C0YW@1qj;7OYmd5eAr`8oNChjg7$Y-? d;wMo242oYt@f#?92gM2~RyT#hhV^S`=|ARyjI96w delta 167 zcmcbk_=B12)W2Q(7#J9g86+oi?dIhvNi8l3$w&<;DlN&F_+H items = store.getItems(); Item itemBrie = items.get(0); - assertEquals(11, itemBrie.getQuality()); + assertEquals("Aged Brie quality increase incorrect", 11, itemBrie.getQuality()); } @Test - public void testUpdateEndOfDay() { - fail("Test not implemented"); + public void testUpdateEndOfDay_ConjuredManaCake_Quality_6_5() { + //Arrange + GildedRose store = new GildedRose(); + store.addItem(new Item("Conjured Mana Cake", 3, 6)); + + //Act + store.updateEndOfDay(); + + //Assert + List items = store.getItems(); + Item itemCake = items.get(0); + assertEquals("Quality reduction incorrect for regular item" , 5, itemCake.getQuality()); + } + + @Test + public void testUpdateEndOfDay_AgedBrie_SellIn_2_1() { + //Arrange + GildedRose store = new GildedRose(); + store.addItem(new Item("Aged Brie", 2, 10)); + + //Act + store.updateEndOfDay(); + + //Assert + List items = store.getItems(); + Item itemBrie = items.get(0); + assertEquals("SellIn reduction for Aged Brie incorrect", 1, itemBrie.getSellIn()); + } + + @Test + public void testUpdateEndOfDay_AgedBrie_SellIn_0_Neg1() { + //Arrange + GildedRose store = new GildedRose(); + store.addItem(new Item("Conjured Mana Cake", 0, 10)); + + //Act + store.updateEndOfDay(); + + //Assert + List items = store.getItems(); + Item itemBrie = items.get(0); + assertEquals("SellIn reduction to negative value incorrect", -1, itemBrie.getSellIn()); + } + + /* + * Not sure if this test is valid? + * */ + @Test + public void testUpdateEndOfDay_Sulfuras_Quality_DifferentThan80() { + //Arrange + GildedRose store = new GildedRose(); + store.addItem(new Item("Sulfuras, Hand of Ragnaros", 4, 60)); + + //Act + store.updateEndOfDay(); + + //Assert + List items = store.getItems(); + Item itemSulfuras = items.get(0); + assertEquals("Sulfuras quality can be set to a different value than 80", 80, itemSulfuras.getQuality()); + } + + @Test + public void testUpdateEndOfDay_Sulfuras_SellIn_5_5() { + //Arrange + GildedRose store = new GildedRose(); + store.addItem(new Item("Sulfuras, Hand of Ragnaros", 5, 80)); + + //Act + store.updateEndOfDay(); + + //Assert + List items = store.getItems(); + Item itemSulfuras = items.get(0); + assertEquals("Sulfuras SellIn value decreases", 5, itemSulfuras.getSellIn()); + } + + @Test + public void testUpdateEndOfDay_Sulfuras_Quality_80_80() { + //Arrange + GildedRose store = new GildedRose(); + store.addItem(new Item("Sulfuras, Hand of Ragnaros", 5, 80)); + + //Act + store.updateEndOfDay(); + + //Assert + List items = store.getItems(); + Item itemSulfuras = items.get(0); + assertEquals("Sulfuras quality decreases", 80, itemSulfuras.getQuality()); + } + + @Test + public void testUpdateEndOfDay_ConjuredManaCake_NegativeSellIn_Quality_8_6() { + //Arrange + GildedRose store = new GildedRose(); + store.addItem(new Item("Conjured Mana Cake", -2, 8)); + + //Act + store.updateEndOfDay(); + + //Assert + List items = store.getItems(); + Item itemCake = items.get(0); + assertEquals("Quality decreases incorrectly with negative SellIn", 6, itemCake.getQuality()); + } + + @Test + public void testUpdateEndOfDay_ConjuredManaCake_NegativeSellIn_ZeroQuality_0_0() { + GildedRose store = new GildedRose(); + store.addItem(new Item("Conjured Mana Cake", -2, 0)); + + //Act + store.updateEndOfDay(); + + //Assert + List items = store.getItems(); + Item itemCake = items.get(0); + assertEquals("Negative quality", 0, itemCake.getQuality()); + + } + + @Test + public void testUpdateEndOfDay_AgedBrie_SellInCloserThan10_Quality_10_12() { + GildedRose store = new GildedRose(); + store.addItem(new Item("Aged Brie", 8, 10)); + + store.updateEndOfDay(); + + List items = store.getItems(); + Item itemBrie = items.get(0); + assertEquals("Quality not increasing correctly when SellIn less than 10", 12, itemBrie.getQuality()); + } + + @Test + public void testUpdateEndOfDay_AgedBrie_QualityAt50_50_50() { + GildedRose store = new GildedRose(); + store.addItem(new Item("Aged Brie", 8, 50)); + + store.updateEndOfDay(); + + List items = store.getItems(); + Item itemBrie = items.get(0); + assertEquals("Quality increased over 50", 50, itemBrie.getQuality()); } } From 0357bcd23ae25864fea5f291152687fa0bd96d27 Mon Sep 17 00:00:00 2001 From: Sami Peltola Date: Wed, 19 Oct 2016 20:13:01 +0300 Subject: [PATCH 2/2] Some refactoring done --- bin/fi/oulu/tol/sqat/GildedRose.class | Bin 2131 -> 1938 bytes bin/fi/oulu/tol/sqat/Item.class | Bin 1034 -> 1756 bytes .../oulu/tol/sqat/tests/GildedRoseTest.class | Bin 4316 -> 6362 bytes src/fi/oulu/tol/sqat/GildedRose.java | 50 +-- src/fi/oulu/tol/sqat/Item.java | 24 ++ .../oulu/tol/sqat/tests/GildedRoseTest.java | 356 +++++++++++------- 6 files changed, 262 insertions(+), 168 deletions(-) diff --git a/bin/fi/oulu/tol/sqat/GildedRose.class b/bin/fi/oulu/tol/sqat/GildedRose.class index b904cd2a2f60ff47b023e9e0b84ddbe56eddc526..cd7bf86b7ce5fce026ff95e5c577e927bcad1d6c 100644 GIT binary patch delta 964 zcmZWoO-~b16g_WBXeke98bDN33gu)ZrqB4}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N`sk zH|Y?7?u#x&=~6sK7tC>d00p057@uMUcM-!wx|jFqrg?&K{DBD;p__9Alk6Pbj#qJk zZ6U>OW0rk~dG;8K>{nc5zazu`L{^GoRT{*aw2Zuz#T98C?@OOyK)Q`<|D7I5`Vtvj iA|6?K`VshxZju9RAK=ab7A6mHYvPPJm@DL!@b16uzSTPb diff --git a/bin/fi/oulu/tol/sqat/Item.class b/bin/fi/oulu/tol/sqat/Item.class index 86c608e1a130d3506ba1bc783f500e2d34d0181d..a83853803bc68e6ff851a17668aaccc76a4796c9 100644 GIT binary patch literal 1756 zcmai!TTc@~7>3{N(YD)`Q$Z;x6$tz_nri!4 zv(<{NH{ys$7&_EWG}Y9sef8Depq&%>kJLbz1kO+v!3j1i2I*4FJECvz?U z;>PA=jAKGVg0WT4BvK+@fNsf{6oW|)zVXen+lHm@bQ*hl>#eqDI_qlIG;>#L8KUiV zM(hKlP5te_N^#-wecx`ZR32Pog8A>th$2QghWc_`WJQe4%ZTF!-8kmCiSDwDgy_!J z^;%2U+IrVJrZt)!i@T9EtiGX)-{U9A__O_vkpr#$y4f~tildZ``x z)u?G!r9VTG^Phh{GFp0_%GGA4RnuP>qId~$a8|^@K!N^Y9y0Ocy7`1yqx0sX_|7mQ zi4>nQTP8w?@I9vdLRwk8z>qR^!PfKzZvJF{2zfro$pVWK;mic*W;k~gX-u(Kapz+i zx7i}e$tyWuB6G<361l_7c?UCIW|eOd6;;kq_`wf1Rm|xecF?jL;Guc=nbg(ZWV8Us zl*MxtE=7}Gx+roEVcd=C%Edf63A32{@jKoK7I0g?PUiv1#!OqahxMASx9 zU?EVX)Gsm}D8j21BvR@ZnW0GG3K6k2LPY7ZwzyTIx+&$|8A|#3IR=2UJPC6>z*M)y zDJ*)xrK^A+0)X=bE?fg#4h9zU1P;``OrUZNaOEl>mplMmB5?T{po&#*Kb|@@6*XiD zzabhq4T~)eJNL;wrYi5!ssnTnx?jV4PMjqEiq^WkXWS8SUDAR#wDvuaxX!z|(L+po fyW$bWrC;w7dku?U19=Z=_^5{$V7Ni25bpm6H=^Vi delta 36 scmcb^+r`0k>ff$?3=9m$3_2URmN8EDVX|Um-`vh5#l*_Mz{H>p0NOAKGynhq diff --git a/bin/fi/oulu/tol/sqat/tests/GildedRoseTest.class b/bin/fi/oulu/tol/sqat/tests/GildedRoseTest.class index f3ef10f3478f830d36401877cd7e78dc15b5f928..b4c5d52e96fd060e6839f40cd3abaac93390db06 100644 GIT binary patch literal 6362 zcmbuCS#TRw7KYFD63McNg=0cUAoKtswxdLngJOfj;siT!kjY}lkbyz8rMBFm-JPgg zNldZtgknPS05vth0~E#b07VTXOj0lm4^S{OJU~$l^S~6v@+~K#3;5~-X|wCSuZ5EPV8247Ncg)}b7%i*uh6qKewS|BXrDj^ds4b)F%H^f$38gqDPiP=$&lovb8<&eJ zKXy+xSyQUXXk|5>C`oX3^7A|Q>FO_Gq0|h0&p{Od^?Il@Lt(k03HkD*_ z+K!TLsng21YO07hpzDSuTdJWWU@T)43yIw&1;ye|AcOYKE+=-$Qnf@zMGmdBidKgxj#t=J!mwTvRT&y~{l!*H0=jF!8nBx6!4iy^6cuBgbSVm8CF{HrxW z=M&_-03ug39xzR%Xhmr~UC1aZ+ed?Yv0TVRB;uAW+=U^22NskO8)noxDXZFuVw!Tn zwo{ezjJkrjBbCgilVQ4)QG9Glk$h>%x}-u~Ni`*1*{2kxY1EEnP2qex=_S|`(1b~t zFihYcniEAJo@DJ;bBZKSS_mqQDw;N|OWfnqlx#|SxL$cLel&1=p5^6?u9`o-D9_50 z&Y}`SF#FBHF&LDwcErAdQWFv5z{up6r*+CmAEva zpzBGpq$veO&&$ObyN2R!817%oz)g~AXk`yK2MfnDMmmDk-5}?#Gc7cNvO1}>Z7&^7 zpnTD(92-EE#s-Ei8_4t}2gf!_IYZB(ABAZTqhX&~v!C=;!o-Y}lJ-w2I=X>^o*?6= z(i~Dr6zfb`%u@n0CvD~uqfG%JdgekPv{8iirfDOHTVOe@vRZuz9Q0mCSTy0G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A5jN=jJ^Iz8O0fYQ>5ITeZ=pu9q6!Y zo0BuoW3qYcvf>-iy%>{Io+*@ z5Fo^^sJKygQe&hAQG5f6Z&B9oAjJ0&;sJ#C0YW@1qj;7OYmd5eAr`8oNChjg7$Y-? d;wMo242oYt@f#?92gM2~RyT#hhV^S`=|ARyjI96w diff --git a/src/fi/oulu/tol/sqat/GildedRose.java b/src/fi/oulu/tol/sqat/GildedRose.java index 24741c6..2449b0b 100644 --- a/src/fi/oulu/tol/sqat/GildedRose.java +++ b/src/fi/oulu/tol/sqat/GildedRose.java @@ -21,74 +21,74 @@ public GildedRose() { } public static void updateEndOfDay() { - for (int i = 0; i < items.size(); i++) + for (Item item: items) { - if ((!"Aged Brie".equals(items.get(i).getName())) && !"Backstage passes to a TAFKAL80ETC concert".equals(items.get(i).getName())) + if ((!"Aged Brie".equals(item.getName())) && !"Backstage passes to a TAFKAL80ETC concert".equals(item.getName())) { - if (items.get(i).getQuality() > 0) + if (item.hasPositiveQuality()) { - if (!"Sulfuras, Hand of Ragnaros".equals(items.get(i).getName())) + if (!"Sulfuras, Hand of Ragnaros".equals(item.getName())) { - items.get(i).setQuality(items.get(i).getQuality() - 1); + item.setQuality(item.getQuality() - 1); } } } else { - if (items.get(i).getQuality() < 50) + if (item.canIncreaseQuality()) { - items.get(i).setQuality(items.get(i).getQuality() + 1); + item.setQuality(item.getQuality() + 1); - if ("Backstage passes to a TAFKAL80ETC concert".equals(items.get(i).getName())) + if ("Backstage passes to a TAFKAL80ETC concert".equals(item.getName())) { - if (items.get(i).getSellIn() < 11) + if (item.getSellIn() < 11) { - if (items.get(i).getQuality() < 50) + if (item.canIncreaseQuality()) { - items.get(i).setQuality(items.get(i).getQuality() + 1); + item.setQuality(item.getQuality() + 1); } } - if (items.get(i).getSellIn() < 6) + if (item.getSellIn() < 6) { - if (items.get(i).getQuality() < 50) + if (item.getQuality() < 50) { - items.get(i).setQuality(items.get(i).getQuality() + 1); + item.setQuality(item.getQuality() + 1); } } } } } - if (!"Sulfuras, Hand of Ragnaros".equals(items.get(i).getName())) + if (!"Sulfuras, Hand of Ragnaros".equals(item.getName())) { - items.get(i).setSellIn(items.get(i).getSellIn() - 1); + item.setSellIn(item.getSellIn() - 1); } - if (items.get(i).getSellIn() < 0) + if (item.hasExpired()) { - if (!"Aged Brie".equals(items.get(i).getName())) + if (!"Aged Brie".equals(item.getName())) { - if (!"Backstage passes to a TAFKAL80ETC concert".equals(items.get(i).getName())) + if (!"Backstage passes to a TAFKAL80ETC concert".equals(item.getName())) { - if (items.get(i).getQuality() > 0) + if (item.hasPositiveQuality()) { - if (!"Sulfuras, Hand of Ragnaros".equals(items.get(i).getName())) + if (!"Sulfuras, Hand of Ragnaros".equals(item.getName())) { - items.get(i).setQuality(items.get(i).getQuality() - 1); + item.setQuality(item.getQuality() - 1); } } } else { - items.get(i).setQuality(items.get(i).getQuality() - items.get(i).getQuality()); + item.setQuality(item.getQuality() - item.getQuality()); } } else { - if (items.get(i).getQuality() < 50) + if (item.canIncreaseQuality()) { - items.get(i).setQuality(items.get(i).getQuality() + 1); + item.setQuality(item.getQuality() + 1); } } } diff --git a/src/fi/oulu/tol/sqat/Item.java b/src/fi/oulu/tol/sqat/Item.java index 447b7fe..68b92af 100644 --- a/src/fi/oulu/tol/sqat/Item.java +++ b/src/fi/oulu/tol/sqat/Item.java @@ -31,5 +31,29 @@ public int getQuality() { public void setQuality(int quality) { this.quality = quality; } + public void decreaseQuality(int amount) { + this.quality -= amount; + } + public void increaseQuality(int amount) { + this.quality += amount; + } + public void increaseSellIn(int amount) { + this.sellIn += amount; + } + public void decreaseSellIn(int amount) { + this.sellIn -= amount; + } + public boolean hasPositiveQuality() { + if (this.quality > 0) return true; + return false; + } + public boolean canIncreaseQuality() { + if (this.quality < 50) return true; + return false; + } + public boolean hasExpired() { + if (this.sellIn < 0) return true; + return false; + } } diff --git a/src/fi/oulu/tol/sqat/tests/GildedRoseTest.java b/src/fi/oulu/tol/sqat/tests/GildedRoseTest.java index 4db6e9a..ea66643 100644 --- a/src/fi/oulu/tol/sqat/tests/GildedRoseTest.java +++ b/src/fi/oulu/tol/sqat/tests/GildedRoseTest.java @@ -1,184 +1,254 @@ package fi.oulu.tol.sqat.tests; - import static org.junit.Assert.*; - import java.util.ArrayList; import java.util.List; - import org.junit.Test; - import fi.oulu.tol.sqat.GildedRose; import fi.oulu.tol.sqat.Item; - public class GildedRoseTest { - -// Example scenarios for testing -// Item("+5 Dexterity Vest", 10, 20)); -// Item("Aged Brie", 2, 0)); -// Item("Elixir of the Mongoose", 5, 7)); -// Item("Sulfuras, Hand of Ragnaros", 0, 80)); -// Item("Backstage passes to a TAFKAL80ETC concert", 15, 20)); -// Item("Conjured Mana Cake", 3, 6)); - - @Test - public void testUpdateEndOfDay_AgedBrie_Quality_10_11() { - // Arrange - GildedRose store = new GildedRose(); + + GildedRose store = new GildedRose(); + // Test Aged Brie + @Test + public void testUpdateEndOfDay_AgedBrie_Quality_2_10() { + // Arrange store.addItem(new Item("Aged Brie", 2, 10) ); - // Act store.updateEndOfDay(); - // Assert - List items = store.getItems(); - Item itemBrie = items.get(0); - assertEquals("Aged Brie quality increase incorrect", 11, itemBrie.getQuality()); + int quality = store.getItems().get(0).getQuality(); + String failMessage = "Quality of Aged Brie increases"; + assertEquals(failMessage, 11,quality); } - @Test - public void testUpdateEndOfDay_ConjuredManaCake_Quality_6_5() { - //Arrange - GildedRose store = new GildedRose(); - store.addItem(new Item("Conjured Mana Cake", 3, 6)); - - //Act + public void testUpdateEndOfDay_AgedBrie_Quality_10_50() { + // Arrange + store.addItem(new Item("Aged Brie", 10, 50) ); + // Act store.updateEndOfDay(); - - //Assert - List items = store.getItems(); - Item itemCake = items.get(0); - assertEquals("Quality reduction incorrect for regular item" , 5, itemCake.getQuality()); + // Assert + int quality = store.getItems().get(0).getQuality(); + String failMessage = "The Quality of an item is never more than 50"; + assertEquals(failMessage, 50, quality); } - @Test - public void testUpdateEndOfDay_AgedBrie_SellIn_2_1() { - //Arrange - GildedRose store = new GildedRose(); - store.addItem(new Item("Aged Brie", 2, 10)); - - //Act + public void testUpdateEndOfDay_AgedBrie_Quality_0_10() { + // Arrange + store.addItem(new Item("Aged Brie", 0, 10) ); + // Act store.updateEndOfDay(); - - //Assert - List items = store.getItems(); - Item itemBrie = items.get(0); - assertEquals("SellIn reduction for Aged Brie incorrect", 1, itemBrie.getSellIn()); + // Assert + int quality = store.getItems().get(0).getQuality(); + String failMessage = "The Quality of Aged Brie increases twice after SellIn date has passed"; + assertEquals(failMessage, 12, quality); } - @Test - public void testUpdateEndOfDay_AgedBrie_SellIn_0_Neg1() { - //Arrange - GildedRose store = new GildedRose(); - store.addItem(new Item("Conjured Mana Cake", 0, 10)); - - //Act + public void testUpdateEndOfDay_AgedBrie_Quality_0_50() { + // Arrange + store.addItem(new Item("Aged Brie", 0, 50) ); + // Act store.updateEndOfDay(); - - //Assert - List items = store.getItems(); - Item itemBrie = items.get(0); - assertEquals("SellIn reduction to negative value incorrect", -1, itemBrie.getSellIn()); + // Assert + int quality = store.getItems().get(0).getQuality(); + String failMessage = "The Quality of Aged Brie is never more than 50 increases twice after SellIn date has passed"; + assertEquals(failMessage, 50, quality); } - - /* - * Not sure if this test is valid? - * */ - @Test - public void testUpdateEndOfDay_Sulfuras_Quality_DifferentThan80() { - //Arrange - GildedRose store = new GildedRose(); - store.addItem(new Item("Sulfuras, Hand of Ragnaros", 4, 60)); - - //Act - store.updateEndOfDay(); - - //Assert - List items = store.getItems(); - Item itemSulfuras = items.get(0); - assertEquals("Sulfuras quality can be set to a different value than 80", 80, itemSulfuras.getQuality()); + @Test + public void testUpdateEndOfDay_AgedBrie_Quality_Minus1_20() { + // Arrange + store.addItem(new Item("Aged Brie", -1, 20) ); + // Act + store.updateEndOfDay(); + // Assert + int quality = store.getItems().get(0).getQuality(); + String failMessage = "The Quality of Aged Brie increases twice after SellIn date has passed"; + assertEquals(failMessage, 22, quality); } - @Test - public void testUpdateEndOfDay_Sulfuras_SellIn_5_5() { - //Arrange - GildedRose store = new GildedRose(); - store.addItem(new Item("Sulfuras, Hand of Ragnaros", 5, 80)); - - //Act + public void testUpdateEndOfDay_AgedBrie_SellIn_2_10() { + // Arrange + store.addItem(new Item("Aged Brie", 2, 10) ); + // Act store.updateEndOfDay(); - - //Assert - List items = store.getItems(); - Item itemSulfuras = items.get(0); - assertEquals("Sulfuras SellIn value decreases", 5, itemSulfuras.getSellIn()); + // Assert + int sellIn = store.getItems().get(0).getSellIn(); + String failMessage = "SellIn date decreases"; + assertEquals(failMessage, 1, sellIn); } - @Test - public void testUpdateEndOfDay_Sulfuras_Quality_80_80() { - //Arrange - GildedRose store = new GildedRose(); - store.addItem(new Item("Sulfuras, Hand of Ragnaros", 5, 80)); - - //Act + public void testUpdateEndOfDay_AgedBrie_SellIn_1_10() { + // Arrange + store.addItem(new Item("Aged Brie", 1, 10) ); + // Act store.updateEndOfDay(); - - //Assert - List items = store.getItems(); - Item itemSulfuras = items.get(0); - assertEquals("Sulfuras quality decreases", 80, itemSulfuras.getQuality()); + // Assert + int sellIn = store.getItems().get(0).getSellIn(); + String failMessage = "SellIn date decreases"; + assertEquals(failMessage, 0, sellIn); } - @Test - public void testUpdateEndOfDay_ConjuredManaCake_NegativeSellIn_Quality_8_6() { - //Arrange - GildedRose store = new GildedRose(); - store.addItem(new Item("Conjured Mana Cake", -2, 8)); - - //Act + public void testUpdateEndOfDay_AgedBrie_SellIn_0_10() { + // Arrange + store.addItem(new Item("Aged Brie", 0, 10) ); + // Act store.updateEndOfDay(); - - //Assert - List items = store.getItems(); - Item itemCake = items.get(0); - assertEquals("Quality decreases incorrectly with negative SellIn", 6, itemCake.getQuality()); + // Assert + int sellIn = store.getItems().get(0).getSellIn(); + String failMessage = "SellIn date decreases"; + assertEquals(failMessage, -1, sellIn); } - + // Test Sulfuras @Test - public void testUpdateEndOfDay_ConjuredManaCake_NegativeSellIn_ZeroQuality_0_0() { - GildedRose store = new GildedRose(); - store.addItem(new Item("Conjured Mana Cake", -2, 0)); - - //Act + public void testUpdateEndOfDay_Sulfuras_Quality_0_80() { + // Arrange + store.addItem(new Item("Sulfuras, Hand of Ragnaros", 0, 80) ); + // Act store.updateEndOfDay(); - - //Assert - List items = store.getItems(); - Item itemCake = items.get(0); - assertEquals("Negative quality", 0, itemCake.getQuality()); - + // Assert + int quality = store.getItems().get(0).getQuality(); + String failMessage = "Quality of Sulfuras is 80 and never alters"; + assertEquals(failMessage, 80, quality); } - @Test - public void testUpdateEndOfDay_AgedBrie_SellInCloserThan10_Quality_10_12() { - GildedRose store = new GildedRose(); - store.addItem(new Item("Aged Brie", 8, 10)); - + public void testUpdateEndOfDay_Sulfuras_SellIn_5_80() { + // Arrange + store.addItem(new Item("Sulfuras, Hand of Ragnaros", 5, 80) ); + // Act store.updateEndOfDay(); - - List items = store.getItems(); - Item itemBrie = items.get(0); - assertEquals("Quality not increasing correctly when SellIn less than 10", 12, itemBrie.getQuality()); + // Assert + int sellIn = store.getItems().get(0).getSellIn(); + String failMessage = "Sulfuras, being a legendary item, never has to be sold"; + assertEquals(failMessage, 5, sellIn); } - @Test - public void testUpdateEndOfDay_AgedBrie_QualityAt50_50_50() { - GildedRose store = new GildedRose(); - store.addItem(new Item("Aged Brie", 8, 50)); - + public void testUpdateEndOfDay_Sulfuras_SellIn_0_80() { + // Arrange + store.addItem(new Item("Sulfuras, Hand of Ragnaros", 0, 80) ); + // Act + store.updateEndOfDay(); + // Assert + int sellIn = store.getItems().get(0).getSellIn(); + String failMessage = "Sulfuras, being a legendary item, never has to be sold"; + assertEquals(failMessage, 0, sellIn); + } + // Test Backstage pass + @Test + public void testUpdateEndOfDay_Backstage_Quality_15_20() { + // Arrange + store.addItem(new Item("Backstage passes to a TAFKAL80ETC concert", + 15, 20) ); + // Act + store.updateEndOfDay(); + // Assert + int quality = store.getItems().get(0).getQuality(); + String failMessage = "Quality of Backstage pass increases by 1 when there are more than 10 days"; + assertEquals(failMessage, 21, quality); + } + @Test + public void testUpdateEndOfDay_Backstage_Quality_10_20() { + // Arrange + store.addItem(new Item("Backstage passes to a TAFKAL80ETC concert", + 10, 20) ); + // Act + store.updateEndOfDay(); + // Assert + int quality = store.getItems().get(0).getQuality(); + String failMessage = "Quality of Backstage pass increases by 2 when there are 10 or less days"; + assertEquals(failMessage, 22, quality); + } + @Test + public void testUpdateEndOfDay_Backstage_Quality_8_20() { + // Arrange + store.addItem(new Item("Backstage passes to a TAFKAL80ETC concert", + 8, 20) ); + // Act + store.updateEndOfDay(); + // Assert + int quality = store.getItems().get(0).getQuality(); + String failMessage = "Quality of Backstage pass increases by 2 when there are 10 or less days"; + assertEquals(failMessage, 22, quality); + } + @Test + public void testUpdateEndOfDay_Backstage_Quality_5_20() { + // Arrange + store.addItem(new Item("Backstage passes to a TAFKAL80ETC concert", + 5, 20) ); + // Act + store.updateEndOfDay(); + // Assert + int quality = store.getItems().get(0).getQuality(); + String failMessage = "Quality of Backstage pass increases by 3 when there are 5 or less days"; + assertEquals(failMessage, 23, quality); + } + @Test + public void testUpdateEndOfDay_Backstage_Quality_3_20() { + // Arrange + store.addItem(new Item("Backstage passes to a TAFKAL80ETC concert", + 3, 20) ); + // Act + store.updateEndOfDay(); + // Assert + int quality = store.getItems().get(0).getQuality(); + String failMessage = "Quality of Backstage pass increases by 3 when there are 5 or less days"; + assertEquals(failMessage, 23, quality); + } + @Test + public void testUpdateEndOfDay_Backstage_Quality_0_20() { + // Arrange + store.addItem(new Item("Backstage passes to a TAFKAL80ETC concert", + 0, 20) ); + // Act + store.updateEndOfDay(); + // Assert + int quality = store.getItems().get(0).getQuality(); + String failMessage = "Quality of Backstage drops to 0 after the concert"; + assertEquals(failMessage, 0, quality); + } + @Test + public void testUpdateEndOfDay_Backstage_Quality_15_50() { + // Arrange + store.addItem(new Item("Backstage passes to a TAFKAL80ETC concert", + 15, 50) ); + // Act + store.updateEndOfDay(); + // Assert + int quality = store.getItems().get(0).getQuality(); + String failMessage = "The Quality of an item is never more than 50"; + assertEquals(failMessage, 50, quality); + } + @Test + public void testUpdateEndOfDay_Backstage_SellIn_5_10() { + // Arrange + store.addItem(new Item("Backstage passes to a TAFKAL80ETC concert", + 5, 10) ); + // Act + store.updateEndOfDay(); + // Assert + int sellIn = store.getItems().get(0).getSellIn(); + String failMessage = "The SellIn value should decrease by 1"; + assertEquals(failMessage, 4, sellIn); + } + // Test Elixir + @Test + public void testUpdateEndOfDay_Elixir_Quality_2_7() { + // Arrange + store.addItem(new Item("Elixir of the Mongoose", 2, 7) ); + // Act store.updateEndOfDay(); - - List items = store.getItems(); - Item itemBrie = items.get(0); - assertEquals("Quality increased over 50", 50, itemBrie.getQuality()); + // Assert + int quality = store.getItems().get(0).getQuality(); + String failMessage = "Quality decreases by 1"; + assertEquals(failMessage, 6,quality); + } + @Test + public void testUpdateEndOfDay_SellIn_Quality_2_7() { + // Arrange + store.addItem(new Item("Elixir of the Mongoose", 2, 7) ); + // Act + store.updateEndOfDay(); + // Assert + int sellIn = store.getItems().get(0).getSellIn(); + String failMessage = "SelIn decreases by 1"; + assertEquals(failMessage, 1, sellIn); } -} +} \ No newline at end of file