Skip to content

Commit

Permalink
Merging with Rima's tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michał Kit committed Nov 9, 2013
1 parent abb0955 commit d1706b7
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public CloningKnowledgeManager(Object knowledge) {
* )
*/
@Override
public ValueSet get(Collection<KnowledgePath> knowledgePaths)
public synchronized ValueSet get(Collection<KnowledgePath> knowledgePaths)
throws KnowledgeNotFoundException {
return cloner.deepClone(super.get(knowledgePaths));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public CloningKnowledgeManagerContainer() {
}

@Override
public KnowledgeManager createReplicaFor(KnowledgeManager km) {
public synchronized KnowledgeManager createReplicaFor(KnowledgeManager km) {
if (!replicas.contains(km)) {
KnowledgeManager result = cloner.deepClone(km);
replicas.add(result);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
package cz.cuni.mff.d3s.deeco.knowledge;

import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.MockitoAnnotations.initMocks;

import static org.mockito.Matchers.any;
import java.util.LinkedList;
import java.util.List;

import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;

/**
* @author Rima Al Ali <alali@d3s.mff.cuni.cz>
* @author Michal Kit <kit@d3s.mff.cuni.cz>
*
*/
Expand Down Expand Up @@ -81,11 +85,45 @@ public void notifyReplicaRemovedTest() {
tested.registerReplicaListener(replicaListener);
tested.registerLocalListener(localListener);
// and WHEN a replica of a knowledge manager has been removed
KnowledgeManager replica = tested.createReplicaFor(any(KnowledgeManager.class));
KnowledgeManager replica = tested
.createReplicaFor(any(KnowledgeManager.class));
tested.removeReplica(replica);
// THEN the listener is notified about this fact
verify(replicaListener).replicaRemoved(replica);
// and none of the local listeners is notified
verifyZeroInteractions(localListener);
}

@Test
public void getLocalsTest() {
// WHEN a set of local knowledge managers has been created within the
// container instance
List<KnowledgeManager> locals = new LinkedList<>();
locals.add(tested.createLocal());
locals.add(tested.createLocal());
locals.add(tested.createLocal());
// WHEN the container is accessed for all local knowledge managers
List<KnowledgeManager> containerLocals = tested.getLocals();
// THEN the container returns all local knowledge managers created
// before
assertEquals(locals, containerLocals);
}

@Test
public void getReplicasTest() {
// WHEN a set of replica knowledge managers has been created within the
// container instance
List<KnowledgeManager> replicas = new LinkedList<>();
KnowledgeManager km = mock(KnowledgeManager.class);
replicas.add(tested.createReplicaFor(km));
km = mock(KnowledgeManager.class);
replicas.add(tested.createReplicaFor(km));
km = mock(KnowledgeManager.class);
replicas.add(tested.createReplicaFor(km));
// WHEN the container is accessed for all replica knowledge managers
List<KnowledgeManager> containerReplicas = tested.getReplicas();
// THEN the container returns all replica knowledge managers created
// before
assertEquals(replicas, containerReplicas);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cz.cuni.mff.d3s.deeco.knowledge;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
Expand All @@ -19,6 +20,7 @@
import cz.cuni.mff.d3s.deeco.model.runtime.api.KnowledgeChangeTrigger;

/**
* @author Rima Al Ali <alali@d3s.mff.cuni.cz>
* @author Michal Kit <kit@d3s.mff.cuni.cz>
*
*/
Expand Down Expand Up @@ -75,7 +77,11 @@ public void getOtherKnowledgeManagersTest() {
// KnowledgeManagerView instance

assertTrue(result.size() == 2);
assertTrue(!result.contains(knowledgeManager));
List<KnowledgeManager> expectedResult = new LinkedList<>();
expectedResult.addAll(locals);
expectedResult.addAll(replicas);
expectedResult.remove(knowledgeManager);
assertEquals(expectedResult, result);

}

Expand Down

0 comments on commit d1706b7

Please sign in to comment.