Fix tests in exercies 7

This commit is contained in:
Simon 2019-07-04 12:18:12 +02:00
parent fb42dba6a3
commit fe1920d94c
5 changed files with 100 additions and 76 deletions

View file

@ -2,9 +2,9 @@
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="ce5d9264-6543-4dfb-9894-4df6c2616d5e" name="Default" comment=""> <list default="true" id="ce5d9264-6543-4dfb-9894-4df6c2616d5e" name="Default" comment="">
<change afterPath="$PROJECT_DIR$/../de.hhn.ai.prog2.blatt8.internationalisierung/src/locale_de_DE.properties" afterDir="false" /> <change beforePath="$PROJECT_DIR$/tests/model/OrderTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/tests/model/OrderTest.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/../de.hhn.ai.prog2.blatt8.internationalisierung/src/locale_en.properties" afterDir="false" /> <change beforePath="$PROJECT_DIR$/tests/model/PizzaTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/tests/model/PizzaTest.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../de.hhn.ai.prog2.blatt9.properties/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../de.hhn.ai.prog2.blatt9.properties/.idea/workspace.xml" afterDir="false" />
</list> </list>
<ignored path="$PROJECT_DIR$/out/" /> <ignored path="$PROJECT_DIR$/out/" />
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
@ -23,8 +23,8 @@
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/tests/model/PizzaTest.java"> <entry file="file://$PROJECT_DIR$/tests/model/PizzaTest.java">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="705"> <state relative-caret-position="195">
<caret line="54" selection-start-line="54" selection-end-line="54" /> <caret line="13" selection-start-line="12" selection-end-line="13" />
<folding> <folding>
<element signature="imports" expanded="true" /> <element signature="imports" expanded="true" />
<element signature="e#377#378#0" expanded="true" /> <element signature="e#377#378#0" expanded="true" />
@ -51,11 +51,11 @@
</provider> </provider>
</entry> </entry>
</file> </file>
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/tests/model/OrderTest.java"> <entry file="file://$PROJECT_DIR$/tests/model/OrderTest.java">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1110"> <state relative-caret-position="1560">
<caret line="80" column="40" selection-start-line="80" selection-start-column="40" selection-end-line="80" selection-end-column="40" /> <caret line="112" column="40" selection-start-line="112" selection-start-column="40" selection-end-line="112" selection-end-column="40" />
<folding> <folding>
<element signature="imports" expanded="true" /> <element signature="imports" expanded="true" />
</folding> </folding>
@ -63,7 +63,7 @@
</provider> </provider>
</entry> </entry>
</file> </file>
<file pinned="false" current-in-tab="true"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/tests/services/OrderServiceTest.java"> <entry file="file://$PROJECT_DIR$/tests/services/OrderServiceTest.java">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="945"> <state relative-caret-position="945">
@ -163,10 +163,10 @@
<detection-done>true</detection-done> <detection-done>true</detection-done>
<sorting>DEFINITION_ORDER</sorting> <sorting>DEFINITION_ORDER</sorting>
</component> </component>
<component name="ProjectFrameBounds"> <component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="1280" /> <option name="x" value="787" />
<option name="width" value="2560" /> <option name="width" value="2560" />
<option name="height" value="1410" /> <option name="height" value="1046" />
</component> </component>
<component name="ProjectLevelVcsManager" settingsEditedManually="true" /> <component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectView"> <component name="ProjectView">
@ -175,6 +175,7 @@
</navigator> </navigator>
<panes> <panes>
<pane id="Scope" /> <pane id="Scope" />
<pane id="PackagesPane" />
<pane id="ProjectPane"> <pane id="ProjectPane">
<subPane> <subPane>
<expand> <expand>
@ -193,19 +194,6 @@
<item name="src" type="462c0819:PsiDirectoryNode" /> <item name="src" type="462c0819:PsiDirectoryNode" />
<item name="model" type="462c0819:PsiDirectoryNode" /> <item name="model" type="462c0819:PsiDirectoryNode" />
</path> </path>
<path>
<item name="de.hhn.ai.prog2.blatt7.junit" type="b2602c69:ProjectViewProjectNode" />
<item name="de.hhn.ai.prog2.blatt7.junit" type="462c0819:PsiDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
<item name="services" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="de.hhn.ai.prog2.blatt7.junit" type="b2602c69:ProjectViewProjectNode" />
<item name="de.hhn.ai.prog2.blatt7.junit" type="462c0819:PsiDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
<item name="services" type="462c0819:PsiDirectoryNode" />
<item name="impl" type="462c0819:PsiDirectoryNode" />
</path>
<path> <path>
<item name="de.hhn.ai.prog2.blatt7.junit" type="b2602c69:ProjectViewProjectNode" /> <item name="de.hhn.ai.prog2.blatt7.junit" type="b2602c69:ProjectViewProjectNode" />
<item name="de.hhn.ai.prog2.blatt7.junit" type="462c0819:PsiDirectoryNode" /> <item name="de.hhn.ai.prog2.blatt7.junit" type="462c0819:PsiDirectoryNode" />
@ -227,7 +215,6 @@
<select /> <select />
</subPane> </subPane>
</pane> </pane>
<pane id="PackagesPane" />
</panes> </panes>
</component> </component>
<component name="PropertiesComponent"> <component name="PropertiesComponent">
@ -276,7 +263,7 @@
</list> </list>
</option> </option>
</component> </component>
<component name="RunManager" selected="JUnit.OrderServiceTest"> <component name="RunManager" selected="JUnit.PizzaTest">
<configuration default="true" type="Applet"> <configuration default="true" type="Applet">
<option name="POLICY_FILE" value="$APPLICATION_HOME_DIR$/bin/appletviewer.policy" /> <option name="POLICY_FILE" value="$APPLICATION_HOME_DIR$/bin/appletviewer.policy" />
<method v="2"> <method v="2">
@ -401,9 +388,9 @@
</list> </list>
<recent_temporary> <recent_temporary>
<list> <list>
<item itemvalue="JUnit.OrderServiceTest" />
<item itemvalue="JUnit.OrderTest" />
<item itemvalue="JUnit.PizzaTest" /> <item itemvalue="JUnit.PizzaTest" />
<item itemvalue="JUnit.OrderTest" />
<item itemvalue="JUnit.OrderServiceTest" />
<item itemvalue="JUnit.PizzaTest.removeTopping" /> <item itemvalue="JUnit.PizzaTest.removeTopping" />
<item itemvalue="Application.Order" /> <item itemvalue="Application.Order" />
</list> </list>
@ -433,12 +420,6 @@
<servers /> <servers />
</component> </component>
<component name="TestHistory"> <component name="TestHistory">
<history-entry file="OrderTest - 2019.06.27 at 18h 05m 40s.xml">
<configuration name="OrderTest" configurationId="JUnit" />
</history-entry>
<history-entry file="PizzaTest - 2019.06.27 at 18h 06m 59s.xml">
<configuration name="PizzaTest" configurationId="JUnit" />
</history-entry>
<history-entry file="PizzaTest - 2019.06.27 at 18h 07m 13s.xml"> <history-entry file="PizzaTest - 2019.06.27 at 18h 07m 13s.xml">
<configuration name="PizzaTest" configurationId="JUnit" /> <configuration name="PizzaTest" configurationId="JUnit" />
</history-entry> </history-entry>
@ -463,14 +444,20 @@
<history-entry file="OrderServiceTest - 2019.06.27 at 18h 24m 57s.xml"> <history-entry file="OrderServiceTest - 2019.06.27 at 18h 24m 57s.xml">
<configuration name="OrderServiceTest" configurationId="JUnit" /> <configuration name="OrderServiceTest" configurationId="JUnit" />
</history-entry> </history-entry>
<history-entry file="OrderTest - 2019.07.04 at 12h 06m 28s.xml">
<configuration name="OrderTest" configurationId="JUnit" />
</history-entry>
<history-entry file="PizzaTest - 2019.07.04 at 12h 06m 38s.xml">
<configuration name="PizzaTest" configurationId="JUnit" />
</history-entry>
</component> </component>
<component name="TimeTrackingManager"> <component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="21861000" /> <option name="totallyTimeSpent" value="21861000" />
</component> </component>
<component name="ToolWindowManager"> <component name="ToolWindowManager">
<frame x="1280" y="0" width="2560" height="1410" extended-state="0" /> <frame x="1280" y="0" width="2560" height="1410" extended-state="6" />
<layout> <layout>
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.12708499" /> <window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.12787926" />
<window_info id="Structure" order="1" weight="0.25" /> <window_info id="Structure" order="1" weight="0.25" />
<window_info id="Image Layers" order="2" /> <window_info id="Image Layers" order="2" />
<window_info id="Designer" order="3" /> <window_info id="Designer" order="3" />
@ -479,7 +466,7 @@
<window_info id="Favorites" order="6" side_tool="true" /> <window_info id="Favorites" order="6" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" /> <window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" /> <window_info anchor="bottom" id="Find" order="1" />
<window_info anchor="bottom" id="Run" order="2" weight="0.28892332" /> <window_info anchor="bottom" id="Run" order="2" weight="0.40172786" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" /> <window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" /> <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" /> <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
@ -599,18 +586,6 @@
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/src/services/Date.java" /> <entry file="file://$PROJECT_DIR$/src/services/Date.java" />
<entry file="file://$PROJECT_DIR$/tests/model/PizzaTest.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="705">
<caret line="54" selection-start-line="54" selection-end-line="54" />
<folding>
<element signature="imports" expanded="true" />
<element signature="e#377#378#0" expanded="true" />
<element signature="e#440#441#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/services/dummy/PizzaServiceDummy.java"> <entry file="file://$PROJECT_DIR$/src/services/dummy/PizzaServiceDummy.java">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="495"> <state relative-caret-position="495">
@ -626,23 +601,6 @@
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/tests/model/OrderTest.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1110">
<caret line="80" column="40" selection-start-line="80" selection-start-column="40" selection-end-line="80" selection-end-column="40" />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/tests/services/OrderServiceTest.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="945">
<caret line="75" column="22" selection-start-line="75" selection-start-column="22" selection-end-line="75" selection-end-column="22" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/model/Pizza.java"> <entry file="file://$PROJECT_DIR$/src/model/Pizza.java">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1245"> <state relative-caret-position="1245">
@ -676,6 +634,35 @@
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/tests/services/OrderServiceTest.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="945">
<caret line="75" column="22" selection-start-line="75" selection-start-column="22" selection-end-line="75" selection-end-column="22" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/tests/model/PizzaTest.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="195">
<caret line="13" selection-start-line="12" selection-end-line="13" />
<folding>
<element signature="imports" expanded="true" />
<element signature="e#377#378#0" expanded="true" />
<element signature="e#440#441#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/tests/model/OrderTest.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1560">
<caret line="112" column="40" selection-start-line="112" selection-start-column="40" selection-end-line="112" selection-end-column="40" />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
</component> </component>
<component name="masterDetails"> <component name="masterDetails">
<states> <states>

