Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LiveClassFactory initial tests #28

Merged
merged 8 commits into from
Aug 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ bin/
*.iws
*.iml
*.ipr
.vscode/

### NetBeans ###
nbproject/private/
Expand Down
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ language: java
jdk:
- oraclejdk8
script:
- cd LiveProg
- mvn install
- mvn test
- mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V
- mvn test -B -V
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ public String getColumnName(int column)
switch ( column )
{
case 0: return "Nome";
case 1: return "Vers�o de Produ��o";
case 2: return "Vers�o de Testes";
case 1: return "Versão de Produção";
case 2: return "Versão de Testes";
default: return "";
}
}
Expand Down
129 changes: 87 additions & 42 deletions src/test/java/org/esfinge/liveprog/LiveClassFactoryTest.java
Original file line number Diff line number Diff line change
@@ -1,58 +1,103 @@
package org.esfinge.liveprog;

import org.esfinge.liveprog.monitor.FileSystemMonitor;
import org.mockito.Mockito;

public class LiveClassFactoryTest {
FileSystemMonitor monitorMock = Mockito.mock(FileSystemMonitor.class);
LiveClassLoader loaderMock = Mockito.mock(LiveClassLoader.class);

/*
import org.esfinge.liveprog.db.ILiveClassDB;
import org.esfinge.liveprog.instrumentation.ClassInfo;
import org.esfinge.liveprog.instrumentation.inspector.InspectorHelper;
import org.junit.Assert;
import org.junit.Test;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.never;

public class LiveClassFactoryTest {

/**
* Creates a live object and verifies if updated
*/
@Test
public void testLiveClassFactory() {
public void testCreateObjectInTestMode() {
try {
LiveClassFactory factory = new LiveClassFactory(monitorMock);
Mockito.verify(monitorMock).setObserver(factory);
ILiveClassDB dbMock = mock(ILiveClassDB.class);

LiveClassFactory factory = new LiveClassFactory(dbMock);

ClassA aClass = factory.createLiveObjectInTestMode(ClassA.class);

verify(dbMock, times(1)).getLiveClass(eq(ClassA.class.getName()), eq(true));
verify(dbMock, times(1)).saveLiveClass(eq(ClassA.class.getName()), any());
reset(dbMock);

Assert.assertEquals("Live object not of ClassA.", (new ClassA()).getName(), aClass.getName());

ClassInfo bInfo = (new InspectorHelper()).inspect(ClassB.class);
factory.liveClassUpdated(ClassA.class.getName(), bInfo);

Assert.assertEquals("Live object not of ClassB.", (new ClassB()).getName(), aClass.getName());

verify(dbMock, times(1)).saveLiveClass(eq(ClassA.class.getName()), eq(bInfo));
reset(dbMock);

ClassA a2Class = factory.createLiveObjectInTestMode(ClassA.class);
Assert.assertEquals("New live object not of ClassB.", (new ClassB()).getName(), a2Class.getName());

verify(dbMock, never()).saveLiveClass(any(), any());
reset(dbMock);

ClassA a3Class = factory.createLiveObject(ClassA.class);
Assert.assertEquals("New live object not of ClassA, should not be updated.", (new ClassA()).getName(),
a3Class.getName());

verify(dbMock, times(1)).saveLiveClass(any(), any());
reset(dbMock);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}

/**
* Creates a live object not in test mode and verifies if updated
*/
@Test
public void testCreateObject() {
public void testCreateObjectInProductionMode() {
try {
Mockito
.when(loaderMock.loadUpdatedClass(Mockito.any()))
.then(new Answer<Class<?>>() {
@Override
public Class<?> answer(InvocationOnMock invocation) throws Throwable {
return ClassB.class;
}
});

ClassInstrumentation instrumentationMock = Mockito.mock(ClassInstrumentation.class);
Mockito
.when(instrumentationMock.getClassName())
.then(new Answer<String>() {
@Override
public String answer(InvocationOnMock invocation) throws Throwable {
return ClassA.class.getName();
}
});

LiveClassFactory factory = new LiveClassFactory(monitorMock,loaderMock);
ClassA a = factory.createObject(ClassA.class);

factory.classFileUpdated(instrumentationMock);

Mockito
.verify(loaderMock)
.loadUpdatedClass(Mockito.any());

Assert.assertEquals("ClassB", a.getName());
ILiveClassDB dbMock = mock(ILiveClassDB.class);

LiveClassFactory factory = new LiveClassFactory(dbMock);

ClassA aClass = factory.createLiveObject(ClassA.class);

verify(dbMock, times(1)).getLiveClass(eq(ClassA.class.getName()), eq(false));
verify(dbMock, times(1)).saveLiveClass(eq(ClassA.class.getName()), any());
reset(dbMock);

Assert.assertEquals("Live object not of ClassA.", (new ClassA()).getName(), aClass.getName());

ClassInfo bInfo = (new InspectorHelper()).inspect(ClassB.class);
factory.liveClassUpdated(ClassA.class.getName(), bInfo);

Assert.assertEquals("Live object not of ClassA, should not be updated.", (new ClassA()).getName(), aClass.getName());

verify(dbMock, times(1)).saveLiveClass(eq(ClassA.class.getName()), eq(bInfo));
reset(dbMock);

ClassA a2Class = factory.createLiveObject(ClassA.class);
Assert.assertEquals("New live object not of ClassA, should not be updated.", (new ClassA()).getName(), a2Class.getName());

verify(dbMock, never()).saveLiveClass(any(), any());
reset(dbMock);

ClassA a3Class = factory.createLiveObjectInTestMode(ClassA.class);
Assert.assertEquals("New live object not of ClassB, should be updated.", (new ClassB()).getName(),
a3Class.getName());

verify(dbMock, never()).saveLiveClass(any(), any());
reset(dbMock);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
*/
}