Search in sources :

Example 1 with ThrowingSupplier

use of org.junit.jupiter.api.function.ThrowingSupplier in project Mal4J by KatsuteDev.

the class TestUser method testMangaAffinity.

@SuppressWarnings("SpellCheckingInspection")
@Test
final void testMangaAffinity() {
    final MangaAffinity affinity = user.getMangaAffinity("Xinil");
    annotateTest(() -> assertEquals(affinity.getShared().length, affinity.getSharedCount()));
    annotateTest(() -> assertDoesNotThrow((ThrowingSupplier<Float>) affinity::getAffinity));
}
Also used : MangaAffinity(com.kttdevelopment.mal4j.user.property.MangaAffinity) ThrowingSupplier(org.junit.jupiter.api.function.ThrowingSupplier) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with ThrowingSupplier

use of org.junit.jupiter.api.function.ThrowingSupplier in project JOSM_MapWIthAI_plugin by KaartGroup.

the class DataConflationSenderTest method testEmptyUrl.

@Test
void testEmptyUrl() {
    MapWithAIConflationCategoryMock.url = "";
    new MapWithAIConflationCategoryMock();
    final DataSet external = new DataSet(new Node(LatLon.NORTH_POLE));
    final DataSet openstreetmap = new DataSet(new Node(LatLon.ZERO));
    final DataConflationSender dataConflationSender = new DataConflationSender(MapWithAICategory.OTHER, openstreetmap, external);
    dataConflationSender.run();
    assertNull(assertDoesNotThrow((ThrowingSupplier<DataSet>) dataConflationSender::get));
}
Also used : DataSet(org.openstreetmap.josm.data.osm.DataSet) Node(org.openstreetmap.josm.data.osm.Node) ThrowingSupplier(org.junit.jupiter.api.function.ThrowingSupplier) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with ThrowingSupplier

use of org.junit.jupiter.api.function.ThrowingSupplier in project Mal4J by KatsuteDev.

the class TestUser method testAnimeAffinity.

@SuppressWarnings("SpellCheckingInspection")
@Test
final void testAnimeAffinity() {
    final AnimeAffinity affinity = user.getAnimeAffinity("Xinil");
    annotateTest(() -> assertEquals(affinity.getShared().length, affinity.getSharedCount()));
    annotateTest(() -> assertDoesNotThrow((ThrowingSupplier<Float>) affinity::getAffinity));
}
Also used : AnimeAffinity(com.kttdevelopment.mal4j.user.property.AnimeAffinity) ThrowingSupplier(org.junit.jupiter.api.function.ThrowingSupplier) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with ThrowingSupplier

use of org.junit.jupiter.api.function.ThrowingSupplier in project kogito-apps by kiegroup.

the class ExplanationServiceImplTest method testCounterfactualsExplainAsyncSuccess.

