aboutsummaryrefslogtreecommitdiffstats
path: root/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/RoutingPolicyRepositoryTest.java
blob: 71bec84f82b4c84ae02e74e535af701e135e3b2e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.documentapi.messagebus.protocol;

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class RoutingPolicyRepositoryTest {

    @Test
    public void policy_creation_does_not_swallow_exception() {
        final RoutingPolicyRepository repo = new RoutingPolicyRepository();
        final RoutingPolicyFactory factory = mock(RoutingPolicyFactory.class);

        when(factory.createPolicy(anyString())).thenThrow(new IllegalArgumentException("oh no!"));
        repo.putFactory("foo", factory);

        try {
            repo.createPolicy("foo", "bar");
            fail();
        } catch (IllegalArgumentException e) {
            assertEquals("oh no!", e.getMessage());
        }
    }

}