Last active
March 31, 2016 11:22
-
-
Save karlkilden/01e89291f9d3917d07968d51a5d0cfb2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package se.raindance.mp.export.job; | |
import java.util.Locale; | |
public class Atm { | |
public static final String INSERT_PIN_RESPONSE = "Enter pincode"; | |
public static final String CHANGE_LANGUAGE = "Change Language"; | |
public static final String ENGLISH_GREETING = "Hello!"; | |
public static final String FRENCH_GREETING = "Bonjour!"; | |
public static final String INSERT_CARD = "Please insert card"; | |
private OperationalState cardState = OperationalState.NO_CARD; | |
public String insertCard(String string) { | |
cardState = OperationalState.HAS_CARD; | |
return INSERT_PIN_RESPONSE; | |
} | |
public String insertPincode(int pincode) { | |
if (cardState == OperationalState.HAS_CARD) { | |
return CHANGE_LANGUAGE; | |
} | |
return INSERT_CARD; | |
} | |
public String changeLanguage(Locale chosenLanguage) { | |
if (Locale.ENGLISH == chosenLanguage) { | |
return ENGLISH_GREETING; | |
} | |
if (Locale.FRENCH == chosenLanguage) { | |
return FRENCH_GREETING; | |
} | |
return null; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package se.raindance.mp.export.job; | |
import java.util.Locale; | |
import org.junit.Assert; | |
import org.junit.Before; | |
import org.junit.Test; | |
public class AtmTest { | |
Atm atm; | |
@Before | |
public void before() throws Exception { | |
atm = new Atm(); | |
} | |
@Test | |
public void insert_card_should_prompt_for_pincode() throws Exception { | |
String atmResponse = atm.insertCard("my visa"); | |
Assert.assertEquals("a request for pincode was expected", Atm.INSERT_PIN_RESPONSE, atmResponse); | |
} | |
@Test | |
public void insert_pincode_should_prompt_for_change_language() throws Exception { | |
atm.insertCard("cart"); | |
String atmResponse = atm.insertPincode(1234); | |
Assert.assertEquals("a language change question was expected", Atm.CHANGE_LANGUAGE, atmResponse); | |
} | |
@Test | |
public void change_language_should_greet_in_chosen_language_english() throws Exception { | |
String atmResponse = atm.changeLanguage(Locale.ENGLISH); | |
Assert.assertEquals("an english greeting was expected", Atm.ENGLISH_GREETING, atmResponse); | |
} | |
@Test | |
public void change_language_should_greet_in_chosen_language_french() throws Exception { | |
String atmResponse = atm.changeLanguage(Locale.FRENCH); | |
Assert.assertEquals("an english greeting was expected", Atm.FRENCH_GREETING, atmResponse); | |
} | |
@Test | |
public void _when_press_pin_and_no_card_prompt_to_insert_card() throws Exception { | |
String atmResponse = atm.insertPincode(1234); | |
Assert.assertEquals("a prompt to insert card was expected", Atm.INSERT_CARD, atmResponse); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment