├── .gitignore
├── .idea
├── .name
├── codeStyles
│ ├── Project.xml
│ └── codeStyleConfig.xml
├── gradle.xml
├── jarRepositories.xml
├── misc.xml
├── runConfigurations.xml
└── vcs.xml
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── denisbrandi
│ │ │ └── functionalmapping
│ │ │ ├── data
│ │ │ ├── fp
│ │ │ │ ├── mapper
│ │ │ │ │ ├── AlbumDataMapper.kt
│ │ │ │ │ ├── ListMappers.kt
│ │ │ │ │ └── SongDataMapper.kt
│ │ │ │ └── repository
│ │ │ │ │ └── AlbumRepositoryImpl.kt
│ │ │ ├── network
│ │ │ │ ├── AlbumApiService.kt
│ │ │ │ ├── AlbumApiServiceImpl.kt
│ │ │ │ └── model
│ │ │ │ │ ├── NetworkAlbum.kt
│ │ │ │ │ └── NetworkSong.kt
│ │ │ └── oop
│ │ │ │ ├── mapper
│ │ │ │ ├── AlbumDataMapper.kt
│ │ │ │ ├── ListMapper.kt
│ │ │ │ ├── ListMapperImpl.kt
│ │ │ │ ├── Mapper.kt
│ │ │ │ ├── NullableInputListMapper.kt
│ │ │ │ ├── NullableInputListMapperImpl.kt
│ │ │ │ ├── NullableOutputListMapper.kt
│ │ │ │ ├── NullableOutputListMapperImpl.kt
│ │ │ │ └── SongDataMapper.kt
│ │ │ │ └── repository
│ │ │ │ └── AlbumRepositoryImpl.kt
│ │ │ ├── di
│ │ │ ├── FPRepositoryFactory.kt
│ │ │ └── OOPRepositoryFactory.kt
│ │ │ └── domain
│ │ │ ├── model
│ │ │ ├── Album.kt
│ │ │ ├── Result.kt
│ │ │ └── Song.kt
│ │ │ └── repository
│ │ │ └── AlbumRepository.kt
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── denisbrandi
│ └── functionalmapping
│ └── data
│ ├── fp
│ ├── mapper
│ │ ├── AlbumDataMapperKtTest.kt
│ │ ├── ListMappersKtTest.kt
│ │ └── SongDataMapperKtTest.kt
│ └── repository
│ │ └── AlbumRepositoryImplTest.kt
│ └── oop
│ ├── mapper
│ ├── AlbumDataMapperTest.kt
│ ├── ListMapperImplTest.kt
│ ├── NullableInputListMapperImplTest.kt
│ ├── NullableOutputListMapperImplTest.kt
│ └── SongDataMapperTest.kt
│ └── repository
│ └── AlbumRepositoryImplTest.kt
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | MediumArticles
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | xmlns:android
17 |
18 | ^$
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 | xmlns:.*
28 |
29 | ^$
30 |
31 |
32 | BY_NAME
33 |
34 |
35 |
36 |
37 |
38 |
39 | .*:id
40 |
41 | http://schemas.android.com/apk/res/android
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | .*:name
51 |
52 | http://schemas.android.com/apk/res/android
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 | name
62 |
63 | ^$
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 | style
73 |
74 | ^$
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 | .*
84 |
85 | ^$
86 |
87 |
88 | BY_NAME
89 |
90 |
91 |
92 |
93 |
94 |
95 | .*
96 |
97 | http://schemas.android.com/apk/res/android
98 |
99 |
100 | ANDROID_ATTRIBUTE_ORDER
101 |
102 |
103 |
104 |
105 |
106 |
107 | .*
108 |
109 | .*
110 |
111 |
112 | BY_NAME
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
--------------------------------------------------------------------------------
/.idea/codeStyles/codeStyleConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
20 |
21 |
--------------------------------------------------------------------------------
/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | apply plugin: 'kotlin-android'
4 |
5 | apply plugin: 'kotlin-android-extensions'
6 |
7 | android {
8 | compileSdkVersion 29
9 | buildToolsVersion "29.0.2"
10 | defaultConfig {
11 | applicationId "com.denisbrandi.mediumarticles"
12 | minSdkVersion 21
13 | targetSdkVersion 29
14 | versionCode 1
15 | versionName "1.0"
16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17 | }
18 | compileOptions {
19 | sourceCompatibility JavaVersion.VERSION_1_8
20 | targetCompatibility JavaVersion.VERSION_1_8
21 | }
22 | buildTypes {
23 | release {
24 | minifyEnabled false
25 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
26 | }
27 | }
28 | }
29 |
30 | dependencies {
31 | implementation fileTree(dir: 'libs', include: ['*.jar'])
32 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
33 | implementation 'androidx.appcompat:appcompat:1.0.2'
34 | implementation 'androidx.core:core-ktx:1.0.2'
35 |
36 | implementation "io.reactivex.rxjava2:rxjava:2.2.9"
37 | implementation "io.reactivex.rxjava2:rxandroid:2.1.1"
38 | implementation "io.reactivex.rxjava2:rxkotlin:2.3.0"
39 | implementation 'com.squareup.retrofit2:retrofit:2.6.0'
40 | implementation "com.squareup.retrofit2:converter-gson:2.6.0"
41 | implementation "com.squareup.okhttp3:logging-interceptor:3.14.1"
42 | implementation "com.squareup.retrofit2:adapter-rxjava2:2.6.0"
43 |
44 | testImplementation 'junit:junit:4.12'
45 | testImplementation 'org.mockito:mockito-core:2.28.2'
46 | testImplementation 'com.nhaarman.mockitokotlin2:mockito-kotlin:2.1.0'
47 | testImplementation "com.google.truth:truth:0.44"
48 | androidTestImplementation 'androidx.test.ext:junit:1.1.0'
49 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
50 | }
51 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/java/com/denisbrandi/functionalmapping/data/fp/mapper/AlbumDataMapper.kt:
--------------------------------------------------------------------------------
1 | package com.denisbrandi.functionalmapping.data.fp.mapper
2 |
3 | import com.denisbrandi.functionalmapping.data.network.model.NetworkAlbum
4 | import com.denisbrandi.functionalmapping.data.network.model.NetworkSong
5 | import com.denisbrandi.functionalmapping.domain.model.Album
6 | import com.denisbrandi.functionalmapping.domain.model.Song
7 |
8 | inline fun mapAlbumDto(input: NetworkAlbum, mapSongList: (List?) -> List): Album {
9 | return Album(
10 | input.id.orEmpty(),
11 | input.title.orEmpty(),
12 | mapSongList(input.songs)
13 | )
14 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/denisbrandi/functionalmapping/data/fp/mapper/ListMappers.kt:
--------------------------------------------------------------------------------
1 | package com.denisbrandi.functionalmapping.data.fp.mapper
2 |
3 | inline fun mapList(input: List, mapListItem: (I) -> O): List {
4 | return input.map { mapListItem(it) }
5 | }
6 |
7 | inline fun mapNullInputList(input: List?, mapListItem: (I) -> O): List {
8 | return input?.map { mapListItem(it) } ?: emptyList()
9 | }
10 |
11 | inline fun mapNullOutputList(input: List, mapListItem: (I) -> O): List? {
12 | return if (input.isEmpty()) null else input.map { mapListItem(it) }
13 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/denisbrandi/functionalmapping/data/fp/mapper/SongDataMapper.kt:
--------------------------------------------------------------------------------
1 | package com.denisbrandi.functionalmapping.data.fp.mapper
2 |
3 | import com.denisbrandi.functionalmapping.data.network.model.NetworkSong
4 | import com.denisbrandi.functionalmapping.domain.model.Song
5 | import java.text.SimpleDateFormat
6 | import java.util.*
7 |
8 | fun mapSongDto(input: NetworkSong): Song {
9 | return Song(
10 | input.id.orEmpty(),
11 | input.name.orEmpty(),
12 | input.link.orEmpty(),
13 | input.duration ?: 0,
14 | Song.Metadata(
15 | formatAlbumDate(input.creationDate),
16 | formatAlbumDate(input.uploadDate),
17 | input.authorFullName.orEmpty()
18 | )
19 | )
20 | }
21 |
22 | private fun formatAlbumDate(date: String?): Long {
23 | return date?.let {
24 | SimpleDateFormat("dd MMMM yyyy HH:mm:ss", Locale.UK).parse(it).time
25 | } ?: Long.MIN_VALUE
26 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/denisbrandi/functionalmapping/data/fp/repository/AlbumRepositoryImpl.kt:
--------------------------------------------------------------------------------
1 | package com.denisbrandi.functionalmapping.data.fp.repository
2 |
3 | import com.denisbrandi.functionalmapping.data.network.AlbumApiService
4 | import com.denisbrandi.functionalmapping.data.network.model.NetworkAlbum
5 | import com.denisbrandi.functionalmapping.domain.model.Album
6 | import com.denisbrandi.functionalmapping.domain.model.Result
7 | import com.denisbrandi.functionalmapping.domain.model.SimpleResult
8 | import com.denisbrandi.functionalmapping.domain.repository.AlbumRepository
9 | import io.reactivex.Single
10 |
11 | class AlbumRepositoryImpl(
12 | private val albumApiService: AlbumApiService,
13 | private val mapAlbumDto: (NetworkAlbum) -> Album
14 | ) : AlbumRepository {
15 |
16 | override fun getAlbumById(id: String): Single> {
17 | return albumApiService.getAlbumById(id).map {
18 | it.fold(
19 | success = { dto -> Result.Success(mapAlbumDto(dto)) },
20 | failure = { throwable -> Result.Failure(throwable) }
21 | )
22 | }
23 | }
24 |
25 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/denisbrandi/functionalmapping/data/network/AlbumApiService.kt:
--------------------------------------------------------------------------------
1 | package com.denisbrandi.functionalmapping.data.network
2 |
3 | import com.denisbrandi.functionalmapping.data.network.model.NetworkAlbum
4 | import com.denisbrandi.functionalmapping.domain.model.SimpleResult
5 | import io.reactivex.Single
6 |
7 | interface AlbumApiService {
8 |
9 | fun getAlbumById(id: String): Single>
10 |
11 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/denisbrandi/functionalmapping/data/network/AlbumApiServiceImpl.kt:
--------------------------------------------------------------------------------
1 | package com.denisbrandi.functionalmapping.data.network
2 |
3 | import com.denisbrandi.functionalmapping.data.network.model.NetworkAlbum
4 | import com.denisbrandi.functionalmapping.domain.model.SimpleResult
5 | import io.reactivex.Single
6 |
7 | class AlbumApiServiceImpl: AlbumApiService {
8 | override fun getAlbumById(id: String): Single> {
9 | TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
10 | }
11 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/denisbrandi/functionalmapping/data/network/model/NetworkAlbum.kt:
--------------------------------------------------------------------------------
1 | package com.denisbrandi.functionalmapping.data.network.model
2 |
3 | import com.google.gson.annotations.SerializedName
4 |
5 | data class NetworkAlbum(
6 | @SerializedName("id")
7 | val id: String?,
8 | @SerializedName("title")
9 | val title: String?,
10 | @SerializedName("songs")
11 | val songs: List?
12 | )
--------------------------------------------------------------------------------
/app/src/main/java/com/denisbrandi/functionalmapping/data/network/model/NetworkSong.kt:
--------------------------------------------------------------------------------
1 | package com.denisbrandi.functionalmapping.data.network.model
2 |
3 | import com.google.gson.annotations.SerializedName
4 |
5 | data class NetworkSong(
6 | @SerializedName("id")
7 | val id: String?,
8 | @SerializedName("name")
9 | val name: String?,
10 | @SerializedName("link")
11 | val link: String?,
12 | @SerializedName("duration")
13 | val duration: Long?,
14 | @SerializedName("creationDate")
15 | val creationDate: String?,
16 | @SerializedName("uploadDate")
17 | val uploadDate: String?,
18 | @SerializedName("authorFullName")
19 | val authorFullName: String?
20 | )
--------------------------------------------------------------------------------
/app/src/main/java/com/denisbrandi/functionalmapping/data/oop/mapper/AlbumDataMapper.kt:
--------------------------------------------------------------------------------
1 | package com.denisbrandi.functionalmapping.data.oop.mapper
2 |
3 | import com.denisbrandi.functionalmapping.data.network.model.NetworkAlbum
4 | import com.denisbrandi.functionalmapping.data.network.model.NetworkSong
5 | import com.denisbrandi.functionalmapping.domain.model.Album
6 | import com.denisbrandi.functionalmapping.domain.model.Song
7 |
8 | class AlbumDataMapper(
9 | private val songListDataMapper: NullableInputListMapper
10 | ) : Mapper {
11 |
12 | override fun map(input: NetworkAlbum): Album {
13 | return Album(
14 | input.id.orEmpty(),
15 | input.title.orEmpty(),
16 | songListDataMapper.map(input.songs)
17 | )
18 | }
19 |
20 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/denisbrandi/functionalmapping/data/oop/mapper/ListMapper.kt:
--------------------------------------------------------------------------------
1 | package com.denisbrandi.functionalmapping.data.oop.mapper
2 |
3 | interface ListMapper: Mapper, List>
4 |
--------------------------------------------------------------------------------
/app/src/main/java/com/denisbrandi/functionalmapping/data/oop/mapper/ListMapperImpl.kt:
--------------------------------------------------------------------------------
1 | package com.denisbrandi.functionalmapping.data.oop.mapper
2 |
3 | class ListMapperImpl(
4 | private val mapper: Mapper
5 | ) : ListMapper {
6 | override fun map(input: List): List {
7 | return input.map { mapper.map(it) }
8 | }
9 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/denisbrandi/functionalmapping/data/oop/mapper/Mapper.kt:
--------------------------------------------------------------------------------
1 | package com.denisbrandi.functionalmapping.data.oop.mapper
2 |
3 | interface Mapper {
4 | fun map(input: I): O
5 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/denisbrandi/functionalmapping/data/oop/mapper/NullableInputListMapper.kt:
--------------------------------------------------------------------------------
1 | package com.denisbrandi.functionalmapping.data.oop.mapper
2 |
3 | interface NullableInputListMapper : Mapper?, List>
--------------------------------------------------------------------------------
/app/src/main/java/com/denisbrandi/functionalmapping/data/oop/mapper/NullableInputListMapperImpl.kt:
--------------------------------------------------------------------------------
1 | package com.denisbrandi.functionalmapping.data.oop.mapper
2 |
3 | class NullableInputListMapperImpl(
4 | private val mapper: Mapper
5 | ) : NullableInputListMapper {
6 | override fun map(input: List?): List {
7 | return input?.map { mapper.map(it) }.orEmpty()
8 | }
9 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/denisbrandi/functionalmapping/data/oop/mapper/NullableOutputListMapper.kt:
--------------------------------------------------------------------------------
1 | package com.denisbrandi.functionalmapping.data.oop.mapper
2 |
3 | interface NullableOutputListMapper: Mapper, List?>
4 |
--------------------------------------------------------------------------------
/app/src/main/java/com/denisbrandi/functionalmapping/data/oop/mapper/NullableOutputListMapperImpl.kt:
--------------------------------------------------------------------------------
1 | package com.denisbrandi.functionalmapping.data.oop.mapper
2 |
3 | class NullableOutputListMapperImpl(
4 | private val mapper: Mapper
5 | ) : NullableOutputListMapper {
6 | override fun map(input: List): List? {
7 | return if (input.isEmpty()) null else input.map { mapper.map(it) }
8 | }
9 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/denisbrandi/functionalmapping/data/oop/mapper/SongDataMapper.kt:
--------------------------------------------------------------------------------
1 | package com.denisbrandi.functionalmapping.data.oop.mapper
2 |
3 | import com.denisbrandi.functionalmapping.data.network.model.NetworkSong
4 | import com.denisbrandi.functionalmapping.domain.model.Song
5 | import java.text.SimpleDateFormat
6 | import java.util.*
7 |
8 | class SongDataMapper : Mapper {
9 |
10 | override fun map(input: NetworkSong): Song {
11 | return Song(
12 | input.id.orEmpty(),
13 | input.name.orEmpty(),
14 | input.link.orEmpty(),
15 | input.duration ?: 0,
16 | Song.Metadata(
17 | formatDate(input.creationDate),
18 | formatDate(input.uploadDate),
19 | input.authorFullName.orEmpty()
20 | )
21 | )
22 | }
23 |
24 | private fun formatDate(date: String?): Long {
25 | return date?.let {
26 | SimpleDateFormat(DATE_FORMAT_PATTERN, Locale.UK).parse(it).time
27 | } ?: Long.MIN_VALUE
28 | }
29 |
30 | private companion object {
31 | const val DATE_FORMAT_PATTERN = "dd MMMM yyyy HH:mm:ss"
32 | }
33 |
34 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/denisbrandi/functionalmapping/data/oop/repository/AlbumRepositoryImpl.kt:
--------------------------------------------------------------------------------
1 | package com.denisbrandi.functionalmapping.data.oop.repository
2 |
3 | import com.denisbrandi.functionalmapping.data.network.AlbumApiService
4 | import com.denisbrandi.functionalmapping.data.network.model.NetworkAlbum
5 | import com.denisbrandi.functionalmapping.data.oop.mapper.Mapper
6 | import com.denisbrandi.functionalmapping.domain.model.Album
7 | import com.denisbrandi.functionalmapping.domain.model.Result
8 | import com.denisbrandi.functionalmapping.domain.model.SimpleResult
9 | import com.denisbrandi.functionalmapping.domain.repository.AlbumRepository
10 | import io.reactivex.Single
11 |
12 | class AlbumRepositoryImpl(
13 | private val albumApiService: AlbumApiService,
14 | private val albumDataMapper: Mapper
15 | ) : AlbumRepository {
16 |
17 | override fun getAlbumById(id: String): Single> {
18 | return albumApiService.getAlbumById(id).map {
19 | it.fold(
20 | success = { dto -> Result.Success(albumDataMapper.map(dto)) },
21 | failure = { throwable -> Result.Failure(throwable) }
22 | )
23 | }
24 | }
25 |
26 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/denisbrandi/functionalmapping/di/FPRepositoryFactory.kt:
--------------------------------------------------------------------------------
1 | package com.denisbrandi.functionalmapping.di
2 |
3 | import com.denisbrandi.functionalmapping.data.fp.mapper.mapAlbumDto
4 | import com.denisbrandi.functionalmapping.data.fp.mapper.mapNullInputList
5 | import com.denisbrandi.functionalmapping.data.fp.mapper.mapSongDto
6 | import com.denisbrandi.functionalmapping.data.fp.repository.AlbumRepositoryImpl
7 | import com.denisbrandi.functionalmapping.data.network.AlbumApiServiceImpl
8 | import com.denisbrandi.functionalmapping.data.network.model.NetworkAlbum
9 | import com.denisbrandi.functionalmapping.domain.model.Album
10 | import com.denisbrandi.functionalmapping.domain.repository.AlbumRepository
11 |
12 | object FPRepositoryFactory {
13 |
14 | fun makeAlbumRepository(): AlbumRepository {
15 | return AlbumRepositoryImpl(
16 | AlbumApiServiceImpl(),
17 | makeAlbumDataMapper()
18 | )
19 | }
20 |
21 | private fun makeAlbumDataMapper(): (NetworkAlbum) -> Album = { albumDto ->
22 | mapAlbumDto(albumDto) { listItemDto ->
23 | mapNullInputList(listItemDto) { songDto ->
24 | mapSongDto(songDto)
25 | }
26 | }
27 | }
28 |
29 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/denisbrandi/functionalmapping/di/OOPRepositoryFactory.kt:
--------------------------------------------------------------------------------
1 | package com.denisbrandi.functionalmapping.di
2 |
3 | import com.denisbrandi.functionalmapping.data.network.AlbumApiServiceImpl
4 | import com.denisbrandi.functionalmapping.data.oop.mapper.AlbumDataMapper
5 | import com.denisbrandi.functionalmapping.data.oop.mapper.NullableInputListMapperImpl
6 | import com.denisbrandi.functionalmapping.data.oop.mapper.SongDataMapper
7 | import com.denisbrandi.functionalmapping.data.oop.repository.AlbumRepositoryImpl
8 | import com.denisbrandi.functionalmapping.domain.repository.AlbumRepository
9 |
10 | object OOPRepositoryFactory {
11 |
12 | fun makeAlbumRepository(): AlbumRepository {
13 | return AlbumRepositoryImpl(
14 | AlbumApiServiceImpl(),
15 | AlbumDataMapper(NullableInputListMapperImpl(SongDataMapper()))
16 | )
17 | }
18 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/denisbrandi/functionalmapping/domain/model/Album.kt:
--------------------------------------------------------------------------------
1 | package com.denisbrandi.functionalmapping.domain.model
2 |
3 | // Aggregate
4 | data class Album(
5 | val id: String,
6 | val title: String,
7 | val songs: List
8 | )
--------------------------------------------------------------------------------
/app/src/main/java/com/denisbrandi/functionalmapping/domain/model/Result.kt:
--------------------------------------------------------------------------------
1 | package com.denisbrandi.functionalmapping.domain.model
2 |
3 | sealed class Result {
4 |
5 | data class Success(val value: T) : Result()
6 |
7 | data class Failure(val error: E) : Result()
8 |
9 | inline fun fold(success: (T) -> C, failure: (E) -> C): C = when (this) {
10 | is Success -> success(value)
11 | is Failure -> failure(error)
12 | }
13 |
14 | }
15 |
16 | typealias SimpleResult = Result
--------------------------------------------------------------------------------
/app/src/main/java/com/denisbrandi/functionalmapping/domain/model/Song.kt:
--------------------------------------------------------------------------------
1 | package com.denisbrandi.functionalmapping.domain.model
2 |
3 | // Entity
4 | data class Song(
5 | val id: String,
6 | val name: String,
7 | val link: String,
8 | val duration: Long,
9 | val metadata: Metadata
10 | ) {
11 | // Value Object
12 | data class Metadata(
13 | val creationDate: Long,
14 | val uploadDate: Long,
15 | val authorFullName: String
16 | )
17 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/denisbrandi/functionalmapping/domain/repository/AlbumRepository.kt:
--------------------------------------------------------------------------------
1 | package com.denisbrandi.functionalmapping.domain.repository
2 |
3 | import com.denisbrandi.functionalmapping.domain.model.Album
4 | import com.denisbrandi.functionalmapping.domain.model.SimpleResult
5 | import io.reactivex.Single
6 |
7 | interface AlbumRepository {
8 |
9 | fun getAlbumById(id: String): Single>
10 |
11 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DenisBronx/FunctionalMapping/ce9b00b349bc0f2277bbacb599255506c5141e32/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DenisBronx/FunctionalMapping/ce9b00b349bc0f2277bbacb599255506c5141e32/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DenisBronx/FunctionalMapping/ce9b00b349bc0f2277bbacb599255506c5141e32/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DenisBronx/FunctionalMapping/ce9b00b349bc0f2277bbacb599255506c5141e32/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DenisBronx/FunctionalMapping/ce9b00b349bc0f2277bbacb599255506c5141e32/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DenisBronx/FunctionalMapping/ce9b00b349bc0f2277bbacb599255506c5141e32/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DenisBronx/FunctionalMapping/ce9b00b349bc0f2277bbacb599255506c5141e32/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DenisBronx/FunctionalMapping/ce9b00b349bc0f2277bbacb599255506c5141e32/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DenisBronx/FunctionalMapping/ce9b00b349bc0f2277bbacb599255506c5141e32/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DenisBronx/FunctionalMapping/ce9b00b349bc0f2277bbacb599255506c5141e32/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | MediumArticles
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/denisbrandi/functionalmapping/data/fp/mapper/AlbumDataMapperKtTest.kt:
--------------------------------------------------------------------------------
1 | package com.denisbrandi.functionalmapping.data.fp.mapper
2 |
3 | import com.denisbrandi.functionalmapping.data.network.model.NetworkAlbum
4 | import com.denisbrandi.functionalmapping.data.network.model.NetworkSong
5 | import com.denisbrandi.functionalmapping.domain.model.Song
6 | import com.google.common.truth.Truth.assertThat
7 | import org.junit.Test
8 |
9 | class AlbumDataMapperKtTest {
10 |
11 | private val networkSongList = emptyList()
12 | private val songList = emptyList()
13 | private val mapSongList: (List?) -> List = {
14 | if (it === networkSongList) songList else throw Exception("not mocked")
15 | }
16 |
17 | private fun makeNetworkAlbum(
18 | id: String? = null,
19 | title: String? = null
20 | ): NetworkAlbum {
21 | return NetworkAlbum(id, title, networkSongList)
22 | }
23 |
24 | @Test
25 | fun `mapAlbumDto should replace null values with defaults`() {
26 | val dto = makeNetworkAlbum()
27 |
28 | val actual = mapAlbumDto(dto, mapSongList)
29 |
30 | assertThat(actual.id).isEmpty()
31 | assertThat(actual.title).isEmpty()
32 | }
33 |
34 | @Test
35 | fun `mapAlbumDto should assign correct values`() {
36 | val dto = makeNetworkAlbum("id", "title")
37 |
38 | val actual = mapAlbumDto(dto, mapSongList)
39 |
40 | assertThat(actual.id).isEqualTo("id")
41 | assertThat(actual.title).isEqualTo("title")
42 | assertThat(actual.songs).isEqualTo(songList)
43 | }
44 | }
--------------------------------------------------------------------------------
/app/src/test/java/com/denisbrandi/functionalmapping/data/fp/mapper/ListMappersKtTest.kt:
--------------------------------------------------------------------------------
1 | package com.denisbrandi.functionalmapping.data.fp.mapper
2 |
3 | import com.google.common.truth.Truth.assertThat
4 | import com.nhaarman.mockitokotlin2.mock
5 | import org.junit.Test
6 |
7 | class ListMappersKtTest {
8 |
9 | private val input1: Any = mock()
10 | private val input2: Any = mock()
11 | private val output1: Any = mock()
12 | private val output2: Any = mock()
13 |
14 | private val inputOutputMap = mapOf(input1 to output1, input2 to output2)
15 | private val mapListItem: (Any) -> Any = { input -> inputOutputMap.getValue(input) }
16 |
17 | //region mapList
18 | @Test
19 | fun `mapList should return empty list when input list is empty`() {
20 | val actual = mapList(emptyList(), mapListItem)
21 |
22 | assertThat(actual).isEmpty()
23 | }
24 |
25 | @Test
26 | fun `mapList should return mapped list when input list is 1`() {
27 | val actual = mapList(listOf(input1), mapListItem)
28 |
29 | assertThat(actual.size).isEqualTo(1)
30 | assertThat(actual[0]).isEqualTo(output1)
31 | }
32 |
33 | @Test
34 | fun `mapList should return mapped list when input list is many`() {
35 | val actual = mapList(listOf(input1, input2), mapListItem)
36 |
37 | assertThat(actual.size).isEqualTo(2)
38 | assertThat(actual[0]).isEqualTo(output1)
39 | assertThat(actual[1]).isEqualTo(output2)
40 | }
41 | //endregion
42 |
43 | //region mapNullInputList
44 | @Test
45 | fun `mapNullInputList should return empty list when input list is null`() {
46 | val actual = mapNullInputList(null, mapListItem)
47 |
48 | assertThat(actual).isEmpty()
49 | }
50 |
51 | @Test
52 | fun `mapNullInputList should return empty list when input list is empty`() {
53 | val actual = mapNullInputList(emptyList(), mapListItem)
54 |
55 | assertThat(actual).isEmpty()
56 | }
57 |
58 | @Test
59 | fun `mapNullInputList should return mapped list when input list is 1`() {
60 | val actual = mapNullInputList(listOf(input1), mapListItem)
61 |
62 | assertThat(actual.size).isEqualTo(1)
63 | assertThat(actual[0]).isEqualTo(output1)
64 | }
65 |
66 | @Test
67 | fun `mapNullInputList should return mapped list when input list is many`() {
68 | val actual = mapNullInputList(listOf(input1, input2), mapListItem)
69 |
70 | assertThat(actual.size).isEqualTo(2)
71 | assertThat(actual[0]).isEqualTo(output1)
72 | assertThat(actual[1]).isEqualTo(output2)
73 | }
74 | //endregion
75 |
76 | //region mapNullOutputList
77 | @Test
78 | fun `mapNullOutputList should return empty list when input list is empty`() {
79 | val actual = mapNullOutputList(emptyList(), mapListItem)
80 |
81 | assertThat(actual).isNull()
82 | }
83 |
84 | @Test
85 | fun `mapNullOutputList should return mapped list when input list is 1`() {
86 | val actual = mapNullOutputList(listOf(input1), mapListItem)
87 |
88 | assertThat(actual!!.size).isEqualTo(1)
89 | assertThat(actual[0]).isEqualTo(output1)
90 | }
91 |
92 | @Test
93 | fun `mapNullOutputList should return mapped list when input list is many`() {
94 | val actual = mapNullOutputList(listOf(input1, input2), mapListItem)
95 |
96 | assertThat(actual!!.size).isEqualTo(2)
97 | assertThat(actual[0]).isEqualTo(output1)
98 | assertThat(actual[1]).isEqualTo(output2)
99 | }
100 | //endregion
101 |
102 | }
--------------------------------------------------------------------------------
/app/src/test/java/com/denisbrandi/functionalmapping/data/fp/mapper/SongDataMapperKtTest.kt:
--------------------------------------------------------------------------------
1 | package com.denisbrandi.functionalmapping.data.fp.mapper
2 |
3 | import com.denisbrandi.functionalmapping.data.network.model.NetworkSong
4 | import com.google.common.truth.Truth.assertThat
5 | import org.junit.Test
6 |
7 | class SongDataMapperKtTest {
8 |
9 | private fun makeNetworkSong(
10 | id: String? = null,
11 | name: String? = null,
12 | link: String? = null,
13 | duration: Long? = null,
14 | creationDate: String? = null,
15 | uploadDate: String? = null,
16 | authorFullName: String? = null
17 | ): NetworkSong {
18 | return NetworkSong(
19 | id,
20 | name,
21 | link,
22 | duration,
23 | creationDate,
24 | uploadDate,
25 | authorFullName
26 | )
27 | }
28 |
29 | @Test
30 | fun `mapSongDto should replace null values with defaults`() {
31 | val dto = makeNetworkSong()
32 |
33 | val actual = mapSongDto(dto)
34 |
35 | assertThat(actual.id).isEmpty()
36 | assertThat(actual.name).isEmpty()
37 | assertThat(actual.link).isEmpty()
38 | assertThat(actual.duration).isEqualTo(0)
39 | assertThat(actual.metadata.authorFullName).isEmpty()
40 | assertThat(actual.metadata.creationDate).isEqualTo(Long.MIN_VALUE)
41 | assertThat(actual.metadata.uploadDate).isEqualTo(Long.MIN_VALUE)
42 | }
43 |
44 | @Test
45 | fun `mapSongDto should replace assign and format correct values`() {
46 | val dto = makeNetworkSong(
47 | "id",
48 | "name",
49 | "link",
50 | 50L,
51 | "29 May 2015 05:50:06",
52 | "29 May 2015 05:50:06",
53 | "Name Surname"
54 | )
55 |
56 | val actual = mapSongDto(dto)
57 |
58 | assertThat(actual.id).isEqualTo("id")
59 | assertThat(actual.name).isEqualTo("name")
60 | assertThat(actual.link).isEqualTo("link")
61 | assertThat(actual.duration).isEqualTo(50)
62 | assertThat(actual.metadata.authorFullName).isEqualTo("Name Surname")
63 | assertThat(actual.metadata.creationDate).isEqualTo(1432875006000)
64 | assertThat(actual.metadata.uploadDate).isEqualTo(1432875006000)
65 | }
66 |
67 | }
--------------------------------------------------------------------------------
/app/src/test/java/com/denisbrandi/functionalmapping/data/fp/repository/AlbumRepositoryImplTest.kt:
--------------------------------------------------------------------------------
1 | package com.denisbrandi.functionalmapping.data.fp.repository
2 |
3 | import com.denisbrandi.functionalmapping.data.network.AlbumApiService
4 | import com.denisbrandi.functionalmapping.data.network.model.NetworkAlbum
5 | import com.denisbrandi.functionalmapping.domain.model.Album
6 | import com.denisbrandi.functionalmapping.domain.model.Result
7 | import com.nhaarman.mockitokotlin2.mock
8 | import com.nhaarman.mockitokotlin2.whenever
9 | import io.reactivex.Single
10 | import org.junit.Test
11 |
12 | class AlbumRepositoryImplTest {
13 |
14 | private val albumApiService: AlbumApiService = mock()
15 | private val networkAlbum = NetworkAlbum(null, null, emptyList())
16 | private val album = Album("", "", emptyList())
17 | private val mapAlbumDto: (NetworkAlbum) -> Album = {
18 | if (it === networkAlbum) album else throw Exception("not mocked")
19 | }
20 | private val sut = AlbumRepositoryImpl(albumApiService, mapAlbumDto)
21 |
22 | @Test
23 | fun `getAlbumById should return album when apiService call is successful`() {
24 | whenever(albumApiService.getAlbumById(ALBUM_ID))
25 | .thenReturn(Single.just(Result.Success(networkAlbum)))
26 |
27 | val testObserver = sut.getAlbumById(ALBUM_ID).test()
28 |
29 | testObserver.assertValue(Result.Success(album))
30 | }
31 |
32 | @Test
33 | fun `getAlbumById should return unmapped Failure when apiService call is not successful`() {
34 | val throwable = Throwable()
35 | whenever(albumApiService.getAlbumById(ALBUM_ID))
36 | .thenReturn(Single.just(Result.Failure(throwable)))
37 |
38 | val testObserver = sut.getAlbumById(ALBUM_ID).test()
39 |
40 | testObserver.assertValue(Result.Failure(throwable))
41 | }
42 |
43 | private companion object {
44 | const val ALBUM_ID = "id"
45 | }
46 | }
--------------------------------------------------------------------------------
/app/src/test/java/com/denisbrandi/functionalmapping/data/oop/mapper/AlbumDataMapperTest.kt:
--------------------------------------------------------------------------------
1 | package com.denisbrandi.functionalmapping.data.oop.mapper
2 |
3 | import com.denisbrandi.functionalmapping.data.network.model.NetworkAlbum
4 | import com.denisbrandi.functionalmapping.data.network.model.NetworkSong
5 | import com.denisbrandi.functionalmapping.domain.model.Song
6 | import com.google.common.truth.Truth.assertThat
7 | import com.nhaarman.mockitokotlin2.mock
8 | import com.nhaarman.mockitokotlin2.whenever
9 | import org.junit.Test
10 |
11 | class AlbumDataMapperTest {
12 |
13 | private val networkSongList = emptyList()
14 | private val songList = emptyList()
15 | private val songListDataMapper: NullableInputListMapper = mock {
16 | whenever(it.map(networkSongList)).thenReturn(songList)
17 | }
18 | private val sut = AlbumDataMapper(songListDataMapper)
19 |
20 | private fun makeNetworkAlbum(
21 | id: String? = null,
22 | title: String? = null
23 | ): NetworkAlbum {
24 | return NetworkAlbum(id, title, networkSongList)
25 | }
26 |
27 | @Test
28 | fun `map should replace null values with defaults`() {
29 | val dto = makeNetworkAlbum()
30 |
31 | val actual = sut.map(dto)
32 |
33 | assertThat(actual.id).isEmpty()
34 | assertThat(actual.title).isEmpty()
35 | }
36 |
37 | @Test
38 | fun `map should assign correct values`() {
39 | val dto = makeNetworkAlbum("id", "title")
40 |
41 | val actual = sut.map(dto)
42 |
43 | assertThat(actual.id).isEqualTo("id")
44 | assertThat(actual.title).isEqualTo("title")
45 | assertThat(actual.songs).isEqualTo(songList)
46 | }
47 | }
--------------------------------------------------------------------------------
/app/src/test/java/com/denisbrandi/functionalmapping/data/oop/mapper/ListMapperImplTest.kt:
--------------------------------------------------------------------------------
1 | package com.denisbrandi.functionalmapping.data.oop.mapper
2 |
3 | import com.google.common.truth.Truth.assertThat
4 | import com.nhaarman.mockitokotlin2.mock
5 | import com.nhaarman.mockitokotlin2.whenever
6 | import org.junit.Test
7 |
8 | class ListMapperImplTest {
9 |
10 | private val input1: Any = mock()
11 | private val input2: Any = mock()
12 | private val output1: Any = mock()
13 | private val output2: Any = mock()
14 |
15 | private val mapper: Mapper = mock {
16 | whenever(it.map(input1)).thenReturn(output1)
17 | whenever(it.map(input2)).thenReturn(output2)
18 | }
19 | private val sut = ListMapperImpl(mapper)
20 |
21 | @Test
22 | fun `map should return empty list when input list is empty`() {
23 | val actual = sut.map(emptyList())
24 |
25 | assertThat(actual).isEmpty()
26 | }
27 |
28 | @Test
29 | fun `map should return mapped list when input list is 1`() {
30 | val actual = sut.map(listOf(input1))
31 |
32 | assertThat(actual.size).isEqualTo(1)
33 | assertThat(actual[0]).isEqualTo(output1)
34 | }
35 |
36 | @Test
37 | fun `map should return mapped list when input list is many`() {
38 | val actual = sut.map(listOf(input1, input2))
39 |
40 | assertThat(actual.size).isEqualTo(2)
41 | assertThat(actual[0]).isEqualTo(output1)
42 | assertThat(actual[1]).isEqualTo(output2)
43 | }
44 | }
--------------------------------------------------------------------------------
/app/src/test/java/com/denisbrandi/functionalmapping/data/oop/mapper/NullableInputListMapperImplTest.kt:
--------------------------------------------------------------------------------
1 | package com.denisbrandi.functionalmapping.data.oop.mapper
2 |
3 | import com.google.common.truth.Truth.assertThat
4 | import com.nhaarman.mockitokotlin2.mock
5 | import com.nhaarman.mockitokotlin2.whenever
6 | import org.junit.Test
7 |
8 | class NullableInputListMapperImplTest {
9 |
10 | private val input1: Any = mock()
11 | private val input2: Any = mock()
12 | private val output1: Any = mock()
13 | private val output2: Any = mock()
14 |
15 | private val mapper: Mapper = mock {
16 | whenever(it.map(input1)).thenReturn(output1)
17 | whenever(it.map(input2)).thenReturn(output2)
18 | }
19 | private val sut = NullableInputListMapperImpl(mapper)
20 |
21 | @Test
22 | fun `map should return empty list when input list is null`() {
23 | val actual = sut.map(null)
24 |
25 | assertThat(actual).isEmpty()
26 | }
27 |
28 | @Test
29 | fun `map should return empty list when input list is empty`() {
30 | val actual = sut.map(emptyList())
31 |
32 | assertThat(actual).isEmpty()
33 | }
34 |
35 | @Test
36 | fun `map should return mapped list when input list is 1`() {
37 | val actual = sut.map(listOf(input1))
38 |
39 | assertThat(actual.size).isEqualTo(1)
40 | assertThat(actual[0]).isEqualTo(output1)
41 | }
42 |
43 | @Test
44 | fun `map should return mapped list when input list is many`() {
45 | val actual = sut.map(listOf(input1, input2))
46 |
47 | assertThat(actual.size).isEqualTo(2)
48 | assertThat(actual[0]).isEqualTo(output1)
49 | assertThat(actual[1]).isEqualTo(output2)
50 | }
51 | }
--------------------------------------------------------------------------------
/app/src/test/java/com/denisbrandi/functionalmapping/data/oop/mapper/NullableOutputListMapperImplTest.kt:
--------------------------------------------------------------------------------
1 | package com.denisbrandi.functionalmapping.data.oop.mapper
2 |
3 | import com.google.common.truth.Truth.assertThat
4 | import com.nhaarman.mockitokotlin2.mock
5 | import com.nhaarman.mockitokotlin2.whenever
6 | import org.junit.Test
7 |
8 |
9 | class NullableOutputListMapperImplTest {
10 |
11 | private val input1: Any = mock()
12 | private val input2: Any = mock()
13 | private val output1: Any = mock()
14 | private val output2: Any = mock()
15 |
16 | private val mapper: Mapper = mock {
17 | whenever(it.map(input1)).thenReturn(output1)
18 | whenever(it.map(input2)).thenReturn(output2)
19 | }
20 | private val sut = NullableOutputListMapperImpl(mapper)
21 |
22 | @Test
23 | fun `map should return null list when input list is empty`() {
24 | val actual = sut.map(emptyList())
25 |
26 | assertThat(actual).isNull()
27 | }
28 |
29 | @Test
30 | fun `map should return mapped list when input list is 1`() {
31 | val actual = sut.map(listOf(input1))
32 |
33 | assertThat(actual!!.size).isEqualTo(1)
34 | assertThat(actual[0]).isEqualTo(output1)
35 | }
36 |
37 | @Test
38 | fun `map should return mapped list when input list is many`() {
39 | val actual = sut.map(listOf(input1, input2))
40 |
41 | assertThat(actual!!.size).isEqualTo(2)
42 | assertThat(actual[0]).isEqualTo(output1)
43 | assertThat(actual[1]).isEqualTo(output2)
44 | }
45 | }
--------------------------------------------------------------------------------
/app/src/test/java/com/denisbrandi/functionalmapping/data/oop/mapper/SongDataMapperTest.kt:
--------------------------------------------------------------------------------
1 | package com.denisbrandi.functionalmapping.data.oop.mapper
2 |
3 | import com.denisbrandi.functionalmapping.data.network.model.NetworkSong
4 | import com.google.common.truth.Truth.assertThat
5 | import org.junit.Test
6 |
7 | class SongDataMapperTest {
8 |
9 | private val sut = SongDataMapper()
10 |
11 | private fun makeNetworkSong(
12 | id: String? = null,
13 | name: String? = null,
14 | link: String? = null,
15 | duration: Long? = null,
16 | creationDate: String? = null,
17 | uploadDate: String? = null,
18 | authorFullName: String? = null
19 | ): NetworkSong {
20 | return NetworkSong(
21 | id,
22 | name,
23 | link,
24 | duration,
25 | creationDate,
26 | uploadDate,
27 | authorFullName
28 | )
29 | }
30 |
31 | @Test
32 | fun `map should replace null values with defaults`() {
33 | val dto = makeNetworkSong()
34 |
35 | val actual = sut.map(dto)
36 |
37 | assertThat(actual.id).isEmpty()
38 | assertThat(actual.name).isEmpty()
39 | assertThat(actual.link).isEmpty()
40 | assertThat(actual.duration).isEqualTo(0)
41 | assertThat(actual.metadata.authorFullName).isEmpty()
42 | assertThat(actual.metadata.creationDate).isEqualTo(Long.MIN_VALUE)
43 | assertThat(actual.metadata.uploadDate).isEqualTo(Long.MIN_VALUE)
44 | }
45 |
46 | @Test
47 | fun `map should replace assign and format correct values`() {
48 | val dto = makeNetworkSong(
49 | "id",
50 | "name",
51 | "link",
52 | 50L,
53 | "29 May 2015 05:50:06",
54 | "29 May 2015 05:50:06",
55 | "Name Surname"
56 | )
57 |
58 | val actual = sut.map(dto)
59 |
60 | assertThat(actual.id).isEqualTo("id")
61 | assertThat(actual.name).isEqualTo("name")
62 | assertThat(actual.link).isEqualTo("link")
63 | assertThat(actual.duration).isEqualTo(50)
64 | assertThat(actual.metadata.authorFullName).isEqualTo("Name Surname")
65 | assertThat(actual.metadata.creationDate).isEqualTo(1432875006000)
66 | assertThat(actual.metadata.uploadDate).isEqualTo(1432875006000)
67 | }
68 | }
--------------------------------------------------------------------------------
/app/src/test/java/com/denisbrandi/functionalmapping/data/oop/repository/AlbumRepositoryImplTest.kt:
--------------------------------------------------------------------------------
1 | package com.denisbrandi.functionalmapping.data.oop.repository
2 |
3 | import com.denisbrandi.functionalmapping.data.network.AlbumApiService
4 | import com.denisbrandi.functionalmapping.data.network.model.NetworkAlbum
5 | import com.denisbrandi.functionalmapping.data.oop.mapper.Mapper
6 | import com.denisbrandi.functionalmapping.domain.model.Album
7 | import com.denisbrandi.functionalmapping.domain.model.Result
8 | import com.nhaarman.mockitokotlin2.mock
9 | import com.nhaarman.mockitokotlin2.whenever
10 | import io.reactivex.Single
11 | import org.junit.Test
12 |
13 | class AlbumRepositoryImplTest {
14 |
15 | private val albumApiService: AlbumApiService = mock()
16 | private val albumDataMapper: Mapper = mock()
17 | private val sut = AlbumRepositoryImpl(albumApiService, albumDataMapper)
18 |
19 | @Test
20 | fun `getAlbumById should return album when apiService call is successful`() {
21 | val networkAlbum = NetworkAlbum(null, null, emptyList())
22 | val album = Album("", "", emptyList())
23 | whenever(albumApiService.getAlbumById(ALBUM_ID))
24 | .thenReturn(Single.just(Result.Success(networkAlbum)))
25 | whenever(albumDataMapper.map(networkAlbum)).thenReturn(album)
26 |
27 | val testObserver = sut.getAlbumById(ALBUM_ID).test()
28 |
29 | testObserver.assertValue(Result.Success(album))
30 | }
31 |
32 | @Test
33 | fun `getAlbumById should return unmapped Failure when apiService call is not successful`() {
34 | val throwable = Throwable()
35 | whenever(albumApiService.getAlbumById(ALBUM_ID))
36 | .thenReturn(Single.just(Result.Failure(throwable)))
37 |
38 | val testObserver = sut.getAlbumById(ALBUM_ID).test()
39 |
40 | testObserver.assertValue(Result.Failure(throwable))
41 | }
42 |
43 | private companion object {
44 | const val ALBUM_ID = "id"
45 | }
46 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | ext.kotlin_version = '1.3.50'
5 | repositories {
6 | google()
7 | jcenter()
8 |
9 | }
10 | dependencies {
11 | classpath 'com.android.tools.build:gradle:3.5.3'
12 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | google()
21 | jcenter()
22 |
23 | }
24 | }
25 |
26 | task clean(type: Delete) {
27 | delete rootProject.buildDir
28 | }
29 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 | # Kotlin code style for this project: "official" or "obsolete":
21 | kotlin.code.style=official
22 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DenisBronx/FunctionalMapping/ce9b00b349bc0f2277bbacb599255506c5141e32/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Apr 15 22:20:48 BST 2020
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 | rootProject.name='MediumArticles'
3 |
--------------------------------------------------------------------------------