Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions src/main/java/io/github/artemget/entrys/yaml/EYaml.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* MIT License
*
* Copyright (c) 2024-2025. Artem Getmanskii
*
* 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 io.github.artemget.entrys.yaml;

import io.github.artemget.entrys.ESafe;
import io.github.artemget.entrys.file.EVal;

/**
* By default gets entries from "src/main/resources/application.yaml".
*
* @since 0.4.0
*/
public class EYaml extends ESafe<String> {

/**
* From yaml file at default dir.
*
* @param key Of entry
*/
public EYaml(final String key) {
this(key, "src/main/resources/application.yaml");
}

/**
* From yaml file at custom dir.
*
* @param key Of entry
* @param path To yaml file
*/
public EYaml(final String key, final String path) {
super(
() -> new EVal(key, path).value()
);
}
}
28 changes: 28 additions & 0 deletions src/main/java/io/github/artemget/entrys/yaml/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* MIT License
*
* Copyright (c) 2024-2025. Artem Getmanskii
*
* 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.
*/

/**
* System entries directory.
*/
package io.github.artemget.entrys.yaml;
80 changes: 80 additions & 0 deletions src/test/java/io/github/artemget/entrys/yaml/EYamlTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* MIT License
*
* Copyright (c) 2024-2025. Artem Getmanskii
*
* 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 io.github.artemget.entrys.yaml;

import io.github.artemget.entrys.EntryException;
import io.github.artemget.entrys.file.EVal;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.MockedConstruction;
import org.mockito.Mockito;

/**
* Test cases for {@link io.github.artemget.entrys.yaml.EYaml}.
*
* @since 0.3.0
*/
@SuppressWarnings({"PMD.AvoidDuplicateLiterals", "PMD.TooManyMethods"})
final class EYamlTest {

@Test
void parsesWithDefaultPath() throws EntryException {
final MockedConstruction<EVal> mocked = Mockito.mockConstruction(
EVal.class,
(mock, context) -> Mockito.when(mock.value()).thenReturn("123")
);
Assertions.assertEquals(
"123",
new EYaml("age").value()
);
mocked.close();
}

@Test
void parsesWithCustomPath() throws EntryException {
final MockedConstruction<EVal> mocked = Mockito.mockConstruction(
EVal.class,
(mock, context) -> Mockito.when(mock.value()).thenReturn("12345")
);
Assertions.assertEquals(
"12345",
new EYaml("age", "configuration/application-test.yaml").value()
);
mocked.close();
}

@Test
void shouldThrowException() {
final MockedConstruction<EVal> mocked = Mockito.mockConstruction(
EVal.class,
(mock, context) -> Mockito.when(mock.value()).thenThrow(EntryException.class)
);
Assertions.assertThrows(
EntryException.class,
() -> new EYaml("age", "src/main/resources/application.yaml").value()
);
mocked.close();
}
}
28 changes: 28 additions & 0 deletions src/test/java/io/github/artemget/entrys/yaml/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* MIT License
*
* Copyright (c) 2024-2025. Artem Getmanskii
*
* 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.
*/

/**
* Test cases for system entries.
*/
package io.github.artemget.entrys.yaml;