From 9fffc7a781d67953f64bfc5870a0cba698546b47 Mon Sep 17 00:00:00 2001 From: Kevin Boulongne Date: Fri, 3 May 2024 14:26:50 +0200 Subject: [PATCH] WIP: Add tests --- .../com/infomaniak/lib/core/ExtensionsTest.kt | 41 +++++++++++++++++++ .../com/infomaniak/lib/core/HttpUtilsTest.kt | 3 +- 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 src/androidTest/java/com/infomaniak/lib/core/ExtensionsTest.kt diff --git a/src/androidTest/java/com/infomaniak/lib/core/ExtensionsTest.kt b/src/androidTest/java/com/infomaniak/lib/core/ExtensionsTest.kt new file mode 100644 index 00000000..8e8a4dad --- /dev/null +++ b/src/androidTest/java/com/infomaniak/lib/core/ExtensionsTest.kt @@ -0,0 +1,41 @@ +package com.infomaniak.lib.core + +import android.content.Context +import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.infomaniak.lib.core.utils.humanReadableBinaryBytesCount +import org.junit.Assert +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.Mock +import org.mockito.Mockito.mock +import org.mockito.Mockito.`when` +import org.mockito.MockitoAnnotations + +/** + * Extensions file test + */ +@RunWith(AndroidJUnit4::class) +class ExtensionsTest { + + @Mock + lateinit var mockContext: Context + + @Before + fun setup() { + MockitoAnnotations.initMocks(this) + mockContext = mock(Context::class.java) + `when`(mockContext.applicationContext).thenReturn(mockContext) + } + + @Test + fun humanReadableBinaryBytesCount() { + // Arrange (already in setup) + + // Act + val result = mockContext.humanReadableBinaryBytesCount(1_500L) + + // Assert + Assert.assertEquals(result, "1.5 KB") + } +} diff --git a/src/androidTest/java/com/infomaniak/lib/core/HttpUtilsTest.kt b/src/androidTest/java/com/infomaniak/lib/core/HttpUtilsTest.kt index f17cd938..1d4ee796 100644 --- a/src/androidTest/java/com/infomaniak/lib/core/HttpUtilsTest.kt +++ b/src/androidTest/java/com/infomaniak/lib/core/HttpUtilsTest.kt @@ -23,6 +23,7 @@ import org.mockito.MockitoAnnotations */ @RunWith(AndroidJUnit4::class) class HttpUtilsTest { + @Mock lateinit var mockContext: Context @@ -63,7 +64,7 @@ class HttpUtilsTest { @Test fun getHeaders_Test() { - // Arrange (Already in setup) + // Arrange (already in setup) // Act val headers: Headers = HttpUtils.getHeaders()