Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testfinish exercise #82

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.redhat.shipping;

public class RegionNotFoundException extends Exception{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.redhat.shipping;

import java.util.HashMap;
import java.util.Map;
public class ShippingCalculator{

public static final Map<String,Integer> REGIONS = new HashMap<>();

public ShippingCalculator(){
ShippingCalculator.REGIONS.put("NA", 100);

ShippingCalculator.REGIONS.put("LATAM", 200);

ShippingCalculator.REGIONS.put("EMEA", 300);
ShippingCalculator.REGIONS.put("APAC", 400);

}
public int costForRegion(String name) throws RegionNotFoundException{
if(ShippingCalculator.REGIONS.containsKey(name)){
return ShippingCalculator.REGIONS.get(name);
}
throw new RegionNotFoundException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,61 @@

public class ShippingCalculatorTest {

// @todo: add tests

@Test
public void onNARegionTheCostIs() throws RegionNotFoundException {
//Given a shipping calculator
ShippingCalculator calculator = new ShippingCalculator();

//When NA is the country region
int calculatedCost = calculator.costForRegion("NA");

//Then the shipping cost is
assertEquals(100, calculatedCost);
}

@Test
public void onLATAMRegionTheCostIs200() throws RegionNotFoundException{

//Given a shipping calculator
ShippingCalculator calculator = new ShippingCalculator();

//When LATAM is the country region
int calculatedCost = calculator.costForRegion("LATAM");

//Then the shipping cost is 200
assertEquals(200, calculatedCost);
}

@Test
public void onEMEARegionTheCostIs300() throws RegionNotFoundException{
//Given a shipping calculator
ShippingCalculator calculator = new ShippingCalculator();

//When EMEA is the country region
int calculatedCost = calculator.costForRegion("EMEA");

//Then the shipping cost is 300
assertEquals(300, calculatedCost);
}

@Test
public void onAPACRegionTheCostIs400() throws RegionNotFoundException{
//Given a shipping calculator
ShippingCalculator calculator = new ShippingCalculator();

//When APAC is the countru region
int calculatedCost = calculator.costForRegion("APAC");

//Then the shipping cost is 400
assertEquals(400, calculatedCost);
}

@Test
public void onNonSupportedRegionARegionNotFoundExceptionIsRaised(){
ShippingCalculator calculator = new ShippingCalculator();
assertThrows(RegionNotFoundException.class,
() -> calculator.costForRegion("Unknown Region")
);
}
}