-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adapt timeseries tests to avoid mockito on ByteBuffer failing on java19
We get an exception: org.mockito.exceptions.base.MockitoException: Mockito cannot mock this class: class java.nio.ByteBuffer. Try to use java.nio APIs to use no resources (sparse, private), not sure how this works on all platforms.. Signed-off-by: HARPER Jon <jon.harper87@gmail.com>
- Loading branch information
Showing
3 changed files
with
74 additions
and
83 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
time-series/time-series-api/src/test/java/com/powsybl/timeseries/AbstractBigBufferTest.java
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,58 @@ | ||
/** | ||
* Copyright (c) 2023, RTE (http://www.rte-france.com) | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
package com.powsybl.timeseries; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.AfterEach; | ||
|
||
import java.nio.file.StandardOpenOption; | ||
import java.nio.channels.FileChannel; | ||
import java.nio.ByteBuffer; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
||
import java.util.List; | ||
import java.util.ArrayList; | ||
|
||
/** | ||
* @author Jon Harper <jon.harper at rte-france.com> | ||
*/ | ||
abstract class AbstractBigBufferTest { | ||
|
||
private Path tempdir; | ||
protected List<FileChannel> channels; | ||
|
||
protected ByteBuffer testAllocator(int capacity) { | ||
try { | ||
FileChannel channel = FileChannel.open( | ||
tempdir.resolve(Integer.toString(channels.size())), | ||
StandardOpenOption.READ, StandardOpenOption.WRITE, | ||
StandardOpenOption.CREATE_NEW, StandardOpenOption.SPARSE, | ||
StandardOpenOption.DELETE_ON_CLOSE); | ||
channels.add(channel); | ||
ByteBuffer bytebuffer = channel.map(FileChannel.MapMode.PRIVATE, 0, capacity); | ||
return bytebuffer; | ||
} catch (Exception e) { | ||
throw new RuntimeException("error in allocator test", e); | ||
} | ||
} | ||
|
||
@BeforeEach | ||
void before() throws Exception { | ||
tempdir = Files.createTempDirectory("powsybltimeseriestest"); | ||
channels = new ArrayList<>(); | ||
} | ||
|
||
@AfterEach | ||
void after() throws Exception { | ||
for (FileChannel channel : channels) { | ||
channel.close(); | ||
} | ||
Files.delete(tempdir); | ||
} | ||
|
||
} |
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