Skip to content

Instantly share code, notes, and snippets.

View kmdupr33's full-sized avatar

Matt Dupree kmdupr33

View GitHub Profile
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());
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);
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);
public class MathNerd {
private final mCalcCache;
private final mCalculator;
public MathNerd(CalculationCache calcCache, Calculator calculator) {
mCalcCache = calcCache;
mCalculator = calculator;
}
public void testCacheUpdate() {
//Arrange
CalculationCache calcCache = new CalculationCache();
Calculator calculator = new Calculator();
MathNerd mathNerd = new MathNerd(calcCache, calculator);
Calculation calcualation = new Calculation("e^2000");
@Override
protected void onHandleIntent(Intent intent) {
final String action = intent.getAction();
Log.d(TAG, "Received intent: " + action);
final ContentResolver resolver = getContentResolver();
boolean isAddEvent = false;
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);
@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
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,
/**
* 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() {