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
@Entity | |
@Table(name="charity") | |
public class Charity extends Model { | |
@Id | |
public Integer id; | |
@Column(name="name") | |
public String name; |
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
private <T> CompletionStage<T> wrapContext(Supplier<T> toRun) { | |
return supplyAsync(toRun, executionContext); | |
} | |
public CompletionStage<List<Charity>> findList() { | |
return wrapContext(() -> ebeanServer.find(Charity.class).findList()); | |
} |
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
public class DatabaseExecutionContext extends CustomExecutionContext { | |
@Inject | |
public DatabaseExecutionContext(ActorSystem actorSystem) { | |
super(actorSystem, "database.dispatcher"); | |
} | |
} |
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
public class CharityController { | |
private final CharityRepository charityRepository; | |
private final HttpExecutionContext ec; | |
private final LocalDateTime endDateTime; | |
private final Clock clock; | |
@Inject | |
public CharityController(CharityRepository charityRepository, | |
HttpExecutionContext ec, |
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
GET / controllers.CharityController.index() |
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
public class CharityControllerTest extends WithServer { | |
private Clock clock; | |
@Override | |
protected Application provideApplication() { | |
return new GuiceApplicationBuilder() | |
.overrides(bindClockToMockInstance()) | |
.build(); | |
} |
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
@Test | |
public void Given_IsBeforeEndDate_When_GetRequestIsMadeToIndexPage_Then_StatusIs200() { | |
// GIVEN | |
long beforeEndDate = 9L; | |
given(clock.instant()).willReturn(ofEpochMilli(beforeEndDate)); | |
given(clock.getZone()).willReturn(ZoneId.of("+0")); | |
// WHEN | |
WSResponse result = newClient(providePort()).url("/").get().toCompletableFuture().join(); |
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
public class CharityRepositoryTest extends WithApplication { | |
private CharityRepository repository; | |
@Before | |
public void setUp() { | |
repository = instanceOf(CharityRepository.class); | |
CallableSql cleanCharityTable = getDefaultServer().createCallableSql("delete from charity"); | |
getDefaultServer().execute(cleanCharityTable); |
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
@Test | |
public void Given_CharityObjectsExist_When_FindListIsCalled_Then_AllCharityObjectsAreReturned() { | |
// GIVEN | |
rangeClosed(1, 4).boxed().map(Charity::new).forEach(Model::save); | |
// WHEN | |
List<Charity> result = repository.findList().toCompletableFuture().join(); | |
// THEN |
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
public CompletionStage<List<Charity>> findList() { | |
return null; | |
} |
OlderNewer