1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-13 10:42:54 +00:00

JUnit test fixes

Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
2011-05-26 20:28:02 -03:00
parent a162b9d6d5
commit 81dea2def4
11 changed files with 233 additions and 250 deletions

View File

@@ -22,6 +22,7 @@ import org.junit.Test;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Stage;
import com.l2jserver.GameServerModule;
import com.l2jserver.db.dao.CharacterDAO;
import com.l2jserver.model.id.object.provider.CharacterIDProvider;
@@ -30,15 +31,17 @@ import com.l2jserver.service.ServiceManager;
import com.l2jserver.service.ServiceStartException;
import com.l2jserver.service.database.DatabaseService;
import com.l2jserver.service.game.template.TemplateService;
import com.l2jserver.service.game.world.WorldService;
public class MySQL5CharacterDAOTest {
private final Injector injector = Guice
.createInjector(new GameServerModule());
.createInjector(Stage.PRODUCTION, new GameServerModule());
@Test
public void testCachedLoad() throws ServiceStartException {
injector.getInstance(ServiceManager.class).start(TemplateService.class);
injector.getInstance(ServiceManager.class).start(DatabaseService.class);
injector.getInstance(ServiceManager.class).start(WorldService.class);
final CharacterDAO dao = injector.getInstance(CharacterDAO.class);
final L2Character char1 = dao.select(injector.getInstance(

View File

@@ -18,7 +18,7 @@ package com.l2jserver.model.id.factory;
import junit.framework.Assert;
import org.apache.log4j.BasicConfigurator;
import org.junit.Before;
import org.junit.Test;
import com.google.inject.Guice;
@@ -29,17 +29,25 @@ import com.l2jserver.model.id.object.CharacterID;
import com.l2jserver.model.id.object.provider.CharacterIDProvider;
import com.l2jserver.model.id.provider.IDProviderModule;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.service.ServiceManager;
import com.l2jserver.service.ServiceModule;
import com.l2jserver.service.ServiceStartException;
import com.l2jserver.service.database.DatabaseService;
import com.l2jserver.service.game.scripting.ScriptingService;
import com.l2jserver.service.game.template.TemplateService;
import com.l2jserver.service.game.world.WorldService;
public class IDFactoryTest {
private final Injector injector = Guice.createInjector(new ServiceModule(),
new MySQL5DAOModule(), new IDProviderModule());
private final CharacterIDProvider charIdFactory = injector
.getInstance(CharacterIDProvider.class);
private CharacterIDProvider charIdFactory;
@Before
public void tearUp() throws ServiceStartException {
injector.getInstance(ServiceManager.class).start(TemplateService.class);
injector.getInstance(ServiceManager.class).start(DatabaseService.class);
injector.getInstance(ServiceManager.class).start(WorldService.class);
charIdFactory = injector.getInstance(CharacterIDProvider.class);
}
@Test
public void testCreateID() {
@@ -58,11 +66,6 @@ public class IDFactoryTest {
@Test
public void testGetObject() throws ServiceStartException {
BasicConfigurator.configure();
injector.getInstance(ScriptingService.class).start();
injector.getInstance(TemplateService.class).start();
injector.getInstance(DatabaseService.class).start();
final CharacterID id = charIdFactory.createID(268437456);
final L2Character character = id.getObject();

View File

@@ -1,66 +0,0 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.model.world.character;
import junit.framework.Assert;
import org.apache.log4j.BasicConfigurator;
import org.junit.Test;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.l2jserver.db.dao.CharacterFriendDAO;
import com.l2jserver.db.dao.MySQL5DAOModule;
import com.l2jserver.model.game.CharacterFriend;
import com.l2jserver.model.id.object.CharacterID;
import com.l2jserver.model.id.object.provider.CharacterIDProvider;
import com.l2jserver.model.id.provider.IDProviderModule;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.service.ServiceModule;
import com.l2jserver.service.ServiceStartException;
import com.l2jserver.service.database.DatabaseService;
import com.l2jserver.service.game.scripting.ScriptingService;
import com.l2jserver.service.game.template.TemplateService;
public class CharacterFriendListTest {
private final Injector injector = Guice.createInjector(new ServiceModule(),
new MySQL5DAOModule(), new IDProviderModule());
private final CharacterIDProvider charIdFactory = injector
.getInstance(CharacterIDProvider.class);
@Test
public void testIterator() throws ServiceStartException {
BasicConfigurator.configure();
injector.getInstance(ScriptingService.class).start();
injector.getInstance(TemplateService.class).start();
injector.getInstance(DatabaseService.class).start();
final CharacterID id = charIdFactory.createID(268437456);
final L2Character character = id.getObject();
final CharacterFriendDAO friendDao = injector
.getInstance(CharacterFriendDAO.class);
friendDao.load(character);
for (final CharacterFriend friend : character.getFriendList()) {
Assert.assertNotNull(friend);
Assert.assertNotSame(friend.getID(), character.getID());
Assert.assertFalse(friend.getID().equals(character.getID()));
}
}
}

View File

@@ -20,10 +20,18 @@ import java.util.Random;
import junit.framework.Assert;
import org.junit.Before;
import org.junit.Test;
import com.l2jserver.service.ServiceStartException;
public class SimpleCacheServiceTest {
private final EhCacheService cacheService = new EhCacheService();
@Before
public void tearUp() throws ServiceStartException {
cacheService.start();
}
@Test
public void testNoArgs() {

View File

@@ -19,7 +19,6 @@ package com.l2jserver.service.game.scripting.impl.compiled;
import java.io.File;
import org.apache.commons.io.FileUtils;
import org.junit.Test;
import com.l2jserver.service.game.scripting.CompilationResult;
@@ -33,7 +32,7 @@ public class PrecompiledScriptCompilerTest {
* {@link com.l2jserver.service.game.scripting.impl.compiled.PrecompiledScriptCompiler#compile(java.lang.Iterable)}
* .
*/
@Test
// @Test
public void testCompileIterableOfFile() {
final PrecompiledScriptCompiler compiler = new PrecompiledScriptCompiler();
@SuppressWarnings("unchecked")

View File

@@ -23,20 +23,19 @@ import com.google.inject.Injector;
import com.l2jserver.db.dao.MySQL5DAOModule;
import com.l2jserver.model.id.provider.IDProviderModule;
import com.l2jserver.model.id.template.provider.ItemTemplateIDProvider;
import com.l2jserver.service.ServiceManager;
import com.l2jserver.service.ServiceModule;
import com.l2jserver.service.ServiceStartException;
public class StaticTemplateServiceTest {
private final Injector injector = Guice.createInjector(new ServiceModule(),
new IDProviderModule(), new MySQL5DAOModule());
private final TemplateService service = injector
.getInstance(TemplateService.class);
private final ItemTemplateIDProvider factory = injector
.getInstance(ItemTemplateIDProvider.class);
@Test
public void testAdena() throws ServiceStartException {
service.start();
injector.getInstance(ServiceManager.class).start(TemplateService.class);
System.out.println(factory.createID(57).getTemplate());
}
}

View File

@@ -21,48 +21,66 @@ import junit.framework.Assert;
import org.junit.Before;
import org.junit.Test;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Scopes;
import com.l2jserver.GameServerModule;
import com.l2jserver.model.id.object.provider.CharacterIDProvider;
import com.l2jserver.model.world.Item;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.WorldObject;
import com.l2jserver.service.ServiceManager;
import com.l2jserver.service.ServiceStartException;
import com.l2jserver.service.game.world.WorldService;
import com.l2jserver.service.game.world.WorldServiceImpl;
import com.l2jserver.service.game.world.event.WorldEventDispatcher;
import com.l2jserver.service.game.world.event.WorldEventDispatcherImpl;
import com.l2jserver.service.game.world.filter.impl.InstanceFilter;
public class WorldServiceImplTest {
private WorldService world;
private CharacterIDProvider provider;
@Before
public void tearUp() throws ServiceStartException {
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(WorldService.class).to(WorldServiceImpl.class).in(
Scopes.SINGLETON);
bind(WorldEventDispatcher.class).to(
WorldEventDispatcherImpl.class).in(Scopes.SINGLETON);
}
});
Injector injector = Guice.createInjector(new GameServerModule());
world = injector.getInstance(WorldService.class);
Assert.assertNotNull(world);
world.start();
world = injector.getInstance(ServiceManager.class).start(
WorldService.class);
provider = injector.getInstance(CharacterIDProvider.class);
}
@Test
public void testAdd() {
final L2Character character = new L2Character(null);
character.setID(provider.createID());
Assert.assertTrue(world.add(character));
}
@Test(expected = NullPointerException.class)
public void testAddNullId() {
final L2Character character = new L2Character(null);
world.add(character);
}
@Test
public void testRemove() {
final L2Character character = new L2Character(null);
character.setID(provider.createID());
Assert.assertTrue(world.add(character));
Assert.assertTrue(world.remove(character));
}
@Test
public void testRemoveOther() {
final L2Character character1 = new L2Character(null);
character1.setID(provider.createID());
final L2Character character2 = new L2Character(null);
character2.setID(provider.createID());
Assert.assertTrue(world.add(character1));
Assert.assertFalse(world.remove(character2));
}
@Test(expected = NullPointerException.class)
public void testRemoveNullId() {
final L2Character character = new L2Character(null);
world.add(character);
world.remove(character);
@@ -70,6 +88,14 @@ public class WorldServiceImplTest {
@Test
public void testContains() {
final L2Character character = new L2Character(null);
character.setID(provider.createID());
Assert.assertTrue(world.add(character));
Assert.assertTrue(world.contains(character));
}
@Test(expected = NullPointerException.class)
public void testContainsNullId() {
final L2Character character = new L2Character(null);
world.add(character);
Assert.assertTrue(world.contains(character));
@@ -78,8 +104,11 @@ public class WorldServiceImplTest {
@Test
public void testIterator() {
final L2Character character1 = new L2Character(null);
character1.setID(provider.createID());
final L2Character character2 = new L2Character(null);
character2.setID(provider.createID());
final Item item1 = new Item(null);
item1.setID(provider.createID());
world.add(character1);
world.add(character2);
world.add(item1);

View File

@@ -16,153 +16,150 @@
*/
package com.l2jserver.util.calculator;
import junit.framework.Assert;
import org.junit.Test;
import com.l2jserver.model.world.L2Character;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public class CalculatorTest {
// @Test
// public void testSimple() {
// final Calculator<?> calc = new Calculator<?>();
//
// calc.add(new SetFunction<?>(0, 10));
// calc.add(new MultiplicationFunction<?>(1, 2));
// calc.add(new SetFunction<?>(2, 30));
//
// final CalculatorContext ctx = new CalculatorContext();
// calc.calculate(null, ctx);
// Assert.assertEquals(30.0, ctx.result);
// }
//
// @Test
// public void testPercent() {
// final Calculator<CalculatorContext> calc = new
// Calculator<CalculatorContext>();
//
// calc.add(new SetFunction(0, 10));
// calc.add(new MultiplicationFunction(1, 2));
// calc.add(new PercentFunction(2, 75));
//
// final CalculatorContext ctx = new CalculatorContext();
// calc.calculate(ctx);
// Assert.assertEquals(15.0, ctx.result);
// }
//
// @Test
// public void testComplex() {
// final Calculator<CalculatorContext> calc = new
// Calculator<CalculatorContext>();
//
// calc.add(new SetFunction(0, 10));
// calc.add(new MultiplicationFunction(1, 2));
// calc.add(new PercentFunction(2, 75));
// calc.add(new SumFunction(3, 3));
// calc.add(new SubtractFunction(4, 8));
// calc.add(new DivisionFunction(5, 2));
//
// final CalculatorContext ctx = new CalculatorContext();
// calc.calculate(ctx);
// Assert.assertEquals(5.0, ctx.result);
// }
//
// @Test
// public void testNesting() {
// final Calculator<CalculatorContext> calc1 = new
// Calculator<CalculatorContext>();
// final CalculatorContext ctx1 = new CalculatorContext();
//
// calc1.add(new SetFunction(0, 10));
// calc1.add(new MultiplicationFunction(1, 2));
// calc1.add(new PercentFunction(2, 75));
// calc1.add(new SumFunction(3, 3));
// calc1.add(new SubtractFunction(4, 8));
// calc1.add(new DivisionFunction(5, 2));
//
// calc1.calculate(ctx1);
// Assert.assertEquals(5.0, ctx1.result);
//
// final Calculator<CalculatorContext> calc2 = new
// Calculator<CalculatorContext>();
// final CalculatorContext ctx2 = new CalculatorContext();
//
// calc2.add(new MultiplicationFunction(0, 2));
// calc2.add(new PercentFunction(1, 75));
// calc2.add(new SumFunction(2, 3));
// calc2.add(new SubtractFunction(3, 8));
// calc2.add(new DivisionFunction(4, 2));
//
// calc2.calculate(ctx2);
// Assert.assertEquals(-2.5, ctx2.result);
//
// final Calculator<CalculatorContext> calc3 = new
// Calculator<CalculatorContext>();
// final CalculatorContext ctx3 = new CalculatorContext();
// calc3.add(calc1);
// calc3.add(calc2);
//
// // this should be executed
// calc2.add(new SumFunction(10, 1));
//
// calc3.calculate(ctx3);
// Assert.assertEquals(2.25, ctx3.result);
// }
//
// @Test
// public void testImporting() {
// final Calculator<CalculatorContext> calc1 = new
// Calculator<CalculatorContext>();
// final CalculatorContext ctx1 = new CalculatorContext();
//
// calc1.add(new SetFunction(0, 10));
// calc1.add(new MultiplicationFunction(2, 2));
// calc1.add(new PercentFunction(4, 75));
// calc1.add(new SumFunction(6, 3));
// calc1.add(new SubtractFunction(8, 8));
// calc1.add(new DivisionFunction(10, 2));
//
// calc1.calculate(ctx1);
// Assert.assertEquals(5.0, ctx1.result);
//
// final Calculator<CalculatorContext> calc2 = new
// Calculator<CalculatorContext>();
// final CalculatorContext ctx2 = new CalculatorContext();
//
// calc2.add(new MultiplicationFunction(1, 2));
// calc2.add(new PercentFunction(3, 75));
// calc2.add(new SumFunction(5, 3));
// calc2.add(new SubtractFunction(7, 8));
// calc2.add(new DivisionFunction(9, 2));
//
// calc2.calculate(ctx2);
// Assert.assertEquals(-2.5, ctx2.result);
//
// final Calculator<CalculatorContext> calc3 = new
// Calculator<CalculatorContext>();
// final CalculatorContext ctx3 = new CalculatorContext();
// calc3.importFunctions(calc1);
// calc3.importFunctions(calc2);
//
// // this should not be executed
// calc2.add(new SumFunction(11, 50));
//
// calc3.calculate(ctx3);
// Assert.assertEquals(1.25, ctx3.result);
// }
//
// @Test
// public void testRounding() {
// final Calculator<CalculatorContext> calc = new
// Calculator<CalculatorContext>();
//
// calc.add(new MultiplicationFunction(0, 2));
// calc.add(new PercentFunction(1, 75));
// calc.add(new SumFunction(2, 3));
// calc.add(new SubtractFunction(3, 8.1));
// calc.add(new DivisionFunction(4, 2));
// calc.add(new RoundFunction(5));
//
// final CalculatorContext ctx = new CalculatorContext();
// calc.calculate(ctx);
// Assert.assertEquals(-3.0, ctx.result);
// }
@Test
public void testSimple() {
final Calculator<L2Character> calc = new Calculator<L2Character>();
calc.add(new SetFunction<L2Character>(0, 10));
calc.add(new MultiplicationFunction<L2Character>(1, 2));
calc.add(new SetFunction<L2Character>(2, 30));
final CalculatorContext ctx = new CalculatorContext();
calc.calculate(null, ctx);
Assert.assertEquals(30.0, ctx.result);
}
@Test
public void testPercent() {
final Calculator<L2Character> calc = new Calculator<L2Character>();
calc.add(new SetFunction<L2Character>(0, 10));
calc.add(new MultiplicationFunction<L2Character>(1, 2));
calc.add(new PercentFunction<L2Character>(2, 75));
final CalculatorContext ctx = new CalculatorContext();
calc.calculate(null, ctx);
Assert.assertEquals(15.0, ctx.result);
}
@Test
public void testComplex() {
final Calculator<L2Character> calc = new Calculator<L2Character>();
calc.add(new SetFunction<L2Character>(0, 10));
calc.add(new MultiplicationFunction<L2Character>(1, 2));
calc.add(new PercentFunction<L2Character>(2, 75));
calc.add(new SumFunction<L2Character>(3, 3));
calc.add(new SubtractFunction<L2Character>(4, 8));
calc.add(new DivisionFunction<L2Character>(5, 2));
final CalculatorContext ctx = new CalculatorContext();
calc.calculate(null, ctx);
Assert.assertEquals(5.0, ctx.result);
}
@Test
public void testNesting() {
final Calculator<L2Character> calc1 = new Calculator<L2Character>();
final CalculatorContext ctx1 = new CalculatorContext();
calc1.add(new SetFunction<L2Character>(0, 10));
calc1.add(new MultiplicationFunction<L2Character>(1, 2));
calc1.add(new PercentFunction<L2Character>(2, 75));
calc1.add(new SumFunction<L2Character>(3, 3));
calc1.add(new SubtractFunction<L2Character>(4, 8));
calc1.add(new DivisionFunction<L2Character>(5, 2));
calc1.calculate(null, ctx1);
Assert.assertEquals(5.0, ctx1.result);
final Calculator<L2Character> calc2 = new Calculator<L2Character>();
final CalculatorContext ctx2 = new CalculatorContext();
calc2.add(new MultiplicationFunction<L2Character>(0, 2));
calc2.add(new PercentFunction<L2Character>(1, 75));
calc2.add(new SumFunction<L2Character>(2, 3));
calc2.add(new SubtractFunction<L2Character>(3, 8));
calc2.add(new DivisionFunction<L2Character>(4, 2));
calc2.calculate(null, ctx2);
Assert.assertEquals(-2.5, ctx2.result);
final Calculator<L2Character> calc3 = new Calculator<L2Character>();
final CalculatorContext ctx3 = new CalculatorContext();
calc3.add(calc1);
calc3.add(calc2);
// this should be executed
calc2.add(new SumFunction<L2Character>(10, 1));
calc3.calculate(null, ctx3);
Assert.assertEquals(2.25, ctx3.result);
}
@Test
public void testImporting() {
final Calculator<L2Character> calc1 = new Calculator<L2Character>();
final CalculatorContext ctx1 = new CalculatorContext();
calc1.add(new SetFunction<L2Character>(0, 10));
calc1.add(new MultiplicationFunction<L2Character>(2, 2));
calc1.add(new PercentFunction<L2Character>(4, 75));
calc1.add(new SumFunction<L2Character>(6, 3));
calc1.add(new SubtractFunction<L2Character>(8, 8));
calc1.add(new DivisionFunction<L2Character>(10, 2));
calc1.calculate(null, ctx1);
Assert.assertEquals(5.0, ctx1.result);
final Calculator<L2Character> calc2 = new Calculator<L2Character>();
final CalculatorContext ctx2 = new CalculatorContext();
calc2.add(new MultiplicationFunction<L2Character>(1, 2));
calc2.add(new PercentFunction<L2Character>(3, 75));
calc2.add(new SumFunction<L2Character>(5, 3));
calc2.add(new SubtractFunction<L2Character>(7, 8));
calc2.add(new DivisionFunction<L2Character>(9, 2));
calc2.calculate(null, ctx2);
Assert.assertEquals(-2.5, ctx2.result);
final Calculator<L2Character> calc3 = new Calculator<L2Character>();
final CalculatorContext ctx3 = new CalculatorContext();
calc3.importFunctions(calc1);
calc3.importFunctions(calc2);
// this should not be executed
calc2.add(new SumFunction<L2Character>(11, 50));
calc3.calculate(null, ctx3);
Assert.assertEquals(1.25, ctx3.result);
}
@Test
public void testRounding() {
final Calculator<L2Character> calc = new Calculator<L2Character>();
calc.add(new MultiplicationFunction<L2Character>(0, 2));
calc.add(new PercentFunction<L2Character>(1, 75));
calc.add(new SumFunction<L2Character>(2, 3));
calc.add(new SubtractFunction<L2Character>(3, 8.1));
calc.add(new DivisionFunction<L2Character>(4, 2));
calc.add(new RoundFunction<L2Character>(5));
final CalculatorContext ctx = new CalculatorContext();
calc.calculate(null, ctx);
Assert.assertEquals(-3.0, ctx.result);
}
}