MobSkillFactory throws exception instead of returning null

This commit is contained in:
P0nk
2022-09-07 19:25:30 +02:00
parent 319d65a0c3
commit df5159e34c
3 changed files with 6 additions and 8 deletions

View File

@@ -7327,9 +7327,7 @@ public class Character extends AbstractCharacterObject {
final long length = rs.getInt("length"); final long length = rs.getInt("length");
MobSkill ms = MobSkillFactory.getMobSkill(MobSkillType.from(skillid), skilllv); MobSkill ms = MobSkillFactory.getMobSkill(MobSkillType.from(skillid), skilllv);
if (ms != null) { loadedDiseases.put(disease, new Pair<>(length, ms));
loadedDiseases.put(disease, new Pair<>(length, ms));
}
} }
} }
} }

View File

@@ -58,7 +58,9 @@ public class MobSkillFactory {
readLock.unlock(); readLock.unlock();
} }
return loadMobSkill(type, level).orElse(null); return loadMobSkill(type, level).orElseThrow(
() -> new IllegalArgumentException("No MobSkill exists for type %s, level %d".formatted(type, level))
);
} }
private static Optional<MobSkill> loadMobSkill(final MobSkillType type, final int level) { private static Optional<MobSkill> loadMobSkill(final MobSkillType type, final int level) {

View File

@@ -61,10 +61,8 @@ class MobSkillFactoryTest {
} }
@Test @Test
void shouldReturnNullForNonExistingMobSkill() { void shouldThrowExceptionOnNonExisting() {
MobSkill mobSkill = MobSkillFactory.getMobSkill(MobSkillType.DEFENSE_UP, 1); assertThrows(IllegalArgumentException.class, () -> MobSkillFactory.getMobSkill(MobSkillType.DEFENSE_UP, 1));
assertNull(mobSkill);
} }
} }