use of pokeraidbot.domain.gym.Gym in project pokeraidbot by magnusmickelsson.
the class RaidRepositoryTest method changePokemonWorks.
@Test
public void changePokemonWorks() throws Exception {
// We're not allowed to create signups at night, so mocking time
clockService.setMockTime(LocalTime.of(10, 0));
final LocalDateTime now = clockService.getCurrentDateTime();
final LocalTime nowTime = now.toLocalTime();
LocalDateTime endOfRaid = now.plusMinutes(45);
final Gym gym = gymRepository.findByName("Blenda", uppsalaRegion);
Raid enteiRaid = new Raid(pokemonRepository.search("Entei", null), endOfRaid, gym, localeService, uppsalaRegion);
String raidCreatorName = "testUser1";
User user = mock(User.class);
Guild guild = mock(Guild.class);
Config config = mock(Config.class);
when(user.getName()).thenReturn(raidCreatorName);
try {
repo.newRaid(user, enteiRaid, guild, config, "test");
} catch (RuntimeException e) {
System.err.println(e.getMessage());
fail("Could not save raid: " + e.getMessage());
}
Raid raid = repo.getActiveRaidOrFallbackToExRaid(gym, uppsalaRegion, user);
Raid changedRaid = repo.changePokemon(raid, pokemonRepository.search("Mewtwo", user), guild, config, user, "test");
assertThat(raid.getEndOfRaid(), is(changedRaid.getEndOfRaid()));
assertThat(raid.getGym(), is(changedRaid.getGym()));
assertThat(raid.getSignUps(), is(changedRaid.getSignUps()));
assertThat(raid.getRegion(), is(changedRaid.getRegion()));
assertThat(raid.getPokemon().getName(), is("Entei"));
assertThat(changedRaid.getPokemon().getName(), is("Mewtwo"));
}
use of pokeraidbot.domain.gym.Gym in project pokeraidbot by magnusmickelsson.
the class RaidRepositoryTest method testCreateGetAndDeleteGroup.
@Test
public void testCreateGetAndDeleteGroup() throws Exception {
// We're not allowed to create signups at night, so mocking time
clockService.setMockTime(LocalTime.of(10, 0));
final LocalDateTime now = clockService.getCurrentDateTime();
final LocalTime nowTime = now.toLocalTime();
LocalDateTime endOfRaid = now.plusMinutes(45);
final Gym gym = gymRepository.findByName("Blenda", uppsalaRegion);
Raid enteiRaid = new Raid(pokemonRepository.search("Entei", null), endOfRaid, gym, localeService, uppsalaRegion);
String raidCreatorName = "testUser1";
User user = mock(User.class);
when(user.getName()).thenReturn(raidCreatorName);
Guild guild = mock(Guild.class);
Config config = mock(Config.class);
Raid enteiRaid1 = enteiRaid;
try {
enteiRaid1 = repo.newRaid(user, enteiRaid1, guild, config, "test");
} catch (RuntimeException e) {
System.err.println(e.getMessage());
fail("Could not save raid: " + e.getMessage());
}
enteiRaid = enteiRaid1;
User user2 = mock(User.class);
String userName = "testUser2";
when(user2.getName()).thenReturn(userName);
LocalTime arrivalTime = nowTime.plusMinutes(30);
RaidGroup group = new RaidGroup("testserver", "channel", "infoId", "emoteId", "userId", LocalDateTime.of(LocalDate.now(), arrivalTime));
group = repo.newGroupForRaid(user2, group, enteiRaid, guild, config);
List<RaidGroup> groupsForServer = repo.getGroupsForServer("testserver");
assertThat(group != null, is(true));
assertThat(groupsForServer.size(), is(1));
assertThat(groupsForServer.iterator().next(), is(group));
RaidGroup deleted = repo.deleteGroup(enteiRaid.getId(), group.getId());
assertThat(deleted != null, is(true));
groupsForServer = repo.getGroupsForServer("testserver");
assertThat(groupsForServer.size(), is(0));
}
use of pokeraidbot.domain.gym.Gym in project pokeraidbot by magnusmickelsson.
the class RaidRepositoryTest method testSignUp.
@Test
public void testSignUp() throws Exception {
// We're not allowed to create signups at night, so mocking time
clockService.setMockTime(LocalTime.of(10, 0));
final LocalDateTime now = clockService.getCurrentDateTime();
final LocalTime nowTime = now.toLocalTime();
LocalDateTime endOfRaid = now.plusMinutes(45);
final Gym gym = gymRepository.findByName("Blenda", uppsalaRegion);
Raid enteiRaid = new Raid(pokemonRepository.search("Entei", null), endOfRaid, gym, localeService, uppsalaRegion);
String raidCreatorName = "testUser1";
User user = mock(User.class);
when(user.getName()).thenReturn(raidCreatorName);
Guild guild = mock(Guild.class);
Config config = mock(Config.class);
try {
repo.newRaid(user, enteiRaid, guild, config, "test");
} catch (RuntimeException e) {
System.err.println(e.getMessage());
fail("Could not save raid: " + e.getMessage());
}
User user2 = mock(User.class);
String userName = "testUser2";
when(user2.getName()).thenReturn(userName);
Raid raid = repo.getActiveRaidOrFallbackToExRaid(gym, uppsalaRegion, user2);
// Set to same id for equals comparison
enteiRaid.setId(raid.getId());
// Set creator to same for equals comparison
enteiRaid.setCreator(raid.getCreator());
assertThat(raid, is(enteiRaid));
int howManyPeople = 3;
LocalTime arrivalTime = nowTime.plusMinutes(30);
raid.signUp(user2, howManyPeople, arrivalTime, repo);
assertThat(raid.getSignUps().size(), is(1));
assertThat(raid.getNumberOfPeopleSignedUp(), is(howManyPeople));
final Raid raidFromDb = repo.getActiveRaidOrFallbackToExRaid(gym, uppsalaRegion, user2);
assertThat(raidFromDb, is(raid));
assertThat(raidFromDb.getSignUps().size(), is(1));
}
use of pokeraidbot.domain.gym.Gym in project pokeraidbot by magnusmickelsson.
the class UtilsTest method timeInRaidspan.
@Test
public void timeInRaidspan() throws Exception {
User user = mock(User.class);
when(user.getName()).thenReturn("User");
LocalDateTime localDateTime = LocalDateTime.now();
LocalDateTime same = localDateTime;
LocalDateTime before = localDateTime.minusMinutes(1);
LocalDateTime after = localDateTime.plusMinutes(1);
LocalDateTime end = localDateTime.plusMinutes(Utils.RAID_DURATION_IN_MINUTES);
LocalDateTime sameAsEnd = end;
LocalDateTime beforeEnd = end.minusMinutes(1);
LocalDateTime afterEnd = end.plusMinutes(1);
final LocaleService localeService = mock(LocaleService.class);
when(localeService.getMessageFor(any(), any(), any())).thenReturn("Mupp");
Raid raid = new Raid(pokemonRepository.getByName("Tyranitar"), end, new Gym("Test", "id", "10", "10", null), localeService, "Test");
checkWhetherAssertFails(user, same, localeService, raid, false);
checkWhetherAssertFails(user, after, localeService, raid, false);
checkWhetherAssertFails(user, before, localeService, raid, true);
checkWhetherAssertFails(user, sameAsEnd, localeService, raid, false);
checkWhetherAssertFails(user, afterEnd, localeService, raid, true);
checkWhetherAssertFails(user, beforeEnd, localeService, raid, false);
}
use of pokeraidbot.domain.gym.Gym in project pokeraidbot by magnusmickelsson.
the class GymRepositoryTest method findNewGymInUppsala.
@Test
public void findNewGymInUppsala() throws Exception {
final Gym u969 = repo.findByName("U969", "uppsala");
assertThat(u969.getName(), is("U969"));
assertThat(u969.isExGym(), is(false));
}
Aggregations