-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
346 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
58 changes: 58 additions & 0 deletions
58
spi-test-support/src/test/java/hosh/spi/test/support/ExitStatusAssertTest.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 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2018-2023 Davide Angelocola | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package hosh.spi.test.support; | ||
|
||
import hosh.spi.ExitStatus; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static hosh.spi.test.support.ExitStatusAssert.assertThat; | ||
|
||
@SuppressWarnings("MaskedAssertion") | ||
class ExitStatusAssertTest { | ||
|
||
@Test | ||
void error() { | ||
ExitStatus exitStatus = ExitStatus.of(1); | ||
assertThat(exitStatus).isError(); | ||
assertThat(exitStatus).hasExitCode(1); | ||
try { | ||
assertThat(exitStatus).isSuccess(); | ||
} catch (AssertionError e) { | ||
// all good | ||
} | ||
} | ||
|
||
@Test | ||
void success() { | ||
ExitStatus exitStatus = ExitStatus.of(0); | ||
assertThat(exitStatus).isSuccess(); | ||
assertThat(exitStatus).hasExitCode(0); | ||
try { | ||
assertThat(exitStatus).isError(); | ||
} catch (AssertionError e) { | ||
// all good | ||
} | ||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
spi-test-support/src/test/java/hosh/spi/test/support/RecordMatcherTest.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,54 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2018-2023 Davide Angelocola | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package hosh.spi.test.support; | ||
|
||
import hosh.spi.Keys; | ||
import hosh.spi.Record; | ||
import hosh.spi.Records; | ||
import hosh.spi.Values; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class RecordMatcherTest { | ||
|
||
@Test | ||
void usage() { | ||
RecordMatcher sut = new RecordMatcher(List.of(new Record.Entry(Keys.NAME, Values.ofText("mario")))); | ||
|
||
Record empty = Records.empty(); | ||
assertThat(sut.matches(empty)).isFalse(); | ||
|
||
Record mario = empty.append(Keys.NAME, Values.ofText("mario")); | ||
assertThat(sut.matches(mario)).isTrue(); | ||
|
||
Record marioAndCount = mario.append(Keys.COUNT, Values.ofNumeric(42)); | ||
assertThat(sut.matches(marioAndCount)).isTrue(); // still true, as the required key/value is still there | ||
|
||
Record luigi = empty.append(Keys.NAME, Values.ofText("luigi")); | ||
assertThat(sut.matches(luigi)).isFalse(); // not matching the required key/value (mario) | ||
} | ||
} |
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
73 changes: 73 additions & 0 deletions
73
test-support/src/test/java/hosh/test/support/TemporaryFolderTest.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,73 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2018-2023 Davide Angelocola | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package hosh.test.support; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class TemporaryFolderTest { | ||
|
||
@RegisterExtension | ||
final TemporaryFolder temporaryFolder = new TemporaryFolder(); | ||
|
||
@Test | ||
void usage() throws IOException { | ||
// must always provide a good base directory | ||
assertThat(temporaryFolder.toPath()) | ||
.isNotNull() | ||
.exists() | ||
.isDirectory() | ||
; | ||
|
||
// create a new directory | ||
assertThat(temporaryFolder.newFolder("folder")) | ||
.isNotNull() | ||
.exists() | ||
.isDirectory() | ||
; | ||
|
||
// create a new file | ||
assertThat(temporaryFolder.newFile("file.txt")) | ||
.isNotNull() | ||
.exists() | ||
.isEmptyFile() | ||
; | ||
|
||
// create a new file under a new directory | ||
assertThat(temporaryFolder.newFile(temporaryFolder.newFolder("sub-folder"), "file.txt")) | ||
.isNotNull() | ||
.exists() | ||
.isEmptyFile() | ||
; | ||
|
||
// cleanup | ||
temporaryFolder.afterEach(null); | ||
assertThat(temporaryFolder.toPath()).doesNotExist(); | ||
} | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
test-support/src/test/java/hosh/test/support/WithExecutorTest.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,55 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2018-2023 Davide Angelocola | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package hosh.test.support; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import java.util.concurrent.ExecutorService; | ||
|
||
import static org.mockito.BDDMockito.then; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class WithExecutorTest { | ||
|
||
@Mock | ||
ExecutorService executorService; | ||
|
||
@Test | ||
void usage() { | ||
WithExecutor sut = new WithExecutor(executorService); | ||
|
||
// submit task | ||
Runnable runnable = () -> System.out.println("test"); | ||
sut.submit(runnable); | ||
then(executorService).should().submit(runnable); | ||
|
||
// close after usage | ||
sut.afterAll(null); | ||
then(executorService).should().shutdown(); | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
test-support/src/test/java/hosh/test/support/WithThreadTest.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,48 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2018-2023 Davide Angelocola | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package hosh.test.support; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class WithThreadTest { | ||
|
||
@RegisterExtension | ||
final WithThread withThread = new WithThread(); | ||
|
||
@Test | ||
void threadName() { | ||
withThread.renameTo("super mario"); | ||
assertThat(withThread.currentName()).isEqualTo("super mario"); | ||
} | ||
|
||
@Test | ||
void interrupt() { | ||
assertThat(withThread.isInterrupted()).isEqualTo(false); | ||
withThread.interrupt(); | ||
assertThat(withThread.isInterrupted()).isEqualTo(true); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
test-support/src/test/java/hosh/test/support/WithTimeZoneTest.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,48 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2018-2023 Davide Angelocola | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package hosh.test.support; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import java.util.TimeZone; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class WithTimeZoneTest { | ||
|
||
@RegisterExtension | ||
final WithTimeZone withTimeZone = new WithTimeZone(); | ||
|
||
@Test | ||
void lifeCycle() { | ||
TimeZone zurich = TimeZone.getTimeZone("Europe/Zurich"); | ||
withTimeZone.changeTo(zurich); | ||
assertThat(TimeZone.getDefault()).isEqualTo(zurich); | ||
|
||
TimeZone utc = TimeZone.getTimeZone("UTC"); | ||
withTimeZone.changeTo(utc); | ||
assertThat(TimeZone.getDefault()).isEqualTo(utc); | ||
} | ||
} |