@SuppressWarnings("unchecked")
void testCounterfactualsExplainAsyncSuccess(ThrowingSupplier<BaseExplainabilityResult> invocation) {
    when(instance.stream()).thenReturn(Stream.of(cfExplainerServiceHandlerMock));
    when(cfExplainerMock.explainAsync(any(Prediction.class), eq(predictionProviderMock), any(Consumer.class))).thenReturn(CompletableFuture.completedFuture(COUNTERFACTUAL_RESULT));
    BaseExplainabilityResult result = assertDoesNotThrow(invocation);
    assertNotNull(result);
    assertTrue(result instanceof CounterfactualExplainabilityResult);
    CounterfactualExplainabilityResult counterfactualResult = (CounterfactualExplainabilityResult) result;
    assertEquals(EXECUTION_ID, counterfactualResult.getExecutionId());
    assertEquals(COUNTERFACTUAL_ID, counterfactualResult.getCounterfactualId());
    assertSame(ExplainabilityStatus.SUCCEEDED, counterfactualResult.getStatus());
    assertNull(counterfactualResult.getStatusDetails());
    assertEquals(COUNTERFACTUAL_RESULT.getEntities().size(), counterfactualResult.getInputs().size());
    assertEquals(COUNTERFACTUAL_RESULT.getOutput().size(), counterfactualResult.getOutputs().size());
    assertTrue(counterfactualResult.getOutputs().stream().anyMatch(o -> o.getName().equals("output1")));
    NamedTypedValue value = counterfactualResult.getOutputs().iterator().next();
    assertTrue(value.getValue().isUnit());
    assertEquals(Double.class.getSimpleName(), value.getValue().toUnit().getType());
    assertEquals(555.0, value.getValue().toUnit().getValue().asDouble());
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) SALIENCY_MAP(org.kie.kogito.explainability.TestUtils.SALIENCY_MAP) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) LIMEExplainabilityResult(org.kie.kogito.explainability.api.LIMEExplainabilityResult) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) LimeExplainerServiceHandler(org.kie.kogito.explainability.handlers.LimeExplainerServiceHandler) FeatureImportanceModel(org.kie.kogito.explainability.api.FeatureImportanceModel) COUNTERFACTUAL_ID(org.kie.kogito.explainability.TestUtils.COUNTERFACTUAL_ID) Prediction(org.kie.kogito.explainability.model.Prediction) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) CompletableFuture(java.util.concurrent.CompletableFuture) Mockito.spy(org.mockito.Mockito.spy) FEATURE_IMPORTANCE_1(org.kie.kogito.explainability.TestUtils.FEATURE_IMPORTANCE_1) Mockito.doThrow(org.mockito.Mockito.doThrow) CounterfactualExplainerServiceHandler(org.kie.kogito.explainability.handlers.CounterfactualExplainerServiceHandler) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) BaseExplainabilityResult(org.kie.kogito.explainability.api.BaseExplainabilityResult) SALIENCY(org.kie.kogito.explainability.TestUtils.SALIENCY) Instance(javax.enterprise.inject.Instance) LocalExplainerServiceHandlerRegistry(org.kie.kogito.explainability.handlers.LocalExplainerServiceHandlerRegistry) EXECUTION_ID(org.kie.kogito.explainability.TestUtils.EXECUTION_ID) NamedTypedValue(org.kie.kogito.explainability.api.NamedTypedValue) LimeExplainer(org.kie.kogito.explainability.local.lime.LimeExplainer) CounterfactualExplainer(org.kie.kogito.explainability.local.counterfactual.CounterfactualExplainer) ExplainabilityStatus(org.kie.kogito.explainability.api.ExplainabilityStatus) Mockito.when(org.mockito.Mockito.when) PredictionProvider(org.kie.kogito.explainability.model.PredictionProvider) Assertions.assertSame(org.junit.jupiter.api.Assertions.assertSame) COUNTERFACTUAL_RESULT(org.kie.kogito.explainability.TestUtils.COUNTERFACTUAL_RESULT) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) COUNTERFACTUAL_REQUEST(org.kie.kogito.explainability.TestUtils.COUNTERFACTUAL_REQUEST) LIME_REQUEST(org.kie.kogito.explainability.TestUtils.LIME_REQUEST) Stream(java.util.stream.Stream) ThrowingSupplier(org.junit.jupiter.api.function.ThrowingSupplier) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CounterfactualExplainabilityResult(org.kie.kogito.explainability.api.CounterfactualExplainabilityResult) SaliencyModel(org.kie.kogito.explainability.api.SaliencyModel) Assertions.assertDoesNotThrow(org.junit.jupiter.api.Assertions.assertDoesNotThrow) Mockito.mock(org.mockito.Mockito.mock) NamedTypedValue(org.kie.kogito.explainability.api.NamedTypedValue) Consumer(java.util.function.Consumer) BaseExplainabilityResult(org.kie.kogito.explainability.api.BaseExplainabilityResult) Prediction(org.kie.kogito.explainability.model.Prediction) CounterfactualExplainabilityResult(org.kie.kogito.explainability.api.CounterfactualExplainabilityResult)

Example 5 with ThrowingSupplier

