From e6465af3d149b7bb821ef659403f78c6503e6b2e Mon Sep 17 00:00:00 2001 From: Sona Markosyan Date: Sun, 30 Jan 2022 18:10:18 +0100 Subject: [PATCH] get frequent flying number of a Customer --- .../hs/fulda/de/ci/exam/project/Customer.java | 19 ++++++++++ .../de/ci/exam/project/CustomerTest.java | 38 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 src/main/java/hs/fulda/de/ci/exam/project/Customer.java create mode 100644 src/test/java/hs/fulda/de/ci/exam/project/CustomerTest.java diff --git a/src/main/java/hs/fulda/de/ci/exam/project/Customer.java b/src/main/java/hs/fulda/de/ci/exam/project/Customer.java new file mode 100644 index 0000000..a85e014 --- /dev/null +++ b/src/main/java/hs/fulda/de/ci/exam/project/Customer.java @@ -0,0 +1,19 @@ +package hs.fulda.de.ci.exam.project; + + +public class Customer extends Person{ + + private String frequentFlyerNumber; + + public Customer(String name, Address address, String email, String phone) { + super(name, address, email, phone); + } + + public void setFrequentFlyerNumber(String frequentFlyerNumber) { + this.frequentFlyerNumber = frequentFlyerNumber; + } + + public String getFrequentFlyerNumber() { + return frequentFlyerNumber; + } +} diff --git a/src/test/java/hs/fulda/de/ci/exam/project/CustomerTest.java b/src/test/java/hs/fulda/de/ci/exam/project/CustomerTest.java new file mode 100644 index 0000000..6c53905 --- /dev/null +++ b/src/test/java/hs/fulda/de/ci/exam/project/CustomerTest.java @@ -0,0 +1,38 @@ +package hs.fulda.de.ci.exam.project; + +import org.junit.jupiter.api.Test; + +import java.lang.reflect.Field; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class CustomerTest { + + final Address address1 = new Address("Fuldaer str", "Fulda", "Hessen", "36037", "Germany"); + final Customer person1 = new Customer("Max Mustermann", address1, "max.mustermann@gmail.com", "015147890206"); + + + @Test + public void test_setFlyingNumber() throws NoSuchFieldException, IllegalAccessException{ + + person1.setFrequentFlyerNumber("5"); + + final Field field = person1.getClass().getDeclaredField("frequentFlyerNumber"); + field.setAccessible(true); + assertEquals(field.get(person1), "5","set frequent flying number of the customer"); + } + + @Test + public void test_getFlyingNumber() throws NoSuchFieldException, IllegalAccessException { + + final Field field = person1.getClass().getDeclaredField("frequentFlyerNumber"); + field.setAccessible(true); + field.set(person1, "10"); + + final String result = person1.getFrequentFlyerNumber(); + + assertEquals(result, "10","get frequent flying number of the customer"); + } + +}