#1313 Add Separated Interface design pattern

This commit is contained in:
swarajsaaj
2020-09-10 02:57:56 +05:30
parent ef326ee77e
commit f6942cf18d
13 changed files with 527 additions and 0 deletions

View File

@ -0,0 +1,41 @@
/*
* The MIT License
* Copyright © 2014-2019 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.separatedinterface;
import org.junit.jupiter.api.Test;
import com.iluwatar.separatedinterface.App;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
/**
* Application test.
*/
class AppTest {
@Test
void shouldExecuteWithoutException() {
assertDoesNotThrow(() -> App.main(new String[]{}));
}
}

View File

@ -0,0 +1,25 @@
package com.iluwatar.separatedinterface.invoice;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.mockito.Mockito.*;
public class InvoiceGeneratorTest {
private InvoiceGenerator target;
@Test
public void testGenerateTax() {
var productCost = 50.0;
var tax = 10.0;
TaxCalculator taxCalculatorMock = mock(TaxCalculator.class);
doReturn(tax).when(taxCalculatorMock).calculate(productCost);
target = new InvoiceGenerator(productCost, taxCalculatorMock);
Assertions.assertEquals(target.getAmountWithTax(), productCost + tax);
verify(taxCalculatorMock, times(1)).calculate(productCost);
}
}

View File

@ -0,0 +1,18 @@
package com.iluwatar.separatedinterface.taxes;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class DomesticTaxTest {
private DomesticTax target;
@Test
public void testTaxCaluclation(){
target = new DomesticTax();
var tax=target.calculate(100.0);
Assertions.assertEquals(tax,20.0);
}
}

View File

@ -0,0 +1,18 @@
package com.iluwatar.separatedinterface.taxes;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class ForeignTaxTest {
private ForeignTax target;
@Test
public void testTaxCaluclation(){
target = new ForeignTax();
var tax=target.calculate(100.0);
Assertions.assertEquals(tax,60.0);
}
}