mirror of
https://github.com/HMCore/Orbot.git
synced 2025-12-10 21:06:18 +00:00
Add file tests
This commit is contained in:
45
.idea/workspace.xml
generated
45
.idea/workspace.xml
generated
@@ -4,14 +4,9 @@
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="1aabf22b-2f57-46ac-9973-367d8668ffd3" name="Default Changelist" comment="Refactoring, Tests">
|
||||
<change afterPath="$PROJECT_DIR$/src/test/kotlin/org/hmcore/model/BlogPostPreviewTest.kt" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/test/kotlin/org/hmcore/model/JobListingPreviewTest.kt" afterDir="false" />
|
||||
<list default="true" id="1aabf22b-2f57-46ac-9973-367d8668ffd3" name="Default Changelist" comment="Add more tests">
|
||||
<change afterPath="$PROJECT_DIR$/src/test/kotlin/org/hmcore/extensions/FileTest.kt" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/kotlin/org/hmcore/extensions/Embed.kt" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/kotlin/org/hmcore/extensions/Embed.kt" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/kotlin/org/hmcore/model/BlogPostPreview.kt" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/kotlin/org/hmcore/model/BlogPostPreview.kt" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/kotlin/org/hmcore/model/JobListingPreview.kt" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/kotlin/org/hmcore/model/JobListingPreview.kt" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/test/kotlin/org/hmcore/extensions/EmbedTest.kt" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/kotlin/org/hmcore/extensions/EmbedTest.kt" afterDir="false" />
|
||||
</list>
|
||||
<list id="44283a45-f406-407f-bce2-a31bb9bfc0cc" name="Changes by Valentin" comment="Changes by Valentin" />
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
@@ -237,44 +232,44 @@
|
||||
<DebugAllEnabled>false</DebugAllEnabled>
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
<configuration name="HytaleUpdateBot [build]" type="GradleRunConfiguration" factoryName="Gradle" temporary="true">
|
||||
<configuration name="FileTest" type="GradleRunConfiguration" factoryName="Gradle" temporary="true">
|
||||
<ExternalSystemSettings>
|
||||
<option name="executionName" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="externalSystemIdString" value="GRADLE" />
|
||||
<option name="scriptParameters" />
|
||||
<option name="scriptParameters" value="--tests "org.hmcore.extensions.FileTest"" />
|
||||
<option name="taskDescriptions">
|
||||
<list />
|
||||
</option>
|
||||
<option name="taskNames">
|
||||
<list>
|
||||
<option value="build" />
|
||||
<option value=":test" />
|
||||
</list>
|
||||
</option>
|
||||
<option name="vmOptions" />
|
||||
</ExternalSystemSettings>
|
||||
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
|
||||
<ExternalSystemDebugServerProcess>false</ExternalSystemDebugServerProcess>
|
||||
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
|
||||
<DebugAllEnabled>false</DebugAllEnabled>
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
<configuration name="HytaleUpdateBot [fatJar]" type="GradleRunConfiguration" factoryName="Gradle" temporary="true">
|
||||
<configuration name="FileTest.Ensure exists should create a file if supplied with null but not write text" type="GradleRunConfiguration" factoryName="Gradle" temporary="true">
|
||||
<ExternalSystemSettings>
|
||||
<option name="executionName" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="externalSystemIdString" value="GRADLE" />
|
||||
<option name="scriptParameters" />
|
||||
<option name="scriptParameters" value="--tests "org.hmcore.extensions.FileTest.Ensure exists should create a file if supplied with null but not write text"" />
|
||||
<option name="taskDescriptions">
|
||||
<list />
|
||||
</option>
|
||||
<option name="taskNames">
|
||||
<list>
|
||||
<option value="fatJar" />
|
||||
<option value=":test" />
|
||||
</list>
|
||||
</option>
|
||||
<option name="vmOptions" />
|
||||
</ExternalSystemSettings>
|
||||
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
|
||||
<ExternalSystemDebugServerProcess>false</ExternalSystemDebugServerProcess>
|
||||
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
|
||||
<DebugAllEnabled>false</DebugAllEnabled>
|
||||
<method v="2" />
|
||||
@@ -299,18 +294,18 @@
|
||||
<list>
|
||||
<item itemvalue="Gradle.ColorTest" />
|
||||
<item itemvalue="Gradle.EmbedTest" />
|
||||
<item itemvalue="Gradle.HytaleUpdateBot [build]" />
|
||||
<item itemvalue="Gradle.HytaleUpdateBot [fatJar]" />
|
||||
<item itemvalue="JUnit.All Tests" />
|
||||
<item itemvalue="Kotlin.Main" />
|
||||
<item itemvalue="Gradle.FileTest" />
|
||||
<item itemvalue="Gradle.FileTest.Ensure exists should create a file if supplied with null but not write text" />
|
||||
</list>
|
||||
<recent_temporary>
|
||||
<list>
|
||||
<item itemvalue="Gradle.FileTest.Ensure exists should create a file if supplied with null but not write text" />
|
||||
<item itemvalue="Gradle.FileTest" />
|
||||
<item itemvalue="Gradle.EmbedTest" />
|
||||
<item itemvalue="Gradle.ColorTest" />
|
||||
<item itemvalue="Kotlin.Main" />
|
||||
<item itemvalue="Gradle.HytaleUpdateBot [fatJar]" />
|
||||
<item itemvalue="Gradle.HytaleUpdateBot [build]" />
|
||||
</list>
|
||||
</recent_temporary>
|
||||
</component>
|
||||
@@ -439,7 +434,14 @@
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1622283383268</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="17" />
|
||||
<task id="LOCAL-00017" summary="Add more tests">
|
||||
<created>1622284601372</created>
|
||||
<option name="number" value="00017" />
|
||||
<option name="presentableId" value="LOCAL-00017" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1622284601372</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="18" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
@@ -472,7 +474,8 @@
|
||||
<MESSAGE value="Bug fixes" />
|
||||
<MESSAGE value="Changes by Valentin" />
|
||||
<MESSAGE value="Refactoring, Tests" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="Refactoring, Tests" />
|
||||
<MESSAGE value="Add more tests" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="Add more tests" />
|
||||
</component>
|
||||
<component name="XDebuggerManager">
|
||||
<watches-manager>
|
||||
|
||||
73
src/test/kotlin/org/hmcore/extensions/FileTest.kt
Normal file
73
src/test/kotlin/org/hmcore/extensions/FileTest.kt
Normal file
@@ -0,0 +1,73 @@
|
||||
package org.hmcore.extensions
|
||||
|
||||
import io.mockk.*
|
||||
import java.io.File
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class FileTest {
|
||||
@Test
|
||||
fun `Ensure exists should create a file with default content if it does not exist`() {
|
||||
val file = mockk<File>()
|
||||
mockkStatic("kotlin.io.FilesKt__FileReadWriteKt")
|
||||
|
||||
every { file.exists() } returns false
|
||||
every { file.createNewFile() } returns true
|
||||
every { file.writeText(any()) } just Runs
|
||||
|
||||
file.ensureExists("Default Text")
|
||||
|
||||
verifySequence {
|
||||
file.exists()
|
||||
file.createNewFile()
|
||||
file.writeText("Default Text")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Ensure exists should create a file if supplied with null but not write text`() {
|
||||
val file = mockk<File>()
|
||||
mockkStatic("kotlin.io.FilesKt__FileReadWriteKt")
|
||||
|
||||
every { file.exists() } returns false
|
||||
every { file.createNewFile() } returns true
|
||||
every { file.writeText(any()) } just Runs
|
||||
|
||||
file.ensureExists(null)
|
||||
|
||||
verifySequence {
|
||||
file.exists()
|
||||
file.createNewFile()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Ensure exists should not touch the file if it exists`() {
|
||||
val file = mockk<File>()
|
||||
mockkStatic("kotlin.io.FilesKt__FileReadWriteKt")
|
||||
|
||||
every { file.exists() } returns true
|
||||
every { file.createNewFile() } returns true
|
||||
every { file.writeText(any()) } just Runs
|
||||
|
||||
file.ensureExists(null)
|
||||
|
||||
verifySequence {
|
||||
file.exists()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Ensure exists should return itself`() {
|
||||
val file = mockk<File>()
|
||||
mockkStatic("kotlin.io.FilesKt__FileReadWriteKt")
|
||||
|
||||
every { file.exists() } returns true
|
||||
every { file.createNewFile() } returns true
|
||||
every { file.writeText(any()) } just Runs
|
||||
|
||||
val f2 = file.ensureExists(null)
|
||||
|
||||
assertEquals(file, f2)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user