Skip to content

Instantly share code, notes, and snippets.

View izmajlowiczl's full-sized avatar

Łukasz Izmajłowicz izmajlowiczl

View GitHub Profile
@TestWith({
"0",
"1",
"2"
})
public void AddScore_AddPositiveScore_IncreaseExistingScore(int value) throws Exception {
final UserScoreRepository userScoreRepositoryStub = Make_FakeUserScoreRepository();
final User fakeUser = Make_User();
final UserScoreService userScore = new UserScoreService(userScoreRepositoryStub);
@izmajlowiczl
izmajlowiczl / Test_UserScore_GetValue.java
Created March 10, 2013 20:13
TestingExceptionsWithMessage
@Test
public void GetScore_GetForNotExistingUser_ThrowException() {
final UserScoreRepository userScoreRepositoryStub = Make_FakeUserScoreRepository();
final UserScoreService userScore = new UserScoreService(userScoreRepositoryStub);
final User fakeUser = null;
try {
final int userPoints = userScore.get(fakeUser);
} catch (IllegalArgumentException e) {
final String errorMessage = "User Is null";
@izmajlowiczl
izmajlowiczl / EmailValidator
Created April 24, 2013 06:36
[Android] Simple Email Validation
public boolean isValid(final CharSequence email) {
return android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches();
}
@izmajlowiczl
izmajlowiczl / MainActivity.java
Created May 29, 2013 09:47
Android Show Notification with NotificationCompat
createNotification(Calendar.getInstance().getTimeInMillis(), "hey!");
public static final String NOTIFICATION_DATA = "NOTIFICATION_DATA";
private void createNotification(long when, String data){
String notificationContent ="Notification Content Click Here to go more details";
String notificationTitle ="This is Notification";
//large icon for notification,normally use App icon
Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
int smalIcon =R.drawable.ic_launcher;
String notificationData="This is data : "+data;
@izmajlowiczl
izmajlowiczl / LegalFragment.java
Last active September 5, 2018 16:12
[Android] WebView back button
// Handles back button inside WebView.
// When user clicks back button and web history is not empty shows previous page from history.
mWebView.setOnKeyListener( new View.OnKeyListener() {
@Override
public boolean onKey( View v, int keyCode, KeyEvent event ) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
mWebView.goBack();
return true;
}
@izmajlowiczl
izmajlowiczl / CustomDatePicker.java
Created September 20, 2013 04:16
Date/Time Picker fix for ScrollView
package com.mydriver.customer.ui.common.custom;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewParent;
import android.widget.DatePicker;
/**
@izmajlowiczl
izmajlowiczl / TasksTestRunner.java
Created December 19, 2013 21:42
Custom RobolectricTestRunner with method for attaching fragments
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import org.junit.runners.model.InitializationError;
import org.robolectric.RobolectricTestRunner;
/**
* Customized test runner based on {@link org.robolectric.RobolectricTestRunner}.
*
* Creator: <lukasz.izmajlowicz@mydriver.com>
@Test
public void homeButtonHidesKeyboard() {
final MenuItem item = mock(MenuItem.class);
when(item.getItemId()).thenReturn(android.R.id.home);
testedFragment.onOptionsItemSelected(item);
verify(keyboardHackerMock).hideKeyboardAndResetBottomPaddingFor(any(View.class));
}
@izmajlowiczl
izmajlowiczl / TheLastSyncTimestamp.java
Created May 9, 2014 08:37
SharedPreferences with Robolectric
import android.content.SharedPreferences;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import static org.junit.Assert.assertEquals;
@RunWith(RobolectricTestRunner.class)
public class TheLastSyncTimestamp {
@izmajlowiczl
izmajlowiczl / todayAt
Created November 19, 2014 09:11
Sets device time Usage: ./todatAt 10 23
#!/bin/sh
# Command to set date for running device:
# adb shell date -s yyyymmdd.hhmmss
now="$(date +'%Y%m%d')"
adb shell date -s $now.$1$2