View file

@ -22,6 +22,10 @@ class OrderTest {
@Test @Test
void getCustomer() { void getCustomer() {
assertEquals("Max Mustermann", order.getCustomer()); assertEquals("Max Mustermann", order.getCustomer());
}
@Test
void getWrongCustomber() {
assertNotEquals("Wrong", order.getCustomer()); assertNotEquals("Wrong", order.getCustomer());
} }
@ -29,12 +33,21 @@ class OrderTest {
void setCustomer() { void setCustomer() {
order.setCustomer("Max Mustermann 2"); order.setCustomer("Max Mustermann 2");
assertEquals("Max Mustermann 2", order.getCustomer()); assertEquals("Max Mustermann 2", order.getCustomer());
}
@Test
void setWrongCustomer() {
order.setCustomer("Max Mustermann 2");
assertNotEquals("Max Mustermann", order.getCustomer()); assertNotEquals("Max Mustermann", order.getCustomer());
} }
@Test @Test
void getPizzas() { void getPizzas() {
assertEquals(pizzas, order.getPizzas()); assertEquals(pizzas, order.getPizzas());
}
@Test
void getWrongPizzas() {
assertNotEquals(Arrays.asList(new Pizza(), new Pizza()), order.getPizzas()); assertNotEquals(Arrays.asList(new Pizza(), new Pizza()), order.getPizzas());
} }
@ -43,11 +56,18 @@ class OrderTest {
List<Pizza> newPizzas = new ArrayList<>(Arrays.asList(new Pizza(), new Pizza())); List<Pizza> newPizzas = new ArrayList<>(Arrays.asList(new Pizza(), new Pizza()));
order.setPizzas(newPizzas); order.setPizzas(newPizzas);
assertEquals(newPizzas, order.getPizzas()); assertEquals(newPizzas, order.getPizzas());
}
@Test
void setPizzasUpdatesCorrectly() throws OrderException {
List<Pizza> newPizzas = new ArrayList<>(Arrays.asList(new Pizza(), new Pizza()));
order.setPizzas(newPizzas);
assertNotEquals(pizzas, order.getPizzas()); assertNotEquals(pizzas, order.getPizzas());
} }
/** /**
* Tests if the exception is thrown when order is not in {@link model.Order.OrderState#IN_PROGRESS} * Tests if the exception is thrown when order is not in
* {@link model.Order.OrderState#IN_PROGRESS}
*/ */
@Test @Test
void addPizzaAfterCompletion() { void addPizzaAfterCompletion() {
@ -67,18 +87,30 @@ class OrderTest {
void setOrderState() { void setOrderState() {
order.setOrderState(Order.OrderState.DELIVERD); order.setOrderState(Order.OrderState.DELIVERD);
assertEquals(Order.OrderState.DELIVERD, order.getOrderState()); assertEquals(Order.OrderState.DELIVERD, order.getOrderState());
}
@Test
void setOrderStateUpdatesCorrectly() {
order.setOrderState(Order.OrderState.DELIVERD);
assertNotEquals(Order.OrderState.WAIT, order.getOrderState()); assertNotEquals(Order.OrderState.WAIT, order.getOrderState());
} }
@Test
void setWrongDate() {
Date today = new Date();
Calendar c = Calendar.getInstance();
c.setTime(today);
c.add(Calendar.DAY_OF_MONTH, 21);
Date currentDatePlus21d = c.getTime();
assertThrows(IllegalArgumentException.class, () -> order.setDate(currentDatePlus21d));
}
@Test @Test
void setDate() { void setDate() {
Date today = new Date(); Date today = new Date();
Calendar c = Calendar.getInstance(); Calendar c = Calendar.getInstance();
c.setTime(today); c.setTime(today);
c.add(Calendar.DAY_OF_MONTH, 21); c.add(Calendar.DAY_OF_MONTH, 19);
Date currentDatePlus21d = c.getTime();
assertThrows(IllegalArgumentException.class, () -> order.setDate(currentDatePlus21d));
c.add(Calendar.DAY_OF_MONTH, -2);
Date currentDatePlus19d = c.getTime(); Date currentDatePlus19d = c.getTime();
assertDoesNotThrow(() -> order.setDate(currentDatePlus19d)); assertDoesNotThrow(() -> order.setDate(currentDatePlus19d));
} }

View file

@ -16,10 +16,6 @@ class PizzaTest {
pizza = pizzaServiceDummy.generateRandomPizza(); pizza = pizzaServiceDummy.generateRandomPizza();
} }
@AfterEach
void tearDown() {
}
@Test @Test
void addTopping() { void addTopping() {
Pizza pizza2 = new Pizza(); Pizza pizza2 = new Pizza();
@ -34,6 +30,10 @@ class PizzaTest {
Pizza.Size size = pizzaServiceDummy.getRandomSize(); Pizza.Size size = pizzaServiceDummy.getRandomSize();
pizza.setSize(size); pizza.setSize(size);
assertEquals(size, pizza.getSize()); assertEquals(size, pizza.getSize());
}
@Test
void setSizeWorkingCorrectly() {
pizza.setSize(Pizza.Size.LARGE); pizza.setSize(Pizza.Size.LARGE);
assertNotEquals(Pizza.Size.SMALL, pizza.getSize()); assertNotEquals(Pizza.Size.SMALL, pizza.getSize());
} }
@ -42,6 +42,11 @@ class PizzaTest {
void setName() { void setName() {
pizza.setName("Test 123"); pizza.setName("Test 123");
assertEquals("Test 123", pizza.getName()); assertEquals("Test 123", pizza.getName());
}
@Test
void setNameWorkingCorreclty() {
pizza.setName("Test 123");
assertNotEquals("Wrong", pizza.getName()); assertNotEquals("Wrong", pizza.getName());
} }