diff --git a/.gradle/5.2.1/executionHistory/executionHistory.bin b/.gradle/5.2.1/executionHistory/executionHistory.bin index ab46769..f5303bd 100644 Binary files a/.gradle/5.2.1/executionHistory/executionHistory.bin and b/.gradle/5.2.1/executionHistory/executionHistory.bin differ diff --git a/.gradle/5.2.1/executionHistory/executionHistory.lock b/.gradle/5.2.1/executionHistory/executionHistory.lock index 1fe636b..610b8ca 100644 Binary files a/.gradle/5.2.1/executionHistory/executionHistory.lock and b/.gradle/5.2.1/executionHistory/executionHistory.lock differ diff --git a/.gradle/5.2.1/fileContent/fileContent.lock b/.gradle/5.2.1/fileContent/fileContent.lock index f7d0257..1017ee1 100644 Binary files a/.gradle/5.2.1/fileContent/fileContent.lock and b/.gradle/5.2.1/fileContent/fileContent.lock differ diff --git a/.gradle/5.2.1/fileHashes/fileHashes.bin b/.gradle/5.2.1/fileHashes/fileHashes.bin index de756de..752509c 100644 Binary files a/.gradle/5.2.1/fileHashes/fileHashes.bin and b/.gradle/5.2.1/fileHashes/fileHashes.bin differ diff --git a/.gradle/5.2.1/fileHashes/fileHashes.lock b/.gradle/5.2.1/fileHashes/fileHashes.lock index 9388d5c..076b6cf 100644 Binary files a/.gradle/5.2.1/fileHashes/fileHashes.lock and b/.gradle/5.2.1/fileHashes/fileHashes.lock differ diff --git a/.gradle/5.2.1/fileHashes/resourceHashesCache.bin b/.gradle/5.2.1/fileHashes/resourceHashesCache.bin index bce298e..69e9c46 100644 Binary files a/.gradle/5.2.1/fileHashes/resourceHashesCache.bin and b/.gradle/5.2.1/fileHashes/resourceHashesCache.bin differ diff --git a/.gradle/5.2.1/javaCompile/classAnalysis.bin b/.gradle/5.2.1/javaCompile/classAnalysis.bin index d91bf50..5527d9a 100644 Binary files a/.gradle/5.2.1/javaCompile/classAnalysis.bin and b/.gradle/5.2.1/javaCompile/classAnalysis.bin differ diff --git a/.gradle/5.2.1/javaCompile/jarAnalysis.bin b/.gradle/5.2.1/javaCompile/jarAnalysis.bin index e6cc027..a319fca 100644 Binary files a/.gradle/5.2.1/javaCompile/jarAnalysis.bin and b/.gradle/5.2.1/javaCompile/jarAnalysis.bin differ diff --git a/.gradle/5.2.1/javaCompile/javaCompile.lock b/.gradle/5.2.1/javaCompile/javaCompile.lock index 2bef620..e47d4ee 100644 Binary files a/.gradle/5.2.1/javaCompile/javaCompile.lock and b/.gradle/5.2.1/javaCompile/javaCompile.lock differ diff --git a/.gradle/5.2.1/javaCompile/taskHistory.bin b/.gradle/5.2.1/javaCompile/taskHistory.bin index 8a6f5b5..659bc2c 100644 Binary files a/.gradle/5.2.1/javaCompile/taskHistory.bin and b/.gradle/5.2.1/javaCompile/taskHistory.bin differ diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 84b08c0..33c7d15 100644 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 9646742..4eb671e 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,9 +2,26 @@ - - - + + + + + + + + + + + + + + + + + + + + - + - + @@ -124,12 +141,12 @@ false - + @@ -144,12 +161,12 @@ false - + @@ -166,11 +183,11 @@ + + + - - - @@ -210,16 +227,18 @@ file://$PROJECT_DIR$/src/test/java/com/cabinvoicegenerator/InvoiceServiceTest.java - 36 - - + + file://$PROJECT_DIR$/src/test/java/com/cabinvoicegenerator/InvoiceServiceTest.java + 39 + + file://$PROJECT_DIR$/src/test/java/com/cabinvoicegenerator/InvoiceServiceTest.java - 45 - - - diff --git a/build/classes/java/main/com/cabinvoicegenerator/CabServiceException$ExceptionType.class b/build/classes/java/main/com/cabinvoicegenerator/CabServiceException$ExceptionType.class new file mode 100644 index 0000000..8593ea3 Binary files /dev/null and b/build/classes/java/main/com/cabinvoicegenerator/CabServiceException$ExceptionType.class differ diff --git a/build/classes/java/main/com/cabinvoicegenerator/CabServiceException.class b/build/classes/java/main/com/cabinvoicegenerator/CabServiceException.class new file mode 100644 index 0000000..036d8ce Binary files /dev/null and b/build/classes/java/main/com/cabinvoicegenerator/CabServiceException.class differ diff --git a/build/classes/java/main/com/cabinvoicegenerator/InVoiceService.class b/build/classes/java/main/com/cabinvoicegenerator/InVoiceService.class index 122f62b..57e3ccd 100644 Binary files a/build/classes/java/main/com/cabinvoicegenerator/InVoiceService.class and b/build/classes/java/main/com/cabinvoicegenerator/InVoiceService.class differ diff --git a/build/classes/java/main/com/cabinvoicegenerator/RideRepository.class b/build/classes/java/main/com/cabinvoicegenerator/RideRepository.class index 2cbb86a..0a98744 100644 Binary files a/build/classes/java/main/com/cabinvoicegenerator/RideRepository.class and b/build/classes/java/main/com/cabinvoicegenerator/RideRepository.class differ diff --git a/build/classes/java/test/com/cabinvoicegenerator/InvoiceServiceTest.class b/build/classes/java/test/com/cabinvoicegenerator/InvoiceServiceTest.class index 4246bce..24c3d7b 100644 Binary files a/build/classes/java/test/com/cabinvoicegenerator/InvoiceServiceTest.class and b/build/classes/java/test/com/cabinvoicegenerator/InvoiceServiceTest.class differ diff --git a/build/classes/java/test/com/cabinvoicegenerator/RideRepositoryTest.class b/build/classes/java/test/com/cabinvoicegenerator/RideRepositoryTest.class new file mode 100644 index 0000000..3f89574 Binary files /dev/null and b/build/classes/java/test/com/cabinvoicegenerator/RideRepositoryTest.class differ diff --git a/build/reports/tests/test/classes/com.cabinvoicegenerator.InvoiceServiceTest.html b/build/reports/tests/test/classes/com.cabinvoicegenerator.InvoiceServiceTest.html deleted file mode 100644 index 345e304..0000000 --- a/build/reports/tests/test/classes/com.cabinvoicegenerator.InvoiceServiceTest.html +++ /dev/null @@ -1,142 +0,0 @@ - - - - - -Test results - Class com.cabinvoicegenerator.InvoiceServiceTest - - - - - -
-

