-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix deprecated logging functions (#824)
- Loading branch information
Showing
3 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
codyze-core/src/test/kotlin/de/fraunhofer/aisec/codyze/core/VersionProviderTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (c) 2024, Fraunhofer AISEC. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package de.fraunhofer.aisec.codyze.core | ||
|
||
import org.junit.jupiter.api.Test | ||
import java.io.FileOutputStream | ||
import java.util.Properties | ||
import kotlin.test.assertEquals | ||
|
||
class VersionProviderTest { | ||
|
||
@Test | ||
fun `test initialisation from properties file with incorrect project name`() { | ||
val properties = Properties() | ||
|
||
/* get the property file and load it; we want to fail if we can't find the property file to begin with */ | ||
val propFile = VersionProvider::class.java.classLoader.getResource("codyze.properties")!! | ||
propFile.openStream().use { | ||
properties.load(it) | ||
} | ||
|
||
// change property s.t. internal check fails | ||
val oldValue = properties.setProperty("project.name", "test") as String | ||
FileOutputStream(propFile.file).use { | ||
properties.store(it, null) | ||
} | ||
|
||
// instantiate `VersionProvider` with altered properties -> properties in VersionProvider should now be empty | ||
val vp = VersionProvider | ||
|
||
// check empty properties through reflection | ||
val vpProps = vp.javaClass.getDeclaredField("props") | ||
.also { it.trySetAccessible() } | ||
.let { it.get(vp) as Properties } | ||
assertEquals(vpProps.size, 0) | ||
|
||
// restore original properties file | ||
properties.setProperty("project.name", oldValue) | ||
FileOutputStream(propFile.file).use { | ||
properties.store(it, null) | ||
} | ||
} | ||
} |