-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
213 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
sixpack-java/src/main/java/com/seatgeek/sixpack/PrefetchedExperiment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.seatgeek.sixpack; | ||
|
||
public class PrefetchedExperiment { | ||
|
||
private final Sixpack sixpack; | ||
|
||
public final Experiment baseExperiment; | ||
|
||
public final Alternative selectedAlternative; | ||
|
||
public PrefetchedExperiment(final Sixpack sixpack, final Experiment experiment, final Alternative alternative) { | ||
this.sixpack = sixpack; | ||
baseExperiment = experiment; | ||
selectedAlternative = alternative; | ||
} | ||
|
||
public ParticipatingExperiment participate() { | ||
return sixpack.participate(baseExperiment); | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) return true; | ||
if (!(o instanceof PrefetchedExperiment)) return false; | ||
|
||
final PrefetchedExperiment that = (PrefetchedExperiment) o; | ||
|
||
if (baseExperiment != null ? !baseExperiment.equals(that.baseExperiment) : that.baseExperiment != null) | ||
return false; | ||
return !(selectedAlternative != null ? !selectedAlternative.equals(that.selectedAlternative) : that.selectedAlternative != null); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = baseExperiment != null ? baseExperiment.hashCode() : 0; | ||
result = 31 * result + (selectedAlternative != null ? selectedAlternative.hashCode() : 0); | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
sixpack-java/src/test/java/com/seatgeek/sixpack/PrefetchedExperimentTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.seatgeek.sixpack; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.Mock; | ||
|
||
import nl.jqno.equalsverifier.EqualsVerifier; | ||
import nl.jqno.equalsverifier.Warning; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.MockitoAnnotations.initMocks; | ||
|
||
public class PrefetchedExperimentTest { | ||
@Mock Sixpack mockSixpack; | ||
|
||
@Mock Experiment mockExperiment; | ||
|
||
@Mock Alternative mockAlternative; | ||
|
||
@Before | ||
public void setUp() { | ||
initMocks(this); | ||
} | ||
|
||
@Test | ||
public void testParticipateCallsSixpackParticipate() { | ||
PrefetchedExperiment prefetchedExperiment = new PrefetchedExperiment(mockSixpack, mockExperiment, mockAlternative); | ||
|
||
prefetchedExperiment.participate(); | ||
|
||
verify(mockSixpack).participate(mockExperiment); | ||
} | ||
|
||
@Test | ||
public void testEquals() { | ||
EqualsVerifier.forClass(PrefetchedExperiment.class).suppress(Warning.NULL_FIELDS, Warning.STRICT_INHERITANCE).verify(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters