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
public void testSquare() { | |
Calculator calculator = new Calculator(); | |
TerribleMathStudent terribleMathStudent = new TerribleMathStudent(calculator); | |
//terribleMathStudent uses calculator to do this | |
int result = terribleMathStudent.square(2); | |
assertTrue(calculator.didDoMath()); |
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
public void testSquare() { | |
TerribleMathStudent terribleMathStudent = new TerribleMathStudent(); | |
terribleMathStudent.setCalculator(new BrokenCalculator()); | |
//terribleMathStudent uses broken calculator to do this, so this student really sucks | |
int result = terribleMathStudent.square(2); | |
assertNotEquals(result, 4); | |
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
public void testSquare() { | |
MathNerd mathNerd = new MathNerd(); | |
//Math nerds only use calculators when they need them | |
int result = mathNerd.squareBigNumber(new BrokenCalculator(), 54321); | |
assertNotEquals(result, 2950771041); | |
result = mathNerd.squareBigNumber(new Calculator(), 54321); |
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
public class MathNerd { | |
private final mCalcCache; | |
private final mCalculator; | |
public MathNerd(CalculationCache calcCache, Calculator calculator) { | |
mCalcCache = calcCache; | |
mCalculator = calculator; | |
} |
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
public void testCacheUpdate() { | |
//Arrange | |
CalculationCache calcCache = new CalculationCache(); | |
Calculator calculator = new Calculator(); | |
MathNerd mathNerd = new MathNerd(calcCache, calculator); | |
Calculation calcualation = new Calculation("e^2000"); |
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
@Override | |
protected void onHandleIntent(Intent intent) { | |
final String action = intent.getAction(); | |
Log.d(TAG, "Received intent: " + action); | |
final ContentResolver resolver = getContentResolver(); | |
boolean isAddEvent = false; |
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
public void testCacheUpdate() { | |
//Arrange | |
CalculationCache calcCache = mock(CalculationCache.class); | |
when(calcCache.contains()).thenReturn(false); | |
Calculator calculator = mock(Calculator.class); | |
MathNerd mathNerd = new MathNerd(calcCache, calculator); |
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
@Override | |
public void onStop() { | |
super.onStop(); | |
if (mInitStarred != mStarred) { | |
if (UIUtils.getCurrentTime(this) < mSessionStart) { | |
// Update Calendar event through the Calendar API on Android 4.0 or new versions. | |
Intent intent = null; | |
if (mStarred) { | |
// Service launcher sets up intent to add session to Calendar |
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
public class SessionCalendarUpdaterTests extends TestCase { | |
public void testShouldClearAllSessions() throws RemoteException, OperationApplicationException { | |
SessionCalendarDatabase sessionCalendarDatabase = mock(SessionCalendarDatabase.class); | |
SessionCalendarUserPreferences sessionCalendarUserPreferences = mock(SessionCalendarUserPreferences.class); | |
SessionCalendarUpdater sessionCalendarUpdater = new SessionCalendarUpdater(sessionCalendarDatabase, |
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
/** | |
* Background {@link android.app.Service} that adds or removes session Calendar events through | |
* the {@link CalendarContract} API available in Android 4.0 or above. | |
*/ | |
public class SessionCalendarService extends IntentService { | |
private static final String TAG = makeLogTag(SessionCalendarService.class); | |
//... | |
public SessionCalendarService() { |