Skip to content

Instantly share code, notes, and snippets.

View oliverspryn's full-sized avatar
☀️
Everyday is a great day!

Oliver Spryn oliverspryn

☀️
Everyday is a great day!
View GitHub Profile
@oliverspryn
oliverspryn / colors.xml
Created November 5, 2021 12:41
The dark mode variant of the color pallet
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="launcher_background_color">@android:color/system_neutral1_800</color>
<color name="launcher_foreground_android_color">@android:color/system_accent1_100</color>
</resources>
@oliverspryn
oliverspryn / colors.xml
Created November 5, 2021 12:26
A color pallet using my brand's color scheme
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="launcher_background_color">#3DDC84</color>
<color name="launcher_foreground_android_color">#FFFFFF</color>
</resources>
@oliverspryn
oliverspryn / ic_launcher_foreground.xml
Created November 5, 2021 12:25
An adaptive Android app icon's foreground
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillColor="@color/launcher_foreground_android_color"
android:fillType="nonZero"
@oliverspryn
oliverspryn / ic_launcher_background.xml
Last active November 5, 2021 12:25
An adaptive Android app icon's background
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillColor="@color/launcher_background_color"
android:pathData="M0,0h108v108h-108z" />
@oliverspryn
oliverspryn / ic_launcher.xml
Created November 5, 2021 12:24
An adaptive Android app icon
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>
@oliverspryn
oliverspryn / DetailsViewMvcImplTest.kt
Created October 29, 2021 12:33
A faulty unit test, where only one side-effect is tested, giving me credit for full function coverage
class DetailsViewMvcImplTest : Spek({
describe("The DetailsViewMvcImpl") {
var mockButton: MaterialButton? = null
var mockPhoto: AppCompatImageView? = null
var mockRootView: View? = null
var mockTitle: AppCompatTextView? = null
var uut: DetailsViewMvcImpl? = null
@oliverspryn
oliverspryn / DetailsViewMvcImpl.kt
Created October 29, 2021 12:30
A simple MVC implementation, to demonstrate the fragility of unit tests
class DetailsViewMvcImpl() {
val button: MaterialButton
val photo: AppCompatImageView
val title: AppCompatTextView
init {
rootView = inflater.inflate(R.layout.details_fragment, parent, false)
button = findViewById(R.id.view_online_button)
@oliverspryn
oliverspryn / UnitTest.kt
Created October 21, 2021 21:52
The mocking set up of a unit test where the output of one function is not streamed into the input of the next function, but uses a generic matcher
whenever(userService.getUserName()).thenReturn("jsmith")
whenever(userService.getUserId()).thenReturn("123-456")
whenever(userService.getUrlToAvatarImage(any())).thenReturn("https://ddg.co/") // Generic matcher is prone to error
@oliverspryn
oliverspryn / UnitTest.kt
Created October 21, 2021 21:45
The mocking set up of a unit test where the output of one function streams into the parameter of another
whenever(userService.getUserName()).thenReturn("jsmith")
whenever(userService.getUserId()).thenReturn("123-456") // Output from here...
whenever(userService.getUrlToAvatarImage("123-456")).thenReturn("https://ddg.co/") // ... feeds into here
@oliverspryn
oliverspryn / PhotosControllerTest.kt
Last active October 21, 2021 21:54
A correct example of how to unit test the PhotosController
class PhotosControllerTest : Spek({
describe("The PhotosController") {
var mockPhotosApiService: PhotosApiService? = null
var mockSchedulerForwarder: SchedulerForwarder? = null
var uut: PhotosController? = null
beforeEachTest {
// uut and supporting classes setup and mocked here
}