@Test public void testConvertSuccess() throws IOException { Alternative selected = new Alternative("green"); Call<ConvertResponse> call = mock(Call.class); when(call.execute()).thenReturn(retrofit2.Response.success(new ConvertResponse())); when(mockApi.convert(Matchers.<Experiment>anyObject(), Matchers.anyString())).thenReturn(call); Sixpack sixpack = new Sixpack(mockApi); Experiment experiment = new Experiment(sixpack, "test-experience", new HashSet<Alternative>(), null, 1.0d); ParticipatingExperiment participating = new ParticipatingExperiment(sixpack, experiment, selected); ConvertedExperiment convert = sixpack.convert(participating, "test_kpi"); assertEquals(new ConvertedExperiment(sixpack, experiment), convert); }
ConvertedExperiment convert(final ParticipatingExperiment experiment, String kpi) { logConvert(experiment, kpi); try { Response<ConvertResponse> response = api.convert(experiment.baseExperiment, kpi).execute(); if (response.isSuccessful()) { return new ConvertedExperiment(Sixpack.this, experiment.baseExperiment); } else { logFailedConversion(experiment.baseExperiment, response.code()); throw new ConversionError(null, experiment.baseExperiment); } } catch (RuntimeException | IOException e) { logException(experiment.baseExperiment, e); throw new ConversionError(e, experiment.baseExperiment); } }
Sixpack { ConvertedExperiment convert(final ParticipatingExperiment experiment, String kpi) { logConvert(experiment, kpi); try { Response<ConvertResponse> response = api.convert(experiment.baseExperiment, kpi).execute(); if (response.isSuccessful()) { return new ConvertedExperiment(Sixpack.this, experiment.baseExperiment); } else { logFailedConversion(experiment.baseExperiment, response.code()); throw new ConversionError(null, experiment.baseExperiment); } } catch (RuntimeException | IOException e) { logException(experiment.baseExperiment, e); throw new ConversionError(e, experiment.baseExperiment); } } }
Sixpack { ConvertedExperiment convert(final ParticipatingExperiment experiment, String kpi) { logConvert(experiment, kpi); try { Response<ConvertResponse> response = api.convert(experiment.baseExperiment, kpi).execute(); if (response.isSuccessful()) { return new ConvertedExperiment(Sixpack.this, experiment.baseExperiment); } else { logFailedConversion(experiment.baseExperiment, response.code()); throw new ConversionError(null, experiment.baseExperiment); } } catch (RuntimeException | IOException e) { logException(experiment.baseExperiment, e); throw new ConversionError(e, experiment.baseExperiment); } } Sixpack(final HttpUrl sixpackUrl, final String clientId, final OkHttpClient client);   Sixpack(final SixpackApi api);   Sixpack(final SixpackApi api, final String clientId); }
Sixpack { ConvertedExperiment convert(final ParticipatingExperiment experiment, String kpi) { logConvert(experiment, kpi); try { Response<ConvertResponse> response = api.convert(experiment.baseExperiment, kpi).execute(); if (response.isSuccessful()) { return new ConvertedExperiment(Sixpack.this, experiment.baseExperiment); } else { logFailedConversion(experiment.baseExperiment, response.code()); throw new ConversionError(null, experiment.baseExperiment); } } catch (RuntimeException | IOException e) { logException(experiment.baseExperiment, e); throw new ConversionError(e, experiment.baseExperiment); } } Sixpack(final HttpUrl sixpackUrl, final String clientId, final OkHttpClient client);   Sixpack(final SixpackApi api);   Sixpack(final SixpackApi api, final String clientId); ExperimentBuilder experiment(); String getClientId(); void setLogLevel(LogLevel logLevel); LogLevel getLogLevel(); void setLogger(final Logger logger); static String generateRandomClientId(); }
Sixpack { ConvertedExperiment convert(final ParticipatingExperiment experiment, String kpi) { logConvert(experiment, kpi); try { Response<ConvertResponse> response = api.convert(experiment.baseExperiment, kpi).execute(); if (response.isSuccessful()) { return new ConvertedExperiment(Sixpack.this, experiment.baseExperiment); } else { logFailedConversion(experiment.baseExperiment, response.code()); throw new ConversionError(null, experiment.baseExperiment); } } catch (RuntimeException | IOException e) { logException(experiment.baseExperiment, e); throw new ConversionError(e, experiment.baseExperiment); } } Sixpack(final HttpUrl sixpackUrl, final String clientId, final OkHttpClient client);   Sixpack(final SixpackApi api);   Sixpack(final SixpackApi api, final String clientId); ExperimentBuilder experiment(); String getClientId(); void setLogLevel(LogLevel logLevel); LogLevel getLogLevel(); void setLogger(final Logger logger); static String generateRandomClientId(); static final HttpUrl DEFAULT_URL; static final String NAME_REGEX; static final Pattern NAME_PATTERN; static final LogLevel DEFAULT_LOG_LEVEL; static final String SIXPACK_LOG_TAG; }