rmonico/Neutrino — Issue #6: Problema com package
Author: guerraem
Created: 2011-12-15 20:58:01+00:00
State: open

Deu esse erro:

java.lang.ClassCastException: org.eclipse.jdt.core.dom.PackageBinding cannot be cast to org.eclipse.jdt.core.dom.ITypeBinding
at org.ita.neutrino.astparser.SourceFileParser$ImportVisitor.visit(SourceFileParser.java:44)
at org.eclipse.jdt.core.dom.ImportDeclaration.accept0(ImportDeclaration.java:220)
at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2480)
at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2551)
at org.eclipse.jdt.core.dom.CompilationUnit.accept0(CompilationUnit.java:218)
at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2480)
at org.ita.neutrino.astparser.SourceFileParser.populateImportList(SourceFileParser.java:176)
at org.ita.neutrino.astparser.SourceFileParser.parse(SourceFileParser.java:166)
at org.ita.neutrino.astparser.ASTParser.parseAllSourceFilesInWorkspace(ASTParser.java:118)
at org.ita.neutrino.astparser.ASTParser.parse(ASTParser.java:72)
at org.ita.neutrino.testsmells.core.EclipseTestSmellDetector.getParsedCode(EclipseTestSmellDetector.java:89)
at org.ita.neutrino.testsmells.core.EclipseTestSmellDetector.run(EclipseTestSmellDetector.java:61)
at org.ita.neutrino.testsmells.core.EclipseTestSmellDetector.run(EclipseTestSmellDetector.java:51)
at org.ita.neutrino.testsmells.ActionController.runDetection(ActionController.java:51)
at org.ita.neutrino.testsmells.ActionController.run(ActionController.java:42)
at org.eclipse.ui.internal.PluginAction.runWithEvent(PluginAction.java:251)
at org.eclipse.ui.internal.WWinPluginAction.runWithEvent(WWinPluginAction.java:229)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584)
at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:501)
at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4066)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3657)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2640)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2604)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2438)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:671)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:664)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:115)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:620)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:575)
at org.eclipse.equinox.launcher.Main.run(Main.java:1408)

Com esse código:

package tests;

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.List;

import codigosFonte.*;

import org.junit.Before;
import org.junit.Test;

public class IdentifiableDaoProxyTest {
IdentifiableDao mock;
List aux20,aux50,vazio;
MockIdentifiable mi, mi99, mi21, mi19;
IdentifiableDaoProxy idp;

@Before
public void setarVariaveis(){
vazio = new ArrayList();
aux20 = new ArrayList();
for(int i=0;i<20;i++){
aux20.add(new MockIdentifiable(i));
}
aux50 = new ArrayList();
for(int i=100;i<150;i++){
aux50.add(new MockIdentifiable(i));
}
mi99 = new MockIdentifiable(99);
mi21 = new MockIdentifiable(21);
}

@Test
public void bancoVazioTest(){
mock = new IdentifiableDao(vazio);
idp = new IdentifiableDaoProxy(mock);
assertEquals(idp.list(), vazio);
}

@Test
public void getByIDTest1(){
mock = new IdentifiableDao(aux20);
idp = new IdentifiableDaoProxy(mock);
assertEquals(idp.getByID(1), mock.getByID(1));
assertEquals(idp.getByID(12), mock.getByID(12));
assertEquals(idp.getByID(22), mock.getByID(22));
}

@Test
public void getByIDTest2(){
mock = new IdentifiableDao(aux50);
idp = new IdentifiableDaoProxy(mock);
assertEquals(idp.getByID(100), mock.getByID(100));
assertEquals(idp.getByID(142), mock.getByID(142));
assertEquals(idp.getByID(92), mock.getByID(92));
}

@Test
public void updateTestConsistencia(){
mock = new IdentifiableDao(aux50);
idp = new IdentifiableDaoProxy(mock);
idp.insert(mi99);
assertEquals(idp.getByID(99), mock.getByID(99));
idp.update(mi99);
assertEquals(idp.getByID(1099), mock.getByID(1099));
}

@Test
public void updateTestObjeto(){
mock = new IdentifiableDao(aux50);
idp = new IdentifiableDaoProxy(mock);
idp.insert(mi21);
assertEquals(idp.getByID(21), mi21);
idp.update(mi21);
assertEquals(mi21.getID(), 1021);
assertEquals(idp.getByID(1021), mi21);
}

@Test
public void insertTestConsitencia(){
mock = new IdentifiableDao(aux20);
idp = new IdentifiableDaoProxy(mock);
mi = new MockIdentifiable(50);
idp.insert(mi);
assertEquals(idp.getByID(50), mock.getByID(50));
}

@Test
public void insertTestObjeto(){
mock = new IdentifiableDao(aux20);
idp = new IdentifiableDaoProxy(mock);
mi = new MockIdentifiable(50);
idp.insert(mi);
assertEquals(idp.getByID(50), mi);
}

@Test
public void listTestRetornarPrimeira(){
mock = new IdentifiableDao(aux50);
idp = new IdentifiableDaoProxy(mock);
assertEquals(idp.list(), mock.list());
mock.insert(mi21);
assertFalse(idp.list() == mock.list());
}

@Test
public void listTestObjeto(){
mock = new IdentifiableDao(aux20);
idp = new IdentifiableDaoProxy(mock);
assertEquals(idp.list(), mock.list());
mock.insert(mi21);
mock.insert(mi99);
assertFalse(idp.list().contains(mi21));
assertFalse(idp.list().contains(mi99));
}

@Test
public void deleteTestConsitencia1(){
mock = new IdentifiableDao(aux50);
idp = new IdentifiableDaoProxy(mock);
Integer id = 19;
idp.delete(id);
assertEquals(idp.getByID(id), mock.getByID(id));
assertEquals(null, idp.getByID(id));
assertEquals(null, mock.getByID(id));
}

@Test
public void deleteTestConsistencia2(){
mock = new IdentifiableDao(aux20);
idp = new IdentifiableDaoProxy(mock);
mi = new MockIdentifiable(50);
Integer id = 10;
idp.delete(id);
assertEquals(idp.getByID(id), mock.getByID(id));
assertEquals(null, idp.getByID(id));
assertEquals(null, mock.getByID(id));
}

@Test
public void deleteExceptionTest1(){
mock = new IdentifiableDao(aux20);
idp = new IdentifiableDaoProxy(mock);
assertEquals(mock.list(),idp.list());
mock.delete(2);
mock.delete(3);
mock.delete(4);
assertNotSame(mock.list(),idp.list());
idp.delete(2);
idp.list();
assertEquals(mock.list(),idp.list());
}

@Test
public void insertExceptionTest2(){
mock = new IdentifiableDao(aux20);
idp = new IdentifiableDaoProxy(mock);
assertEquals(mock.list(),idp.list());
mock.delete(4);
assertNotSame(mock.list(),idp.list());
idp.insert(null);
assertEquals(mock.list(),idp.list());
}

@Test
public void updateExceptionTest3(){
mock = new IdentifiableDao(aux50);
idp = new IdentifiableDaoProxy(mock);
assertEquals(mock.list(),idp.list());
mock.delete(120);
mock.delete(122);
mock.delete(114);
assertNotSame(mock.list(),idp.list());
idp.update(idp.getByID(100));
assertNull(idp.getByID(100));
assertNotSame(mock.list(),idp.list());
idp.update(idp.getByID(120));
assertEquals(mock.list(),idp.list());
}

}