package com.currencycloud.client;


import com.currencycloud.client.exception.UnexpectedException;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;

public class CurrencyCloudClientOnBehalfOfTest {

    protected CurrencyCloudClient client = new CurrencyCloudClient("http://localhost:5555", null, null);

    @Test
    public void testSetsTheValueOnTheSessionAndRemovesItWhenDone() throws Exception {
        final String obo = "c6ece846-6df1-461d-acaa-b42a6aa74045";
        assertThat(client.getOnBehalfOf(), nullValue());
        client.onBehalfOfDo(obo, new Runnable() {
            @Override
            public void run() {
                assertThat(client.getOnBehalfOf(), equalTo(obo));
            }
        });
        assertThat(client.getOnBehalfOf(), nullValue());
    }

    @Test
    public void testStillRemovesTheValueFromTheSessionOnError() throws Exception {
        final String obo = "c6ece846-6df1-461d-acaa-b42a6aa74045";
        assertThat(client.getOnBehalfOf(), nullValue());
        try {
            client.onBehalfOfDo(obo, new Runnable() {
                @Override
                public void run() {
                    assertThat(client.getOnBehalfOf(), equalTo(obo));
                    throw new UnexpectedException("Completed Expected error");
                }
            });
        } catch (UnexpectedException ignore) { }
        assertThat(client.getOnBehalfOf(), nullValue());
    }

    @Test
    public void testPreventsReentrantUsage() throws Exception {
        final String obo = "c6ece846-6df1-461d-acaa-b42a6aa74045";
        assertThat(client.getOnBehalfOf(), nullValue());
        try {
            client.onBehalfOfDo(obo, new Runnable() {
                @Override
                public void run() {
                    client.onBehalfOfDo("f57b2d33-652c-4589-a8ff-7762add2706d", new Runnable() {
                        @Override public void run() {
                            throw new UnexpectedException("Should raise exception");
                        }
                    });
                }
            });
        } catch (IllegalStateException e) {
            assertThat(e.getMessage(), containsString("Can't nest on-behalf-of calls"));
        }
        assertThat(client.getOnBehalfOf(), nullValue());
    }

    @Test
    public void testPreventsIllegalIdFormat() throws Exception {
        assertThat(client.getOnBehalfOf(), nullValue());
        try {
            client.onBehalfOfDo("Richard Nienaber", new Runnable() {
                @Override
                public void run() {
                    throw new UnexpectedException("Should raise exception");
                }
            });
        } catch (IllegalArgumentException e) {
            assertThat(e.getMessage(), containsString("is not a UUID"));
        }
        assertThat(client.getOnBehalfOf(), nullValue());
    }
}
@@ -33,71 +33,8 @@
 ;%0A%0A%0A
-import com.currencycloud.client.exception.UnexpectedException;%0A
 impo
@@ -1229,34 +1229,31 @@
   throw new 
-Unexpected
+Runtime
 Exception(%22C
@@ -1334,37 +1334,114 @@
 ch (
-UnexpectedException ignore) %7B
+RuntimeException e) %7B%0A            assertThat(e.getMessage(), equalTo(%22Completed Expected error%22));%0A       
  %7D%0A 
@@ -2020,35 +2020,30 @@
 row new 
-UnexpectedException
+AssertionError
 (%22Should
@@ -2664,27 +2664,22 @@
 new 
-UnexpectedException
+AssertionError
 (%22Sh

Fix the test to more accurately test what it is meant to test.