use of org.junit.jupiter.api.function.ThrowingSupplier in project kolmafia by kolmafia.

the class StateCheckWrappersTest method postShutdownTest.

@Test
public void postShutdownTest() throws IllegalAccessException, InvocationTargetException {
    initialize(new InitializeParams());
    Assertions.assertDoesNotThrow((ThrowingSupplier<Object>) proxyServer.shutdown()::get, "Shutdown failed");
    testWithAllMethods((methodName, requestCaller) -> {
        // Post-shutdown requests should complete exceptionally with InvalidRequest
        ExecutionException error = Assertions.assertThrows(ExecutionException.class, requestCaller.get()::get, methodName);
        ResponseErrorException response = Assertions.assertInstanceOf(ResponseErrorException.class, error.getCause(), methodName);
        Assertions.assertEquals("Server was shut down", response.getMessage(), methodName);
        Assertions.assertEquals(ResponseErrorCode.InvalidRequest.getValue(), response.getResponseError().getCode(), methodName);
    }, (methodName, notificationRunner) -> {
        // Post-shutdown notifications should simply be ignored
        notificationRunner.run();
        pauser.pause(100);
        Assertions.assertTrue(ignoredNotification(), methodName);
    });
    // State-related methods
    // initialize(InitializeParams) acts like any other requests post-shutdown
    ExecutionException error = Assertions.assertThrows(ExecutionException.class, proxyServer.initialize(new InitializeParams())::get);
    ResponseErrorException response = Assertions.assertInstanceOf(ResponseErrorException.class, error.getCause());
    Assertions.assertEquals("Server was shut down", response.getMessage());
    Assertions.assertEquals(ResponseErrorCode.InvalidRequest.getValue(), response.getResponseError().getCode());
    // initialized(InitializedParams) acts like any other notification post-shutdown
    clearIgnoredNotification();
    proxyServer.initialized(new InitializedParams());
    pauser.pause(100);
    Assertions.assertTrue(ignoredNotification());
    // shutdown() acts like any other request post-shutdown
    error = Assertions.assertThrows(ExecutionException.class, proxyServer.shutdown()::get);
    response = Assertions.assertInstanceOf(ResponseErrorException.class, error.getCause());
    Assertions.assertEquals("Server was shut down", response.getMessage());
    Assertions.assertEquals(ResponseErrorCode.InvalidRequest.getValue(), response.getResponseError().getCode());
    // exit() is always accepted
    clearIgnoredNotification();
    proxyServer.exit();
    pauser.pause(100);
    Assertions.assertFalse(ignoredNotification());
    Assertions.assertTrue(trueServer.executor.isShutdown());
}
Also used : ResponseErrorException(org.eclipse.lsp4j.jsonrpc.ResponseErrorException) ThrowingSupplier(org.junit.jupiter.api.function.ThrowingSupplier) InitializeParams(org.eclipse.lsp4j.InitializeParams) ExecutionException(java.util.concurrent.ExecutionException) InitializedParams(org.eclipse.lsp4j.InitializedParams) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)5 ThrowingSupplier (org.junit.jupiter.api.function.ThrowingSupplier)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 AnimeAffinity (com.kttdevelopment.mal4j.user.property.AnimeAffinity)1 MangaAffinity (com.kttdevelopment.mal4j.user.property.MangaAffinity)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1 Consumer (java.util.function.Consumer)1 Stream (java.util.stream.Stream)1 Instance (javax.enterprise.inject.Instance)1 InitializeParams (org.eclipse.lsp4j.InitializeParams)1 InitializedParams (org.eclipse.lsp4j.InitializedParams)1 ResponseErrorException (org.eclipse.lsp4j.jsonrpc.ResponseErrorException)1 Assertions.assertDoesNotThrow (org.junit.jupiter.api.Assertions.assertDoesNotThrow)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)1 Assertions.assertNull (org.junit.jupiter.api.Assertions.assertNull)1 Assertions.assertSame (org.junit.jupiter.api.Assertions.assertSame)1 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)1 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)1