001package edu.pdx.cs.joy.apptbookweb; 002 003import edu.pdx.cs.joy.ParserException; 004import edu.pdx.cs.joy.web.HttpRequestHelper; 005import org.junit.jupiter.api.Test; 006 007import java.io.IOException; 008import java.io.StringWriter; 009import java.util.Map; 010 011import static org.hamcrest.MatcherAssert.assertThat; 012import static org.hamcrest.Matchers.equalTo; 013import static org.mockito.ArgumentMatchers.eq; 014import static org.mockito.Mockito.mock; 015import static org.mockito.Mockito.when; 016 017public class AppointmentBookRestClientTest { 018 019 @Test 020 void getAllDictionaryEntriesPerformsHttpGetWithNoParameters() throws ParserException, IOException { 021 Map<String, String> dictionary = Map.of("One", "1", "Two", "2"); 022 023 HttpRequestHelper http = mock(HttpRequestHelper.class); 024 when(http.get(eq(Map.of()))).thenReturn(dictionaryAsText(dictionary)); 025 026 AppointmentBookRestClient client = new AppointmentBookRestClient(http); 027 028 assertThat(client.getAllDictionaryEntries(), equalTo(dictionary)); 029 } 030 031 private HttpRequestHelper.Response dictionaryAsText(Map<String, String> dictionary) { 032 StringWriter writer = new StringWriter(); 033 new TextDumper(writer).dump(dictionary); 034 035 return new HttpRequestHelper.Response(writer.toString()); 036 } 037}