Skip to content

Commit 1328e32

Browse files
authored
Merge pull request #3 from VMadalin/mv/add-tests-coverage
Add test coverage for :commons:ui and :core modules
2 parents 8e311bb + f3e5e94 commit 1328e32

File tree

11 files changed

+472
-30
lines changed

11 files changed

+472
-30
lines changed

.detekt/config.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@ comments:
4242
active: false
4343
endOfSentenceFormat: ([.?!][ \t\n\r\f<])|([.?!:]$)
4444
UndocumentedPublicClass:
45-
active: false
45+
active: true
46+
excludes: "**/test_utils/**"
4647
searchInNestedClass: true
4748
searchInInnerClass: true
4849
searchInInnerObject: true
4950
searchInInnerInterface: true
5051
UndocumentedPublicFunction:
51-
active: false
52+
active: true
53+
excludes: "**/test_utils/**"
5254
UndocumentedPublicProperty:
5355
active: false
5456

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ The architecture of the application is based, apply and strictly complies with e
110110
<img src="screenshots/architecture/project_structure.png" width="300" align="right" hspace="20">
111111

112112
- A single-activity architecture, using the [Navigation component](https://developer.android.com/guide/navigation/navigation-getting-started) to manage fragment operations.
113-
- [Android architecture components](https://developer.android.com/topic/libraries/architecture/), part of Android Jetpack for give to project a robust design, testable and maintainable.
113+
- [Android architecture components](https://developer.android.com/topic/libraries/architecture/), part of Android Jetpack for give to project a robust design, testable and maintainable.
114114
- Pattern [Model-View-ViewModel](https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93viewmodel) (MVVM) facilitating a [separation](https://en.wikipedia.org/wiki/Separation_of_concerns) of development of the graphical user interface.
115115
- [S.O.L.I.D](https://en.wikipedia.org/wiki/SOLID) design principles intended to make software designs more understandable, flexible and maintainable.
116116
- [Modular app architecture](https://proandroiddev.com/build-a-modular-android-app-architecture-25342d99de82) allows to be developed features in isolation, independently from other features.
@@ -139,7 +139,7 @@ The `:core` module is an [com.android.library](https://developer.android.com/st
139139

140140
#### Features modules
141141

142-
The `:features` module are an [com.android.dynamic-feature](https://developer.android.com/studio/projects/dynamic-delivery) is essentially a gradle module which can be downloaded independently from the base application module. It can hold code and resources and include dependencies, just like any other gradle module.
142+
The `:features` module are an [com.android.dynamic-feature](https://developer.android.com/studio/projects/dynamic-delivery) is essentially a gradle module which can be downloaded independently from the base application module. It can hold code and resources and include dependencies, just like any other gradle module.
143143

144144
#### Commons modules
145145

commons/ui/src/main/kotlin/com/vmadalin/commons/ui/base/BaseFragment.kt

+7
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,14 @@ abstract class BaseFragment<B : ViewDataBinding, M : ViewModel>(
4444
lateinit var viewModel: M
4545
lateinit var viewBinding: B
4646

47+
/**
48+
* Called to initialize dagger injection dependency graph when fragment is attached.
49+
*/
4750
abstract fun onInitDependencyInjection()
51+
52+
/**
53+
* Called to Initialize view data binding variables when fragment view is created.
54+
*/
4855
abstract fun onInitDataBinding()
4956

5057
/**

commons/ui/src/main/kotlin/com/vmadalin/commons/ui/recyclerview/RecyclerViewItemDecoration.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import androidx.annotation.VisibleForTesting.PRIVATE
2323
import androidx.recyclerview.widget.GridLayoutManager
2424
import androidx.recyclerview.widget.LinearLayoutManager
2525
import androidx.recyclerview.widget.RecyclerView
26+
import kotlin.math.ceil
2627

2728
/**
2829
* Simple item decoration allows the application to add a special drawing and layout offset
@@ -85,7 +86,7 @@ class RecyclerViewItemDecoration(
8586
itemCount: Int
8687
) {
8788
val cols = layoutManager.spanCount
88-
val rows = if (itemCount % 2 == 0) itemCount / cols else itemCount / cols + 1
89+
val rows = ceil(itemCount / cols.toDouble()).toInt()
8990

9091
outRect.top = spacingPx
9192
outRect.left = spacingPx
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2019 vmadalin.com
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.vmadalin.commons.ui.extensions
18+
19+
import android.content.Context
20+
import io.mockk.MockKAnnotations
21+
import io.mockk.every
22+
import io.mockk.impl.annotations.MockK
23+
import org.junit.Assert.assertEquals
24+
import org.junit.Before
25+
import org.junit.Test
26+
27+
class ContextExtensionsTest {
28+
29+
@MockK(relaxed = true)
30+
lateinit var context: Context
31+
32+
@Before
33+
fun setUp() {
34+
MockKAnnotations.init(this)
35+
}
36+
37+
@Test
38+
fun getString_WhenIdIsNonNull_ReturnResource() {
39+
val resId = 0
40+
val expectedString = "test"
41+
42+
every { context.getString(any()) } returns expectedString
43+
44+
assertEquals(expectedString, context.getString(resId))
45+
}
46+
47+
@Test
48+
fun getString_WhenIdIsNull_ReturnEmpty() {
49+
val resId = null
50+
val expectedString = ""
51+
52+
assertEquals(expectedString, context.getString(resId))
53+
}
54+
}

0 commit comments

Comments
 (0)