// Path: src/test/java/org/simplify4u/plugins/TestArtifactBuilder.java
// public static TestArtifactBuilder testArtifact() {
//     return new TestArtifactBuilder();
// }
// 
// Path: src/test/java/org/simplify4u/plugins/TestUtils.java
// public static KeyInfo aKeyInfo(String fingerprint) {
//     return KeyInfo.builder().fingerprint(new KeyFingerprint(fingerprint)).build();
// }
// 
// Path: src/test/java/org/simplify4u/plugins/TestUtils.java
// public static KeysMapLocationConfig aKeysMapLocationConfig(String location) {
//     KeysMapLocationConfig config = new KeysMapLocationConfig();
//     config.set(location);
//     return config;
// }


import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.simplify4u.plugins.TestArtifactBuilder.testArtifact;
import static org.simplify4u.plugins.TestUtils.aKeyInfo;
import static org.simplify4u.plugins.TestUtils.aKeysMapLocationConfig;
import org.codehaus.plexus.resource.ResourceManager;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.testng.MockitoTestNGListener;
import org.slf4j.Logger;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
    public void nullLocationTest() throws Exception {

        assertThatThrownBy(() -> keysMap.load(null))
                .isExactlyInstanceOf(NullPointerException.class);

        verifyNoInteractions(resourceManager);
        assertThat(keysMap.isValidKey(testArtifact().build(), null)).isTrue();
    }

    @Test
    public void emptyLocationTest() throws Exception {
        keysMap.load(aKeysMapLocationConfig(""));

        verifyNoInteractions(resourceManager);
        assertThat(keysMap.isValidKey(testArtifact().build(), null)).isTrue();
    }

    @Test
    public void validKeyFromMap() throws Exception {

        doAnswer(invocation -> getClass().getResourceAsStream(invocation.getArgument(0)))
                .when(resourceManager).getResourceAsInputStream(anyString());

        keysMap.load(aKeysMapLocationConfig("/keysMap.list"));

        verify(resourceManager).getResourceAsInputStream(anyString());

        assertThat(
                keysMap.isValidKey(
                        testArtifact().groupId("junit").artifactId("junit").version("4.12").build(),
// Path: src/test/java/org/simplify4u/plugins/TestArtifactBuilder.java
// public static TestArtifactBuilder testArtifact() {
//     return new TestArtifactBuilder();
// }
// 
// Path: src/test/java/org/simplify4u/plugins/TestUtils.java
// public static KeyInfo aKeyInfo(String fingerprint) {
//     return KeyInfo.builder().fingerprint(new KeyFingerprint(fingerprint)).build();
// }
// 
// Path: src/test/java/org/simplify4u/plugins/TestUtils.java
// public static KeysMapLocationConfig aKeysMapLocationConfig(String location) {
//     KeysMapLocationConfig config = new KeysMapLocationConfig();
//     config.set(location);
//     return config;
// }


// Path: src/test/java/org/simplify4u/plugins/keysmap/KeysMapTest.java
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.simplify4u.plugins.TestArtifactBuilder.testArtifact;
import static org.simplify4u.plugins.TestUtils.aKeyInfo;
import static org.simplify4u.plugins.TestUtils.aKeysMapLocationConfig;
import org.codehaus.plexus.resource.ResourceManager;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.testng.MockitoTestNGListener;
import org.slf4j.Logger;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;

    public void nullLocationTest() throws Exception {

        assertThatThrownBy(() -> keysMap.load(null))
                .isExactlyInstanceOf(NullPointerException.class);

        verifyNoInteractions(resourceManager);
        assertThat(keysMap.isValidKey(testArtifact().build(), null)).isTrue();
    }

    @Test
    public void emptyLocationTest() throws Exception {
        keysMap.load(aKeysMapLocationConfig(""));

        verifyNoInteractions(resourceManager);
        assertThat(keysMap.isValidKey(testArtifact().build(), null)).isTrue();
    }

    @Test
    public void validKeyFromMap() throws Exception {

        doAnswer(invocation -> getClass().getResourceAsStream(invocation.getArgument(0)))
                .when(resourceManager).getResourceAsInputStream(anyString());

        keysMap.load(aKeysMapLocationConfig("/keysMap.list"));

        verify(resourceManager).getResourceAsInputStream(anyString());

        assertThat(
                keysMap.isValidKey(
                        testArtifact().groupId("junit").artifactId("junit").version("4.12").build(),
                        aKeyInfo("0x123456789abcdef0"))