Skip to content

Commit

Permalink
[Core] Fix test for Java >= 17
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrobin committed Oct 17, 2024
1 parent f3e7c17 commit 17f0070
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
6 changes: 5 additions & 1 deletion sensorhub-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ dependencies {

testImplementation project(path: ':sensorml-core', configuration: 'testArtifacts')
testImplementation 'commons-io:commons-io:1.3.2'
testImplementation 'com.github.stefanbirkner:system-rules:1.19.0'
}

test {
environment 'SimpleEnvironment', 'value2'
environment 'DuplicateKey', 'value4'
}

// add info to OSGI manifest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,25 @@

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.EnvironmentVariables;

/**
* Various tests to ensure the functionality of the {@link ModuleUtils#expand(String)} and
* {@link ModuleUtils#expand(String, boolean)} methods.
*
* <p>
* The following environment variables must be set for all tests to succeed:<br/>
* - SimpleEnvironment: value2<br/>
* - DuplicateKey: value4<br/>
* </p>
*/
public class TestVariableExpansion {
/**
* Helper that allows us to set environment variables for testing (since there is no System.setenv).
*/
@Rule
public final EnvironmentVariables environmentVariables = new EnvironmentVariables();
// environmentVariables.set() not working on JDK>=17 due to illegal reflective to private module
//@Rule
//public final EnvironmentVariables environmentVariables = new EnvironmentVariables();

/**
* Temporary file that is used to test the functionality of the "${file; ... }" expansion.
Expand All @@ -43,10 +48,11 @@ public class TestVariableExpansion {
@Before
public void setup() throws IOException {
System.setProperty("SimpleProperty", "value1");
environmentVariables.set("SimpleEnvironment", "value2");

System.setProperty("DuplicateKey", "value3");
environmentVariables.set("DuplicateKey", "value4");

// The following doesn't work on JDK>=17. This is now set in build.gradle instead
//environmentVariables.set("SimpleEnvironment", "value2");
//environmentVariables.set("DuplicateKey", "value4");

tempFile = File.createTempFile("variable-expansion-test-", ".txt");
tempFilePath = tempFile.getAbsolutePath();
Expand Down

0 comments on commit 17f0070

Please sign in to comment.