Class com.cabinvoicegenerator.InvoiceServiceTest

- -
- - - - - -
-
- - - - - - - -
-
-
8
-

tests

-
-
-
-
0
-

failures

-
-
-
-
0
-

ignored

-
-
-
-
0.011s
-

duration

-
-
-
-
-
-
100%
-

successful

-
-
-
-
- -
-

Tests

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
TestDurationResult
givenDistanceAndTimeForNormal_ShouldReturnTotalFare0.001spassed
givenDistanceAndTimeForPremium_ShouldReturnTotalFare0spassed
givenLessDistanceAndTimeForNormal_ShouldReturnMinimumFare0spassed
givenLessDistanceAndTimeForPremium_ShouldReturnMinimumFare0spassed
givenMultipleRidesForNormal_ShouldReturnInvoiceSummary0.002spassed
givenMultipleRidesForPremium_ShouldReturnInvoiceSummary0.001spassed
givenUserIdAndRidesForNormal_ShouldReturnInvoiceSummary0.001spassed
givenUserIdAndRidesForPremium_ShouldReturnInvoiceSummary0.006spassed
-
-
-

Standard output

- -
InvoiceSummary{numOfRides=2, totalFare=60.0, averageFare=30.0}
-InvoiceSummary{numOfRides=2, totalFare=30.0, averageFare=15.0}
-
-
-
-
- -
- - diff --git a/build/reports/tests/test/css/base-style.css b/build/reports/tests/test/css/base-style.css deleted file mode 100644 index 4afa73e..0000000 --- a/build/reports/tests/test/css/base-style.css +++ /dev/null @@ -1,179 +0,0 @@ - -body { - margin: 0; - padding: 0; - font-family: sans-serif; - font-size: 12pt; -} - -body, a, a:visited { - color: #303030; -} - -#content { - padding-left: 50px; - padding-right: 50px; - padding-top: 30px; - padding-bottom: 30px; -} - -#content h1 { - font-size: 160%; - margin-bottom: 10px; -} - -#footer { - margin-top: 100px; - font-size: 80%; - white-space: nowrap; -} - -#footer, #footer a { - color: #a0a0a0; -} - -#line-wrapping-toggle { - vertical-align: middle; -} - -#label-for-line-wrapping-toggle { - vertical-align: middle; -} - -ul { - margin-left: 0; -} - -h1, h2, h3 { - white-space: nowrap; -} - -h2 { - font-size: 120%; -} - -ul.tabLinks { - padding-left: 0; - padding-top: 10px; - padding-bottom: 10px; - overflow: auto; - min-width: 800px; - width: auto !important; - width: 800px; -} - -ul.tabLinks li { - float: left; - height: 100%; - list-style: none; - padding-left: 10px; - padding-right: 10px; - padding-top: 5px; - padding-bottom: 5px; - margin-bottom: 0; - -moz-border-radius: 7px; - border-radius: 7px; - margin-right: 25px; - border: solid 1px #d4d4d4; - background-color: #f0f0f0; -} - -ul.tabLinks li:hover { - background-color: #fafafa; -} - -ul.tabLinks li.selected { - background-color: #c5f0f5; - border-color: #c5f0f5; -} - -ul.tabLinks a { - font-size: 120%; - display: block; - outline: none; - text-decoration: none; - margin: 0; - padding: 0; -} - -ul.tabLinks li h2 { - margin: 0; - padding: 0; -} - -div.tab { -} - -div.selected { - display: block; -} - -div.deselected { - display: none; -} - -div.tab table { - min-width: 350px; - width: auto !important; - width: 350px; - border-collapse: collapse; -} - -div.tab th, div.tab table { - border-bottom: solid #d0d0d0 1px; -} - -div.tab th { - text-align: left; - white-space: nowrap; - padding-left: 6em; -} - -div.tab th:first-child { - padding-left: 0; -} - -div.tab td { - white-space: nowrap; - padding-left: 6em; - padding-top: 5px; - padding-bottom: 5px; -} - -div.tab td:first-child { - padding-left: 0; -} - -div.tab td.numeric, div.tab th.numeric { - text-align: right; -} - -span.code { - display: inline-block; - margin-top: 0em; - margin-bottom: 1em; -} - -span.code pre { - font-size: 11pt; - padding-top: 10px; - padding-bottom: 10px; - padding-left: 10px; - padding-right: 10px; - margin: 0; - background-color: #f7f7f7; - border: solid 1px #d0d0d0; - min-width: 700px; - width: auto !important; - width: 700px; -} - -span.wrapped pre { - word-wrap: break-word; - white-space: pre-wrap; - word-break: break-all; -} - -label.hidden { - display: none; -} \ No newline at end of file diff --git a/build/reports/tests/test/css/style.css b/build/reports/tests/test/css/style.css deleted file mode 100644 index 3dc4913..0000000 --- a/build/reports/tests/test/css/style.css +++ /dev/null @@ -1,84 +0,0 @@ - -#summary { - margin-top: 30px; - margin-bottom: 40px; -} - -#summary table { - border-collapse: collapse; -} - -#summary td { - vertical-align: top; -} - -.breadcrumbs, .breadcrumbs a { - color: #606060; -} - -.infoBox { - width: 110px; - padding-top: 15px; - padding-bottom: 15px; - text-align: center; -} - -.infoBox p { - margin: 0; -} - -.counter, .percent { - font-size: 120%; - font-weight: bold; - margin-bottom: 8px; -} - -#duration { - width: 125px; -} - -#successRate, .summaryGroup { - border: solid 2px #d0d0d0; - -moz-border-radius: 10px; - border-radius: 10px; -} - -#successRate { - width: 140px; - margin-left: 35px; -} - -#successRate .percent { - font-size: 180%; -} - -.success, .success a { - color: #008000; -} - -div.success, #successRate.success { - background-color: #bbd9bb; - border-color: #008000; -} - -.failures, .failures a { - color: #b60808; -} - -.skipped, .skipped a { - color: #c09853; -} - -div.failures, #successRate.failures { - background-color: #ecdada; - border-color: #b60808; -} - -ul.linkList { - padding-left: 0; -} - -ul.linkList li { - list-style: none; - margin-bottom: 5px; -} diff --git a/build/reports/tests/test/index.html b/build/reports/tests/test/index.html deleted file mode 100644 index 1ff9a7b..0000000 --- a/build/reports/tests/test/index.html +++ /dev/null @@ -1,133 +0,0 @@ - - - - - -Test results - Test Summary - - - - - -
-

Test Summary

-
- - - - - -
-
- - - - - - - -
-
-
8
-

tests

-
-
-
-
0
-

failures

-
-
-
-
0
-

ignored

-
-
-
-
0.011s
-

duration

-
-
-
-
-
-
100%
-

successful

-
-
-
-
- -
-

Packages

- - - - - - - - - - - - - - - - - - - - - -
PackageTestsFailuresIgnoredDurationSuccess rate
-com.cabinvoicegenerator -8000.011s100%
-
-
-

Classes

- - - - - - - - - - - - - - - - - - - - - -
ClassTestsFailuresIgnoredDurationSuccess rate
-com.cabinvoicegenerator.InvoiceServiceTest -8000.011s100%
-
-
- -
- - diff --git a/build/reports/tests/test/js/report.js b/build/reports/tests/test/js/report.js deleted file mode 100644 index 83bab4a..0000000 --- a/build/reports/tests/test/js/report.js +++ /dev/null @@ -1,194 +0,0 @@ -(function (window, document) { - "use strict"; - - var tabs = {}; - - function changeElementClass(element, classValue) { - if (element.getAttribute("className")) { - element.setAttribute("className", classValue); - } else { - element.setAttribute("class", classValue); - } - } - - function getClassAttribute(element) { - if (element.getAttribute("className")) { - return element.getAttribute("className"); - } else { - return element.getAttribute("class"); - } - } - - function addClass(element, classValue) { - changeElementClass(element, getClassAttribute(element) + " " + classValue); - } - - function removeClass(element, classValue) { - changeElementClass(element, getClassAttribute(element).replace(classValue, "")); - } - - function initTabs() { - var container = document.getElementById("tabs"); - - tabs.tabs = findTabs(container); - tabs.titles = findTitles(tabs.tabs); - tabs.headers = findHeaders(container); - tabs.select = select; - tabs.deselectAll = deselectAll; - tabs.select(0); - - return true; - } - - function getCheckBox() { - return document.getElementById("line-wrapping-toggle"); - } - - function getLabelForCheckBox() { - return document.getElementById("label-for-line-wrapping-toggle"); - } - - function findCodeBlocks() { - var spans = document.getElementById("tabs").getElementsByTagName("span"); - var codeBlocks = []; - for (var i = 0; i < spans.length; ++i) { - if (spans[i].className.indexOf("code") >= 0) { - codeBlocks.push(spans[i]); - } - } - return codeBlocks; - } - - function forAllCodeBlocks(operation) { - var codeBlocks = findCodeBlocks(); - - for (var i = 0; i < codeBlocks.length; ++i) { - operation(codeBlocks[i], "wrapped"); - } - } - - function toggleLineWrapping() { - var checkBox = getCheckBox(); - - if (checkBox.checked) { - forAllCodeBlocks(addClass); - } else { - forAllCodeBlocks(removeClass); - } - } - - function initControls() { - if (findCodeBlocks().length > 0) { - var checkBox = getCheckBox(); - var label = getLabelForCheckBox(); - - checkBox.onclick = toggleLineWrapping; - checkBox.checked = false; - - removeClass(label, "hidden"); - } - } - - function switchTab() { - var id = this.id.substr(1); - - for (var i = 0; i < tabs.tabs.length; i++) { - if (tabs.tabs[i].id === id) { - tabs.select(i); - break; - } - } - - return false; - } - - function select(i) { - this.deselectAll(); - - changeElementClass(this.tabs[i], "tab selected"); - changeElementClass(this.headers[i], "selected"); - - while (this.headers[i].firstChild) { - this.headers[i].removeChild(this.headers[i].firstChild); - } - - var h2 = document.createElement("H2"); - - h2.appendChild(document.createTextNode(this.titles[i])); - this.headers[i].appendChild(h2); - } - - function deselectAll() { - for (var i = 0; i < this.tabs.length; i++) { - changeElementClass(this.tabs[i], "tab deselected"); - changeElementClass(this.headers[i], "deselected"); - - while (this.headers[i].firstChild) { - this.headers[i].removeChild(this.headers[i].firstChild); - } - - var a = document.createElement("A"); - - a.setAttribute("id", "ltab" + i); - a.setAttribute("href", "#tab" + i); - a.onclick = switchTab; - a.appendChild(document.createTextNode(this.titles[i])); - - this.headers[i].appendChild(a); - } - } - - function findTabs(container) { - return findChildElements(container, "DIV", "tab"); - } - - function findHeaders(container) { - var owner = findChildElements(container, "UL", "tabLinks"); - return findChildElements(owner[0], "LI", null); - } - - function findTitles(tabs) { - var titles = []; - - for (var i = 0; i < tabs.length; i++) { - var tab = tabs[i]; - var header = findChildElements(tab, "H2", null)[0]; - - header.parentNode.removeChild(header); - - if (header.innerText) { - titles.push(header.innerText); - } else { - titles.push(header.textContent); - } - } - - return titles; - } - - function findChildElements(container, name, targetClass) { - var elements = []; - var children = container.childNodes; - - for (var i = 0; i < children.length; i++) { - var child = children.item(i); - - if (child.nodeType === 1 && child.nodeName === name) { - if (targetClass && child.className.indexOf(targetClass) < 0) { - continue; - } - - elements.push(child); - } - } - - return elements; - } - - // Entry point. - - window.onload = function() { - initTabs(); - initControls(); - }; -} (window, window.document)); \ No newline at end of file diff --git a/build/reports/tests/test/packages/com.cabinvoicegenerator.html b/build/reports/tests/test/packages/com.cabinvoicegenerator.html deleted file mode 100644 index 5cab5d3..0000000 --- a/build/reports/tests/test/packages/com.cabinvoicegenerator.html +++ /dev/null @@ -1,103 +0,0 @@ - - - - - -Test results - Package com.cabinvoicegenerator - - - - - -
-

Package com.cabinvoicegenerator

- -
- - - - - -
-
- - - - - - - -
-
-
8
-

tests

-
-
-
-
0
-

failures

-
-
-
-
0
-

ignored

-
-
-
-
0.011s
-

duration

-
-
-
-
-
-
100%
-

successful

-
-
-
-
- -
-

Classes

- - - - - - - - - - - - - - - - - - - -
ClassTestsFailuresIgnoredDurationSuccess rate
-InvoiceServiceTest -8000.011s100%
-
-
- -
- - diff --git a/build/test-results/test/TEST-com.cabinvoicegenerator.InvoiceServiceTest.xml b/build/test-results/test/TEST-com.cabinvoicegenerator.InvoiceServiceTest.xml deleted file mode 100644 index 1897185..0000000 --- a/build/test-results/test/TEST-com.cabinvoicegenerator.InvoiceServiceTest.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - diff --git a/build/test-results/test/binary/output.bin b/build/test-results/test/binary/output.bin index 3a1fafe..e69de29 100644 --- a/build/test-results/test/binary/output.bin +++ b/build/test-results/test/binary/output.bin @@ -1,2 +0,0 @@ -?InvoiceSummary{numOfRides=2, totalFare=60.0, averageFare=30.0} - ?InvoiceSummary{numOfRides=2, totalFare=30.0, averageFare=15.0} diff --git a/build/test-results/test/binary/output.bin.idx b/build/test-results/test/binary/output.bin.idx deleted file mode 100644 index b8599ea..0000000 Binary files a/build/test-results/test/binary/output.bin.idx and /dev/null differ diff --git a/build/test-results/test/binary/results.bin b/build/test-results/test/binary/results.bin deleted file mode 100644 index 4315cf9..0000000 Binary files a/build/test-results/test/binary/results.bin and /dev/null differ diff --git a/src/main/java/com/cabinvoicegenerator/CabServiceException.java b/src/main/java/com/cabinvoicegenerator/CabServiceException.java new file mode 100644 index 0000000..dabe0b8 --- /dev/null +++ b/src/main/java/com/cabinvoicegenerator/CabServiceException.java @@ -0,0 +1,25 @@ +package com.cabinvoicegenerator; + +public class CabServiceException extends Exception { + + enum ExceptionType { + NULL_ID, RIDE_NOT_FOUND + } + + ExceptionType type; + + public CabServiceException(String message, String name) { + super(message); + this.type = ExceptionType.valueOf(name); + } + + public CabServiceException(String message, ExceptionType type) { + super(message); + this.type = type; + } + + public CabServiceException(String message, ExceptionType type, Throwable cause) { + super(message, cause); + this.type = type; + } +} diff --git a/src/main/java/com/cabinvoicegenerator/InVoiceService.java b/src/main/java/com/cabinvoicegenerator/InVoiceService.java index dde94c3..ffbfc0b 100644 --- a/src/main/java/com/cabinvoicegenerator/InVoiceService.java +++ b/src/main/java/com/cabinvoicegenerator/InVoiceService.java @@ -35,11 +35,11 @@ public InvoiceSummary calculateTotalFare(Ride[] rides) { return new InvoiceSummary(rides.length, totalFare); } - public void addRides(String userId, Ride[] rides) { + public void addRides(String userId, Ride[] rides) throws CabServiceException { rideRepository.addRides(userId, rides); } - public InvoiceSummary getInvoiceSummmary(String userId) { + public InvoiceSummary getInvoiceSummmary(String userId) throws CabServiceException { Ride[] rides = rideRepository.getRides(userId); return this.calculateTotalFare(rides); } diff --git a/src/main/java/com/cabinvoicegenerator/RideRepository.java b/src/main/java/com/cabinvoicegenerator/RideRepository.java index 215e712..3118bd1 100644 --- a/src/main/java/com/cabinvoicegenerator/RideRepository.java +++ b/src/main/java/com/cabinvoicegenerator/RideRepository.java @@ -11,14 +11,24 @@ public RideRepository() { this.userRides = new HashMap<>(); } - public void addRides(String userId,Ride[] rides) - { - this.userRides.put(userId,new ArrayList(Arrays.asList(rides))); - } - - public Ride[] getRides(String userId) - { - return this.userRides.get(userId).toArray(new Ride[0]); + public void addRides(String userId,Ride[] rides) throws CabServiceException{ + + if (rides != null) { + this.userRides.put(userId, new ArrayList(Arrays.asList(rides))); + } + else{ + throw new CabServiceException("You have no ride ",CabServiceException.ExceptionType.RIDE_NOT_FOUND); + } + } + + public Ride[] getRides(String userId) throws CabServiceException { + + if (userId != null) { + return this.userRides.get(userId).toArray(new Ride[0]); + } + else { + throw new CabServiceException("You have problem in ID", CabServiceException.ExceptionType.NULL_ID); + } } } diff --git a/src/test/java/com/cabinvoicegenerator/InvoiceServiceTest.java b/src/test/java/com/cabinvoicegenerator/InvoiceServiceTest.java index b2df1d2..a8e12d5 100644 --- a/src/test/java/com/cabinvoicegenerator/InvoiceServiceTest.java +++ b/src/test/java/com/cabinvoicegenerator/InvoiceServiceTest.java @@ -36,7 +36,7 @@ public void givenMultipleRidesForNormal_ShouldReturnInvoiceSummary() { } @Test - public void givenUserIdAndRidesForNormal_ShouldReturnInvoiceSummary() { + public void givenUserIdAndRidesForNormal_ShouldReturnInvoiceSummary() throws CabServiceException { InVoiceService inVoiceService = new InVoiceService(CabSubscriptionsType.NORMAL); String userId = "a@b.com"; Ride[] rides = {new Ride(2.0, 5), @@ -80,7 +80,7 @@ public void givenMultipleRidesForPremium_ShouldReturnInvoiceSummary() { } @Test - public void givenUserIdAndRidesForPremium_ShouldReturnInvoiceSummary() { + public void givenUserIdAndRidesForPremium_ShouldReturnInvoiceSummary() throws CabServiceException { InVoiceService inVoiceService = new InVoiceService(CabSubscriptionsType.PREMIUM); String userId = "a@b.com"; Ride[] rides = {new Ride(2.0, 5), @@ -89,7 +89,6 @@ public void givenUserIdAndRidesForPremium_ShouldReturnInvoiceSummary() { inVoiceService.addRides(userId, rides); InvoiceSummary summary = inVoiceService.getInvoiceSummmary(userId); InvoiceSummary expectedInvoiceSummary = new InvoiceSummary(2, 60.0); - System.out.println(expectedInvoiceSummary); Assert.assertEquals(expectedInvoiceSummary, summary); } } diff --git a/src/test/java/com/cabinvoicegenerator/RideRepositoryTest.java b/src/test/java/com/cabinvoicegenerator/RideRepositoryTest.java new file mode 100644 index 0000000..d80f144 --- /dev/null +++ b/src/test/java/com/cabinvoicegenerator/RideRepositoryTest.java @@ -0,0 +1,24 @@ +package com.cabinvoicegenerator; + +import org.junit.Assert; +import org.junit.Test; + +public class RideRepositoryTest { + + @Test + public void givenMessage_RidesAddedByParticularUserId_ShouldReturnSummaryForThatUserId() { + try { + RideRepository rideRepository = new RideRepository(); + String userId = "a@b.com"; + Ride[] rides = {new Ride(2.0, 5), + new Ride(0.1, 1) + }; + rideRepository.addRides(userId, rides); + Ride[] summary = new Ride[0]; + summary = rideRepository.getRides(userId); + Assert.assertEquals(rides[0], summary[0]); + } catch (CabServiceException e) { + Assert.assertEquals(CabServiceException.ExceptionType.NULL_ID, e.getMessage()); + } + } +}