Rename ...Dao -> ...Repository

This commit is contained in:
P0nk
2024-09-14 12:06:09 +02:00
parent abbec8120e
commit 08eeeb54dc
17 changed files with 103 additions and 103 deletions

View File

@@ -1,10 +0,0 @@
package database;
import org.jdbi.v3.core.JdbiException;
public class DaoException extends JdbiException {
public DaoException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@@ -0,0 +1,10 @@
package database;
import org.jdbi.v3.core.JdbiException;
public class DatabaseException extends JdbiException {
public DatabaseException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@@ -3,7 +3,7 @@ package database.character;
import client.Character;
import client.Client;
import client.MonsterBook;
import database.monsterbook.MonsterCardDao;
import database.monsterbook.MonsterCardRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -12,10 +12,10 @@ import java.util.Optional;
public class CharacterLoader {
private static final Logger log = LoggerFactory.getLogger(CharacterLoader.class);
private final MonsterCardDao monsterCardDao;
private final MonsterCardRepository monsterCardRepository;
public CharacterLoader(MonsterCardDao monsterCardDao) {
this.monsterCardDao = monsterCardDao;
public CharacterLoader(MonsterCardRepository monsterCardRepository) {
this.monsterCardRepository = monsterCardRepository;
}
public Optional<Character> loadForChannel(int chrId, Client client) {
@@ -33,7 +33,7 @@ public class CharacterLoader {
}
private MonsterBook loadMonsterBook(int chrId) {
var monsterCards = monsterCardDao.load(chrId);
var monsterCards = monsterCardRepository.load(chrId);
return new MonsterBook(monsterCards);
}
}

View File

@@ -1,7 +1,7 @@
package database.character;
import client.Character;
import database.monsterbook.MonsterCardDao;
import database.monsterbook.MonsterCardRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tools.DatabaseConnection;
@@ -11,10 +11,10 @@ import java.sql.SQLException;
public class CharacterSaver {
private static final Logger log = LoggerFactory.getLogger(CharacterSaver.class);
private final MonsterCardDao monsterCardDao;
private final MonsterCardRepository monsterCardRepository;
public CharacterSaver(MonsterCardDao monsterCardDao) {
this.monsterCardDao = monsterCardDao;
public CharacterSaver(MonsterCardRepository monsterCardRepository) {
this.monsterCardRepository = monsterCardRepository;
}
public void save(Character chr) {
@@ -42,7 +42,7 @@ public class CharacterSaver {
}
// Saving monster cards to both MySQL and Postgres for now
monsterCardDao.save(chr.getId(), chr.getMonsterBook().getCards());
monsterCardRepository.save(chr.getId(), chr.getMonsterBook().getCards());
}
}

View File

@@ -10,20 +10,20 @@ import java.util.List;
import java.util.Optional;
public class DropProvider {
private final DropDao dropDao;
private final DropRepository dropRepository;
private final Cache<Integer, List<MonsterDrop>> monsterDropCache = Caffeine.newBuilder().build();
private final Cache<Integer, List<MonsterGlobalDropEntry>> globalContinentDropCache = Caffeine.newBuilder().build();
private volatile List<GlobalMonsterDrop> globalMonsterDrops = null;
public DropProvider(DropDao dropDao) {
if (dropDao == null) {
public DropProvider(DropRepository dropRepository) {
if (dropRepository == null) {
throw new IllegalArgumentException("DropDao must not be null");
}
this.dropDao = dropDao;
this.dropRepository = dropRepository;
}
private List<MonsterDrop> getMonsterDrops(int monsterId) {
return monsterDropCache.get(monsterId, dropDao::getMonsterDrops);
return monsterDropCache.get(monsterId, dropRepository::getMonsterDrops);
}
public List<MonsterDropEntry> getMonsterDropEntries(int monsterId) {
@@ -61,7 +61,7 @@ public class DropProvider {
}
private void loadGlobalDrops() {
this.globalMonsterDrops = dropDao.getGlobalMonsterDrops();
this.globalMonsterDrops = dropRepository.getGlobalMonsterDrops();
}
// TODO: Temporary. MonsterDropEntry should be removed.

View File

@@ -1,16 +1,16 @@
package database.drop;
import database.DaoException;
import database.DatabaseException;
import database.PgDatabaseConnection;
import org.jdbi.v3.core.Handle;
import org.jdbi.v3.core.JdbiException;
import java.util.List;
public class DropDao {
public class DropRepository {
private final PgDatabaseConnection connection;
public DropDao(PgDatabaseConnection connection) {
public DropRepository(PgDatabaseConnection connection) {
this.connection = connection;
}
@@ -24,7 +24,7 @@ public class DropDao {
.mapTo(MonsterDrop.class)
.list();
} catch (JdbiException e) {
throw new DaoException("Failed to get monster drops for id %d".formatted(monsterId), e);
throw new DatabaseException("Failed to get monster drops for id %d".formatted(monsterId), e);
}
}
@@ -36,7 +36,7 @@ public class DropDao {
.mapTo(GlobalMonsterDrop.class)
.list();
} catch (JdbiException e) {
throw new DaoException("Failed to get global monster drops", e);
throw new DatabaseException("Failed to get global monster drops", e);
}
}
}

View File

@@ -11,24 +11,24 @@ import java.util.Optional;
@ThreadSafe
public class MakerInfoProvider {
private final MakerDao makerDao;
private final MakerRepository makerRepository;
private final Cache<Integer, Optional<MakerReagent>> reagentCache = Caffeine.newBuilder().build();
private final Cache<Integer, Optional<MakerRecipe>> recipeCache = Caffeine.newBuilder().build();
private final Cache<Integer, List<MakerIngredient>> ingredientsCache = Caffeine.newBuilder().build();
public MakerInfoProvider(MakerDao makerDao) {
if (makerDao == null) {
public MakerInfoProvider(MakerRepository makerRepository) {
if (makerRepository == null) {
throw new IllegalArgumentException("MakerDao must not be null");
}
this.makerDao = makerDao;
this.makerRepository = makerRepository;
}
public Optional<MakerReagent> getMakerReagent(int itemId) {
return reagentCache.get(itemId, makerDao::getReagent);
return reagentCache.get(itemId, makerRepository::getReagent);
}
public Optional<MakerRecipe> getMakerRecipe(int itemId) {
return recipeCache.get(itemId, makerDao::getRecipe);
return recipeCache.get(itemId, makerRepository::getRecipe);
}
public Optional<Integer> getStimulant(int itemId) {
@@ -36,7 +36,7 @@ public class MakerInfoProvider {
}
public List<MakerIngredient> getIngredients(int recipeItemId) {
return ingredientsCache.get(recipeItemId, makerDao::getIngredients);
return ingredientsCache.get(recipeItemId, makerRepository::getIngredients);
}
public Optional<MakerDisassemblyInfo> getDisassemblyInfo(int itemId) {

View File

@@ -1,6 +1,6 @@
package database.maker;
import database.DaoException;
import database.DatabaseException;
import database.PgDatabaseConnection;
import org.jdbi.v3.core.Handle;
import org.jdbi.v3.core.JdbiException;
@@ -8,10 +8,10 @@ import org.jdbi.v3.core.JdbiException;
import java.util.List;
import java.util.Optional;
public class MakerDao {
public class MakerRepository {
private final PgDatabaseConnection connection;
public MakerDao(PgDatabaseConnection connection) {
public MakerRepository(PgDatabaseConnection connection) {
this.connection = connection;
}
@@ -25,7 +25,7 @@ public class MakerDao {
.mapTo(MakerReagent.class)
.findOne();
} catch (JdbiException e) {
throw new DaoException("Failed to get maker reagent with item id: %d".formatted(itemId), e);
throw new DatabaseException("Failed to get maker reagent with item id: %d".formatted(itemId), e);
}
}
@@ -39,7 +39,7 @@ public class MakerDao {
.mapTo(MakerRecipe.class)
.findOne();
} catch (JdbiException e) {
throw new DaoException("Failed to get maker recipe with item id: %d".formatted(itemId), e);
throw new DatabaseException("Failed to get maker recipe with item id: %d".formatted(itemId), e);
}
}
@@ -53,7 +53,7 @@ public class MakerDao {
.mapTo(MakerIngredient.class)
.list();
} catch (JdbiException e) {
throw new DaoException("Failed to get maker ingredients for recipe item id %d".formatted(recipeItemId), e);
throw new DatabaseException("Failed to get maker ingredients for recipe item id %d".formatted(recipeItemId), e);
}
}
}

View File

@@ -1,6 +1,6 @@
package database.monsterbook;
import database.DaoException;
import database.DatabaseException;
import database.PgDatabaseConnection;
import org.jdbi.v3.core.Handle;
import org.jdbi.v3.core.JdbiException;
@@ -8,10 +8,10 @@ import org.jdbi.v3.core.statement.PreparedBatch;
import java.util.List;
public class MonsterCardDao {
public class MonsterCardRepository {
private final PgDatabaseConnection connection;
public MonsterCardDao(PgDatabaseConnection connection) {
public MonsterCardRepository(PgDatabaseConnection connection) {
this.connection = connection;
}
@@ -25,7 +25,7 @@ public class MonsterCardDao {
.mapTo(MonsterCard.class)
.list();
} catch (JdbiException e) {
throw new DaoException("Failed to find monster cards (chrId %d)".formatted(chrId), e);
throw new DatabaseException("Failed to find monster cards (chrId %d)".formatted(chrId), e);
}
}
@@ -44,7 +44,7 @@ public class MonsterCardDao {
});
batch.execute();
} catch (JdbiException e) {
throw new DaoException("Failed to save monster cards (chrId %d)".formatted(chrId), e);
throw new DatabaseException("Failed to save monster cards (chrId %d)".formatted(chrId), e);
}
}
}

View File

@@ -1,6 +1,6 @@
package database.note;
import database.DaoException;
import database.DatabaseException;
import database.PgDatabaseConnection;
import model.Note;
import org.jdbi.v3.core.Handle;
@@ -29,7 +29,7 @@ public class NoteDao {
.bind(5, 0)
.execute();
} catch (JdbiException e) {
throw new DaoException("Failed to save note: %s".formatted(note.toString()), e);
throw new DatabaseException("Failed to save note: %s".formatted(note.toString()), e);
}
}
@@ -46,7 +46,7 @@ public class NoteDao {
.mapTo(Note.class)
.list();
} catch (JdbiException e) {
throw new DaoException("Failed to find notes sent to: %s".formatted(receiver), e);
throw new DatabaseException("Failed to find notes sent to: %s".formatted(receiver), e);
}
}
@@ -60,7 +60,7 @@ public class NoteDao {
return note;
} catch (JdbiException e) {
throw new DaoException("Failed to delete note with id: %d".formatted(id), e);
throw new DatabaseException("Failed to delete note with id: %d".formatted(id), e);
}
}
@@ -76,7 +76,7 @@ public class NoteDao {
.mapTo(Note.class)
.findOne();
} catch (JdbiException e) {
throw new DaoException("Failed find note with id %s".formatted(id), e);
throw new DatabaseException("Failed find note with id %s".formatted(id), e);
}
return note;
}
@@ -90,7 +90,7 @@ public class NoteDao {
.bind(0, id)
.execute();
} catch (JdbiException e) {
throw new DaoException("Failed to delete note with id %d".formatted(id), e);
throw new DatabaseException("Failed to delete note with id %d".formatted(id), e);
}
}
}

View File

@@ -1,6 +1,6 @@
package database.shop;
import database.DaoException;
import database.DatabaseException;
import database.PgDatabaseConnection;
import org.jdbi.v3.core.Handle;
import org.jdbi.v3.core.JdbiException;
@@ -25,7 +25,7 @@ public class ShopDao {
.mapTo(Shop.class)
.findOne();
} catch (JdbiException e) {
throw new DaoException("Failed to get shop with id %d".formatted(shopId), e);
throw new DatabaseException("Failed to get shop with id %d".formatted(shopId), e);
}
}
@@ -40,7 +40,7 @@ public class ShopDao {
.mapTo(ShopItem.class)
.list();
} catch (JdbiException e) {
throw new DaoException("Failed to get shop items for shop %d".formatted(shopId), e);
throw new DatabaseException("Failed to get shop items for shop %d".formatted(shopId), e);
}
}
}

View File

@@ -45,12 +45,12 @@ import database.PgDatabaseConfig;
import database.PgDatabaseConnection;
import database.character.CharacterLoader;
import database.character.CharacterSaver;
import database.drop.DropDao;
import database.drop.DropProvider;
import database.maker.MakerDao;
import database.drop.DropRepository;
import database.maker.MakerInfoProvider;
import database.maker.MakerRepository;
import database.migration.FlywayRunner;
import database.monsterbook.MonsterCardDao;
import database.monsterbook.MonsterCardRepository;
import database.note.NoteDao;
import database.shop.ShopDao;
import net.ChannelDependencies;
@@ -1002,15 +1002,15 @@ public class Server {
}
private ChannelDependencies registerChannelDependencies(PgDatabaseConnection connection) {
MonsterCardDao monsterCardDao = new MonsterCardDao(connection);
CharacterLoader characterLoader = new CharacterLoader(monsterCardDao);
CharacterSaver characterSaver = new CharacterSaver(monsterCardDao);
MonsterCardRepository monsterCardRepository = new MonsterCardRepository(connection);
CharacterLoader characterLoader = new CharacterLoader(monsterCardRepository);
CharacterSaver characterSaver = new CharacterSaver(monsterCardRepository);
TransitionService transitionService = new TransitionService(characterSaver);
BanService banService = new BanService(transitionService);
NoteService noteService = new NoteService(new NoteDao(connection));
MakerProcessor makerProcessor = new MakerProcessor(new MakerInfoProvider(new MakerDao(connection)));
MakerProcessor makerProcessor = new MakerProcessor(new MakerInfoProvider(new MakerRepository(connection)));
FredrickProcessor fredrickProcessor = new FredrickProcessor(noteService);
DropProvider dropProvider = new DropProvider(new DropDao(connection));
DropProvider dropProvider = new DropProvider(new DropRepository(connection));
ShopFactory shopFactory = new ShopFactory(new ShopDao(connection));
CommandContext commandContext = new CommandContext(null, dropProvider, shopFactory,
characterSaver, transitionService);

View File

@@ -1,7 +1,7 @@
package service;
import client.Character;
import database.DaoException;
import database.DatabaseException;
import database.note.NoteDao;
import model.Note;
import net.packet.out.ShowNotesPacket;
@@ -52,7 +52,7 @@ public class NoteService {
try {
noteDao.save(note);
return true;
} catch (DaoException e) {
} catch (DatabaseException e) {
log.error("Failed to send note {}", note, e);
return false;
}
@@ -80,7 +80,7 @@ public class NoteService {
final List<Note> notes;
try {
notes = noteDao.findAllByTo(to);
} catch (DaoException e) {
} catch (DatabaseException e) {
log.error("Failed to find notes sent to chr name {}", to, e);
return Collections.emptyList();
}
@@ -101,7 +101,7 @@ public class NoteService {
public Optional<Note> delete(int noteId) {
try {
return noteDao.delete(noteId);
} catch (DaoException e) {
} catch (DatabaseException e) {
log.error("Failed to discard note with id {}", noteId, e);
return Optional.empty();
}

View File

@@ -21,19 +21,19 @@ import static org.mockito.Mockito.when;
class DropProviderTest {
@Mock
private DropDao dropDao;
private DropRepository dropRepository;
private DropProvider dropProvider;
@BeforeEach
void reset() {
MockitoAnnotations.openMocks(this);
this.dropProvider = new DropProvider(dropDao);
this.dropProvider = new DropProvider(dropRepository);
}
@Test
void getMonsterDropEntries_noDrops() {
when(dropDao.getMonsterDrops(anyInt())).thenReturn(Collections.emptyList());
when(dropRepository.getMonsterDrops(anyInt())).thenReturn(Collections.emptyList());
List<MonsterDropEntry> dropEntries = dropProvider.getMonsterDropEntries(489340);
@@ -43,7 +43,7 @@ class DropProviderTest {
@Test
void getMonsterDropEntries() {
MonsterDrop snailShellDrop = snailShellDrop();
when(dropDao.getMonsterDrops(anyInt())).thenReturn(List.of(snailShellDrop));
when(dropRepository.getMonsterDrops(anyInt())).thenReturn(List.of(snailShellDrop));
List<MonsterDropEntry> dropEntries = dropProvider.getMonsterDropEntries(100100);
@@ -58,7 +58,7 @@ class DropProviderTest {
@Test
void getCachedMonsterDropEntries() {
when(dropDao.getMonsterDrops(anyInt())).thenReturn(List.of(snailShellDrop()));
when(dropRepository.getMonsterDrops(anyInt())).thenReturn(List.of(snailShellDrop()));
int monsterId = 100100;
List<MonsterDropEntry> dropEntries1 = dropProvider.getMonsterDropEntries(monsterId);
@@ -73,7 +73,7 @@ class DropProviderTest {
assertEquals(dropEntry1.Maximum, dropEntry2.Maximum);
assertEquals(dropEntry1.questid, dropEntry2.questid);
assertEquals(dropEntry1.chance, dropEntry2.chance);
verify(dropDao, times(1)).getMonsterDrops(anyInt());
verify(dropRepository, times(1)).getMonsterDrops(anyInt());
}
private MonsterDrop snailShellDrop() {
@@ -83,7 +83,7 @@ class DropProviderTest {
@Test
void getCachedGlobalDropEntries() {
GlobalMonsterDrop globalDrop = new GlobalMonsterDrop(2049100, -1, 2, 3, null, 450);
when(dropDao.getGlobalMonsterDrops()).thenReturn(List.of(globalDrop));
when(dropRepository.getGlobalMonsterDrops()).thenReturn(List.of(globalDrop));
List<MonsterGlobalDropEntry> dropEntries1 = dropProvider.getRelevantGlobalDrops(AnyValues.integer());
List<MonsterGlobalDropEntry> dropEntries2 = dropProvider.getRelevantGlobalDrops(AnyValues.integer());
@@ -104,13 +104,13 @@ class DropProviderTest {
assertEquals(dropEntry1.questid, dropEntry2.questid);
assertEquals(450, dropEntry1.chance);
assertEquals(dropEntry1.chance, dropEntry2.chance);
verify(dropDao, times(1)).getGlobalMonsterDrops();
verify(dropRepository, times(1)).getGlobalMonsterDrops();
}
@Test
void getRelevantGlobalDrop() {
GlobalMonsterDrop ossyriaDrop = new GlobalMonsterDrop(AnyValues.integer(), 2, AnyValues.integer(), AnyValues.integer(), AnyValues.integer(), AnyValues.integer());
when(dropDao.getGlobalMonsterDrops()).thenReturn(List.of(ossyriaDrop));
when(dropRepository.getGlobalMonsterDrops()).thenReturn(List.of(ossyriaDrop));
int ossyriaMapId = 200_000_200;
List<MonsterGlobalDropEntry> dropEntries = dropProvider.getRelevantGlobalDrops(ossyriaMapId);
@@ -121,7 +121,7 @@ class DropProviderTest {
@Test
void getRelevantGlobalDrop_wrongContinent() {
GlobalMonsterDrop ellinDrop = new GlobalMonsterDrop(AnyValues.integer(), 3, AnyValues.integer(), AnyValues.integer(), AnyValues.integer(), AnyValues.integer());
when(dropDao.getGlobalMonsterDrops()).thenReturn(List.of(ellinDrop));
when(dropRepository.getGlobalMonsterDrops()).thenReturn(List.of(ellinDrop));
int victoriaMapId = 102_000_000;
List<MonsterGlobalDropEntry> dropEntries = dropProvider.getRelevantGlobalDrops(victoriaMapId);
@@ -132,28 +132,28 @@ class DropProviderTest {
@Test
void clearCaches_shouldClearMonsterDrops() {
MonsterDrop drop = snailShellDrop();
when(dropDao.getMonsterDrops(anyInt())).thenReturn(List.of(drop));
when(dropRepository.getMonsterDrops(anyInt())).thenReturn(List.of(drop));
int monsterId = 100100;
List<MonsterDropEntry> drops1 = dropProvider.getMonsterDropEntries(monsterId);
dropProvider.clearCaches();
List<MonsterDropEntry> drops2 = dropProvider.getMonsterDropEntries(monsterId);
verify(dropDao, times(2)).getMonsterDrops(anyInt());
verify(dropRepository, times(2)).getMonsterDrops(anyInt());
assertEquals(1, drops1.size());
assertEquals(1, drops2.size());
}
@Test
void clearCaches_shouldClearGlobalDrops() {
when(dropDao.getGlobalMonsterDrops()).thenReturn(List.of(globalDrop()));
when(dropRepository.getGlobalMonsterDrops()).thenReturn(List.of(globalDrop()));
int mapId = 100_000_123;
List<MonsterGlobalDropEntry> drops1 = dropProvider.getRelevantGlobalDrops(mapId);
dropProvider.clearCaches();
List<MonsterGlobalDropEntry> drops2 = dropProvider.getRelevantGlobalDrops(mapId);
verify(dropDao, times(2)).getGlobalMonsterDrops();
verify(dropRepository, times(2)).getGlobalMonsterDrops();
assertEquals(1, drops1.size());
assertEquals(1, drops2.size());
}

View File

@@ -22,14 +22,14 @@ import static org.mockito.Mockito.when;
class MakerInfoProviderTest {
@Mock
private MakerDao makerDao;
private MakerRepository makerRepository;
private MakerInfoProvider makerInfoProvider;
@BeforeEach
void reset() {
MockitoAnnotations.openMocks(this);
this.makerInfoProvider = new MakerInfoProvider(makerDao);
this.makerInfoProvider = new MakerInfoProvider(makerRepository);
}
@Test
@@ -41,7 +41,7 @@ class MakerInfoProviderTest {
void getReagentFromDb() {
int itemId = 5783;
MakerReagent reagent = createReagent(itemId);
when(makerDao.getReagent(anyInt())).thenReturn(Optional.of(reagent));
when(makerRepository.getReagent(anyInt())).thenReturn(Optional.of(reagent));
Optional<MakerReagent> retrievedReagent = makerInfoProvider.getMakerReagent(itemId);
@@ -53,7 +53,7 @@ class MakerInfoProviderTest {
void getCachedReagent() {
int itemId = 90123444;
MakerReagent reagent = createReagent(itemId);
when(makerDao.getReagent(anyInt())).thenReturn(Optional.of(reagent));
when(makerRepository.getReagent(anyInt())).thenReturn(Optional.of(reagent));
Optional<MakerReagent> firstReagent = makerInfoProvider.getMakerReagent(itemId);
Optional<MakerReagent> secondReagent = makerInfoProvider.getMakerReagent(itemId);
@@ -62,7 +62,7 @@ class MakerInfoProviderTest {
assertEquals(reagent, firstReagent.get());
assertTrue(secondReagent.isPresent());
assertEquals(reagent, secondReagent.get());
verify(makerDao, times(1)).getReagent(itemId);
verify(makerRepository, times(1)).getReagent(itemId);
}
private MakerReagent createReagent(int itemId) {
@@ -73,7 +73,7 @@ class MakerInfoProviderTest {
void getRecipeFromDb() {
int itemId = 43893;
MakerRecipe recipe = createRecipe(itemId);
when(makerDao.getRecipe(itemId)).thenReturn(Optional.of(recipe));
when(makerRepository.getRecipe(itemId)).thenReturn(Optional.of(recipe));
Optional<MakerRecipe> retrievedRecipe = makerInfoProvider.getMakerRecipe(itemId);
@@ -94,7 +94,7 @@ class MakerInfoProviderTest {
void getCachedRecipe() {
int itemId = 10848;
MakerRecipe recipe = createRecipe(itemId);
when(makerDao.getRecipe(anyInt())).thenReturn(Optional.of(recipe));
when(makerRepository.getRecipe(anyInt())).thenReturn(Optional.of(recipe));
Optional<MakerRecipe> firstRecipe = makerInfoProvider.getMakerRecipe(itemId);
Optional<MakerRecipe> secondRecipe = makerInfoProvider.getMakerRecipe(itemId);
@@ -103,7 +103,7 @@ class MakerInfoProviderTest {
assertEquals(recipe, firstRecipe.get());
assertTrue(secondRecipe.isPresent());
assertEquals(recipe, secondRecipe.get());
verify(makerDao, times(1)).getRecipe(itemId);
verify(makerRepository, times(1)).getRecipe(itemId);
}
private MakerRecipe createRecipe(int itemId) {
@@ -114,7 +114,7 @@ class MakerInfoProviderTest {
void getStimulant() {
int catalyst = 4031200;
MakerRecipe recipeWithCatalyst = new MakerRecipe(0, (short) 0, (short) 0, (short) 0, 0, null, null, catalyst, (short) 0, (short) 0);
when(makerDao.getRecipe(anyInt())).thenReturn(Optional.of(recipeWithCatalyst));
when(makerRepository.getRecipe(anyInt())).thenReturn(Optional.of(recipeWithCatalyst));
Optional<Integer> stimulant = makerInfoProvider.getStimulant(AnyValues.integer());
@@ -144,9 +144,9 @@ class MakerInfoProviderTest {
void getMakerItemCreateEntry() {
final int itemId = 458945;
MakerRecipe recipe = createRecipe(itemId);
when(makerDao.getRecipe(anyInt())).thenReturn(Optional.of(recipe));
when(makerRepository.getRecipe(anyInt())).thenReturn(Optional.of(recipe));
MakerIngredient ingredient = new MakerIngredient(1002003, (short) 5);
when(makerDao.getIngredients(anyInt())).thenReturn(List.of(ingredient));
when(makerRepository.getIngredients(anyInt())).thenReturn(List.of(ingredient));
Optional<MakerItemFactory.MakerItemCreateEntry> optionalCreateEntry = makerInfoProvider.getMakerItemEntry(itemId);
@@ -166,6 +166,6 @@ class MakerInfoProviderTest {
}
private void givenNoRecipe() {
when(makerDao.getRecipe(anyInt())).thenReturn(Optional.empty());
when(makerRepository.getRecipe(anyInt())).thenReturn(Optional.empty());
}
}

View File

@@ -25,7 +25,7 @@ import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static testutil.AnyValues.daoException;
import static testutil.AnyValues.dbException;
class NoteServiceTest {
@@ -78,7 +78,7 @@ class NoteServiceTest {
@Test
void sendFailure() {
doThrow(daoException()).when(noteDao).save(any());
doThrow(dbException()).when(noteDao).save(any());
boolean success = noteService.sendNormal(AnyValues.string(), AnyValues.string(), AnyValues.string());
@@ -119,7 +119,7 @@ class NoteServiceTest {
@Test
void showNotesFailure_shouldNotSendPacket() {
var chr = Mocks.chr("mockChr");
when(noteDao.findAllByTo(any())).thenThrow(daoException());
when(noteDao.findAllByTo(any())).thenThrow(dbException());
noteService.show(chr);
@@ -140,7 +140,7 @@ class NoteServiceTest {
@Test
void deleteNoteFailure() {
when(noteDao.delete(anyInt())).thenThrow(daoException());
when(noteDao.delete(anyInt())).thenThrow(dbException());
Optional<Note> deletedNote = noteService.delete(4382);

View File

@@ -1,6 +1,6 @@
package testutil;
import database.DaoException;
import database.DatabaseException;
public class AnyValues {
@@ -16,7 +16,7 @@ public class AnyValues {
return 4;
}
public static DaoException daoException() {
return new DaoException(string(), new RuntimeException());
public static DatabaseException dbException() {
return new DatabaseException(string(), new RuntimeException());
}
}