Java Code Examples for org.jmock.integration.junit4.JUnit4Mockery#checking()

The following examples show how to use org.jmock.integration.junit4.JUnit4Mockery#checking() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PacketHandlerImplTest.java    From AisAbnormal with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void initNoAnalyses() throws Exception {
    PropertiesConfiguration configuration = new PropertiesConfiguration();
    configuration.addProperty(CONFKEY_ANALYSIS_COG_ENABLED, false);
    configuration.addProperty(CONFKEY_ANALYSIS_SOG_ENABLED, false);
    configuration.addProperty(CONFKEY_ANALYSIS_TYPESIZE_ENABLED, false);
    configuration.addProperty(CONFKEY_ANALYSIS_DRIFT_ENABLED, false);
    configuration.addProperty(CONFKEY_ANALYSIS_SUDDENSPEEDCHANGE_ENABLED, false);
    configuration.addProperty(CONFKEY_ANALYSIS_CLOSEENCOUNTER_ENABLED, false);
    configuration.addProperty(CONFKEY_ANALYSIS_FREEFLOW_ENABLED, false);

    final JUnit4Mockery context = new JUnit4Mockery();
    Injector injectorMock = context.mock(Injector.class);

    context.checking(new Expectations() {{
    }});

    PacketHandlerImpl sut = new PacketHandlerImpl(configuration, injectorMock, null, null, null, null);
    Set<Analysis> analyses = sut.getAnalyses();

    assertEquals(0, analyses.size());
}
 
Example 2
Source File: SafetyZoneServiceTest.java    From AisAbnormal with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void testComputeSafetyZoneWithAlternativeConfigurationParameterEllipseLength() {
    JUnit4Mockery context = new JUnit4Mockery();
    Configuration configurationMock = context.mock(Configuration.class);
    context.checking(new Expectations() {{
        oneOf(configurationMock).getDouble(with(CONFKEY_SAFETYZONES_SAFETY_ELLIPSE_LENGTH));
        will(returnValue(1.0));
        oneOf(configurationMock).getDouble(with(CONFKEY_SAFETYZONES_SAFETY_ELLIPSE_BREADTH));
        will(returnValue(3.0));
        oneOf(configurationMock).getDouble(with(CONFKEY_SAFETYZONES_SAFETY_ELLIPSE_BEHIND));
        will(returnValue(0.25));
    }});

    SafetyZoneService sut = new SafetyZoneService(configurationMock);

    Ellipse safetyEllipse = sut.safetyZone(position, position, 90.0f, 0.0f, 100.0f, 15.0f, 65.0f, 5.5f);

    assertEquals(-15.0, safetyEllipse.getX(), 1e-6);
    assertEquals(-2.0, safetyEllipse.getY(), 1e-6);
    assertEquals(22.5, safetyEllipse.getBeta(), 1e-6);
    assertEquals(75.0, safetyEllipse.getAlpha(), 1e-6);
    assertEquals(0.0, safetyEllipse.getThetaDeg(), 1e-6);
}
 
Example 3
Source File: SafetyZoneServiceTest.java    From AisAbnormal with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void testComputeSafetyZoneWithAlternativeConfigurationParameterEllipseBreadth() {
    JUnit4Mockery context = new JUnit4Mockery();
    Configuration configurationMock = context.mock(Configuration.class);
    context.checking(new Expectations() {{
        oneOf(configurationMock).getDouble(with(CONFKEY_SAFETYZONES_SAFETY_ELLIPSE_LENGTH));
        will(returnValue(2.0));
        oneOf(configurationMock).getDouble(with(CONFKEY_SAFETYZONES_SAFETY_ELLIPSE_BREADTH));
        will(returnValue(5.0));
        oneOf(configurationMock).getDouble(with(CONFKEY_SAFETYZONES_SAFETY_ELLIPSE_BEHIND));
        will(returnValue(0.25));
    }});

    SafetyZoneService sut = new SafetyZoneService(configurationMock);

    Ellipse safetyEllipse = sut.safetyZone(position, position, 90.0f, 0.0f, 100.0f, 15.0f, 65.0f, 5.5f);

    assertEquals(10.0, safetyEllipse.getX(), 1e-6);
    assertEquals(-2.0, safetyEllipse.getY(), 1e-6);
    assertEquals(37.5, safetyEllipse.getBeta(), 1e-6);
    assertEquals(100.0, safetyEllipse.getAlpha(), 1e-6);
    assertEquals(0.0, safetyEllipse.getThetaDeg(), 1e-6);
}
 
Example 4
Source File: SafetyZoneServiceTest.java    From AisAbnormal with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void testComputeSafetyZoneWithAlternativeConfigurationParameterEllipseBehind() {
    JUnit4Mockery context = new JUnit4Mockery();
    Configuration configurationMock = context.mock(Configuration.class);
    context.checking(new Expectations() {{
        oneOf(configurationMock).getDouble(with(CONFKEY_SAFETYZONES_SAFETY_ELLIPSE_LENGTH));
        will(returnValue(2.0));
        oneOf(configurationMock).getDouble(with(CONFKEY_SAFETYZONES_SAFETY_ELLIPSE_BREADTH));
        will(returnValue(3.0));
        oneOf(configurationMock).getDouble(with(CONFKEY_SAFETYZONES_SAFETY_ELLIPSE_BEHIND));
        will(returnValue(0.75));
    }});

    SafetyZoneService sut = new SafetyZoneService(configurationMock);

    Ellipse safetyEllipse = sut.safetyZone(position, position, 90.0f, 0.0f, 100.0f, 15.0f, 65.0f, 5.5f);

    assertEquals(-15.0, safetyEllipse.getX(), 1e-6);
    assertEquals(-2.0, safetyEllipse.getY(), 1e-6);
    assertEquals(22.5, safetyEllipse.getBeta(), 1e-6);
    assertEquals(125.0, safetyEllipse.getAlpha(), 1e-6);
    assertEquals(0.0, safetyEllipse.getThetaDeg(), 1e-6);
}
 
Example 5
Source File: PacketHandlerImplTest.java    From AisAbnormal with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void initSelectedAnalyses() throws Exception {
    PropertiesConfiguration configuration = new PropertiesConfiguration();
    configuration.addProperty(CONFKEY_ANALYSIS_COG_ENABLED, false);
    configuration.addProperty(CONFKEY_ANALYSIS_SOG_ENABLED, false);
    configuration.addProperty(CONFKEY_ANALYSIS_TYPESIZE_ENABLED, false);
    configuration.addProperty(CONFKEY_ANALYSIS_DRIFT_ENABLED, false);
    configuration.addProperty(CONFKEY_ANALYSIS_SUDDENSPEEDCHANGE_ENABLED, true);
    configuration.addProperty(CONFKEY_ANALYSIS_CLOSEENCOUNTER_ENABLED, true);
    configuration.addProperty(CONFKEY_ANALYSIS_FREEFLOW_ENABLED, false);
    configuration.addProperty(CONFKEY_SAFETYZONES_SAFETY_ELLIPSE_LENGTH, 2.0);
    configuration.addProperty(CONFKEY_SAFETYZONES_SAFETY_ELLIPSE_BREADTH, 3.0);
    configuration.addProperty(CONFKEY_SAFETYZONES_SAFETY_ELLIPSE_BEHIND, 0.25);

    final JUnit4Mockery context = new JUnit4Mockery();
    Injector injectorMock = context.mock(Injector.class);
    EventEmittingTracker trackingServiceMock = context.mock(EventEmittingTracker.class);

    SafetyZoneService safetyZoneService = new SafetyZoneService(configuration);

    context.checking(new Expectations() {{
        ignoring(trackingServiceMock);
        oneOf(injectorMock).getInstance(with(SuddenSpeedChangeAnalysis.class)); will(returnValue(new SuddenSpeedChangeAnalysis(configuration, null, trackingServiceMock, null)));
        oneOf(injectorMock).getInstance(with(CloseEncounterAnalysis.class)); will(returnValue(new CloseEncounterAnalysis(configuration, null, trackingServiceMock, null, safetyZoneService)));
    }});

    PacketHandlerImpl sut = new PacketHandlerImpl(configuration, injectorMock, null, null, null, null);

    Set<Analysis> analyses = sut.getAnalyses();
    assertEquals(2, analyses.size());
    assertEquals(false, analyses.stream().anyMatch(a -> a instanceof CourseOverGroundAnalysis));
    assertEquals(false, analyses.stream().anyMatch(a -> a instanceof SpeedOverGroundAnalysis));
    assertEquals(false, analyses.stream().anyMatch(a -> a instanceof ShipTypeAndSizeAnalysis));
    assertEquals(false, analyses.stream().anyMatch(a -> a instanceof DriftAnalysis));
    assertEquals(true, analyses.stream().anyMatch(a -> a instanceof SuddenSpeedChangeAnalysis));
    assertEquals(true, analyses.stream().anyMatch(a -> a instanceof CloseEncounterAnalysis));
    assertEquals(false, analyses.stream().anyMatch(a -> a instanceof FreeFlowAnalysis));
}
 
Example 6
Source File: SafetyZoneServiceTest.java    From AisAbnormal with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Before
public void setup() {
    JUnit4Mockery context = new JUnit4Mockery();
    Configuration configurationMock = context.mock(Configuration.class);
    context.checking(new Expectations() {{
        oneOf(configurationMock).getDouble(with(CONFKEY_SAFETYZONES_SAFETY_ELLIPSE_LENGTH));
        will(returnValue(2.0));
        oneOf(configurationMock).getDouble(with(CONFKEY_SAFETYZONES_SAFETY_ELLIPSE_BREADTH));
        will(returnValue(3.0));
        oneOf(configurationMock).getDouble(with(CONFKEY_SAFETYZONES_SAFETY_ELLIPSE_BEHIND));
        will(returnValue(0.25));
    }});
    sut = new SafetyZoneService(configurationMock);
}
 
Example 7
Source File: DocumentChangesCollectorTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  myCollector = new DocumentChangesCollector();
  buffer = new StringBuilder(TEXT);
  myCollector.setCollectChanges(true);
  myMockery = new JUnit4Mockery() {{
    setImposteriser(ClassImposteriser.INSTANCE);
  }};

  myDocument = myMockery.mock(Document.class);

  myMockery.checking(new Expectations() {{
    allowing(myDocument).getTextLength(); will(returnValue(TEXT.length()));
  }});
}
 
Example 8
Source File: PathMacroManagerTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Before
public final void setupApplication() throws Exception {
  // in fact the test accesses extension points so it rather should be converted to a platform one
  assumeNotNull(ApplicationManager.getApplication());

  context = new JUnit4Mockery();
  context.setImposteriser(ClassImposteriser.INSTANCE);
  myApplication = context.mock(ApplicationEx.class, "application");

  context.checking(new Expectations() {
    {
      allowing(myApplication).isUnitTestMode();
      will(returnValue(false));

      // some tests leave invokeLater()'s after them
      allowing(myApplication).invokeLater(with(any(Runnable.class)), with(any(ModalityState.class)));

      allowing(myApplication).runReadAction(with(any(Runnable.class)));
      will(new Action() {
        @Override
        public void describeTo(final Description description) {
          description.appendText("runs runnable");
        }

        @Override
        @javax.annotation.Nullable
        public Object invoke(final Invocation invocation) throws Throwable {
          ((Runnable)invocation.getParameter(0)).run();
          return null;
        }
      });
    }
  });
}
 
Example 9
Source File: ExportHandlerTest.java    From pentaho-aggdesigner with GNU General Public License v2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  controller = new ExportHandler();
  context = new JUnit4Mockery() {
    {
      // only here to mock types that are not interfaces
      setImposteriser(ClassImposteriser.INSTANCE);
    }
  };
  doc = context.mock(Document.class);
  container = context.mock(XulDomContainer.class);
  outputService = context.mock(OutputService.class);
  executor = context.mock(SqlExecutor.class);

  aggList = new AggListImpl();

  controller.setOutputService(outputService);
  controller.setAggList(aggList);
  controller.setDdlDmlExecutor(executor);

  // need some expectations here as setXulDomContainer calls getDocumentRoot on the container
  context.checking(new Expectations() {
    {
      one(container).getDocumentRoot();
      will(returnValue(doc));
    }
  });

  controller.setXulDomContainer(container);

}
 
Example 10
Source File: ConnectionControllerTest.java    From pentaho-aggdesigner with GNU General Public License v2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  controller = new ConnectionController();
  context = new JUnit4Mockery();
  doc = context.mock(Document.class);
  container = context.mock(XulDomContainer.class);
  dataHandler = context.mock(XulEventHandler.class);
  model = context.mock(ConnectionModel.class);
  controller.setConnectionModel(model);
  workspace = new Workspace();
  controller.setWorkspace(workspace);
  outputService = context.mock(OutputService.class);
  controller.setOutputService(outputService);
  aSchemaProvider = context.mock(SchemaProviderUiExtension.class);
  cubeNames = Arrays.asList("testCube1", "testCube2");
  providerModel = context.mock(SchemaModel.class);

  // need some expectations here as setXulDomContainer calls getDocumentRoot on the container
  context.checking(new Expectations() {
    {
      one(container).getDocumentRoot();
      will(returnValue(doc));
      allowing(doc).invokeLater(with(any(Runnable.class))); //don't care if the controller uses invokeLater or not
    }
  });

  controller.setXulDomContainer(container);
  controller.setDataHandler(dataHandler);
}
 
Example 11
Source File: AggListControllerTest.java    From pentaho-aggdesigner with GNU General Public License v2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  controller = new AggListController();
  context = new JUnit4Mockery() {
    {
      // only here to mock types that are not interfaces
      setImposteriser(ClassImposteriser.INSTANCE);
    }
  };
  doc = context.mock(Document.class);
  container = context.mock(XulDomContainer.class);
  outputService = context.mock(OutputService.class);
  workspace = context.mock(Workspace.class);
  connModel = context.mock(ConnectionModel.class);
  schema = context.mock(Schema.class);
  uiExt = context.mock(AlgorithmUiExtension.class);
  algo = context.mock(Algorithm.class);
  aggregateSummaryModel = context.mock(AggregateSummaryModel.class);

  aggList = new AggListImpl();

  controller.setOutputService(outputService);
  controller.setAggList(aggList);
  controller.setAlgorithmUiExtension(uiExt);
  controller.setAlgorithm(algo);

  // need some expectations here as setXulDomContainer calls getDocumentRoot on the container
  context.checking(new Expectations() {
    {
      one(container).getDocumentRoot();
      will(returnValue(doc));
    }
  });

  controller.setXulDomContainer(container);
  controller.setWorkspace(workspace);
  controller.setConnectionModel(connModel);
  controller.setAggregateSummaryModel(aggregateSummaryModel);
  
}
 
Example 12
Source File: PacketHandlerImplTest.java    From AisAbnormal with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Test
public void initAllAnalyses() throws Exception {
    PropertiesConfiguration configuration = new PropertiesConfiguration();
    configuration.addProperty(CONFKEY_ANALYSIS_COG_ENABLED, true);
    configuration.addProperty(CONFKEY_ANALYSIS_SOG_ENABLED, true);
    configuration.addProperty(CONFKEY_ANALYSIS_TYPESIZE_ENABLED, true);
    configuration.addProperty(CONFKEY_ANALYSIS_DRIFT_ENABLED, true);
    configuration.addProperty(CONFKEY_ANALYSIS_SUDDENSPEEDCHANGE_ENABLED, true);
    configuration.addProperty(CONFKEY_ANALYSIS_CLOSEENCOUNTER_ENABLED, true);
    configuration.addProperty(CONFKEY_ANALYSIS_FREEFLOW_ENABLED, true);
    configuration.addProperty(CONFKEY_ANALYSIS_FREEFLOW_BBOX, new Integer[] {1, 2, 3, 4});
    configuration.addProperty(CONFKEY_SAFETYZONES_SAFETY_ELLIPSE_LENGTH, 2.0);
    configuration.addProperty(CONFKEY_SAFETYZONES_SAFETY_ELLIPSE_BREADTH, 3.0);
    configuration.addProperty(CONFKEY_SAFETYZONES_SAFETY_ELLIPSE_BEHIND, 0.25);

    final JUnit4Mockery context = new JUnit4Mockery();
    Injector injectorMock = context.mock(Injector.class);
    EventEmittingTracker trackingServiceMock = context.mock(EventEmittingTracker.class);

    SafetyZoneService safetyZoneService = new SafetyZoneService(configuration);

    context.checking(new Expectations() {{
        ignoring(trackingServiceMock);
        oneOf(injectorMock).getInstance(with(CourseOverGroundAnalysis.class)); will(returnValue(new CourseOverGroundAnalysis(configuration, null, null, trackingServiceMock, null, null)));
        oneOf(injectorMock).getInstance(with(SpeedOverGroundAnalysis.class)); will(returnValue(new SpeedOverGroundAnalysis(configuration, null, null, trackingServiceMock, null, null)));
        oneOf(injectorMock).getInstance(with(ShipTypeAndSizeAnalysis.class)); will(returnValue(new ShipTypeAndSizeAnalysis(configuration, null, null, trackingServiceMock, null, null)));
        oneOf(injectorMock).getInstance(with(DriftAnalysis.class)); will(returnValue(new DriftAnalysis(configuration, null, trackingServiceMock, null)));
        oneOf(injectorMock).getInstance(with(SuddenSpeedChangeAnalysis.class)); will(returnValue(new SuddenSpeedChangeAnalysis(configuration, null, trackingServiceMock, null)));
        oneOf(injectorMock).getInstance(with(CloseEncounterAnalysis.class)); will(returnValue(new CloseEncounterAnalysis(configuration, null, trackingServiceMock, null, safetyZoneService)));
        oneOf(injectorMock).getInstance(with(FreeFlowAnalysis.class)); will(returnValue(new FreeFlowAnalysis(configuration, null, trackingServiceMock, null)));
    }});

    PacketHandlerImpl sut = new PacketHandlerImpl(configuration, injectorMock, null, null, null, null);

    Set<Analysis> analyses = sut.getAnalyses();
    assertEquals(7, analyses.size());
    assertEquals(true, analyses.stream().anyMatch(a -> a instanceof CourseOverGroundAnalysis));
    assertEquals(true, analyses.stream().anyMatch(a -> a instanceof SpeedOverGroundAnalysis));
    assertEquals(true, analyses.stream().anyMatch(a -> a instanceof ShipTypeAndSizeAnalysis));
    assertEquals(true, analyses.stream().anyMatch(a -> a instanceof DriftAnalysis));
    assertEquals(true, analyses.stream().anyMatch(a -> a instanceof SuddenSpeedChangeAnalysis));
    assertEquals(true, analyses.stream().anyMatch(a -> a instanceof CloseEncounterAnalysis));
    assertEquals(true, analyses.stream().anyMatch(a -> a instanceof FreeFlowAnalysis));
}
 
Example 13
Source File: MondrianFileSchemaProviderTest.java    From pentaho-aggdesigner with GNU General Public License v2.0 4 votes vote down vote up
@Before
public void setUp() throws Exception {
  /*
   * In this integration test, we want to mock only the XUL framework, all other components
   * we want to be the "real" ones.  This will allow us to test application behavior without
   * dependency on a UI.
   */
  context = new JUnit4Mockery();
  doc = context.mock(Document.class);
  container = context.mock(XulDomContainer.class);

  // need some expectations here as setXulDomContainer calls getDocumentRoot on the container
  context.checking(new Expectations() {
    {
      allowing(container).getDocumentRoot();
      will(returnValue(doc));
      allowing(container).addEventHandler(with(any(XulEventHandler.class)));
      allowing(doc).addOverlay(with(any(String.class)));
      ignoring(container);
      allowing(doc).getElementById(with(aNonNull(String.class)));
      will(returnValue(context.mock(XulComponent.class, Long.toString(System.currentTimeMillis()))));
      allowing(doc).addInitializedBinding(with(any(Binding.class)));
      allowing(doc).invokeLater(with(any(Runnable.class))); //don't care if the controller uses invokeLater or not, this is UI stuff
    }
  });

  schemaProvider.setXulDomContainer(container);


  //In order to really make this an integration test, there needs to be a BindingFactory that is injected into the controller
  //so we can mock or stub it out and allow the object->object bindings to actually be bound while the xulcomponent bindings
  //are consumed.  Here we are proxying the BindingFactory to acheive this.
  bindingFactory.setDocument(doc);
  //setup the proxy binding factory that will ignore all XUL stuff
  XulSupressingBindingFactoryProxy proxy = new XulSupressingBindingFactoryProxy();
  proxy.setProxiedBindingFactory(bindingFactory);
  schemaProvider.setBindingFactory(proxy);

  schemaProvider.onLoad();

  eventRecorder = new EventRecorder();
  eventRecorder.setLogging(true);
  eventRecorder.record(schemaProvider);
}
 
Example 14
Source File: ConnectionControllerITest.java    From pentaho-aggdesigner with GNU General Public License v2.0 4 votes vote down vote up
@Before
public void setUp() throws Exception {
  /*
   * In this integration test, we want to mock only the XUL framework, all other components
   * we want to be the "real" ones.  This will allow us to test application behavior without
   * dependency on a UI.
   */
  context = new JUnit4Mockery();
  eventRecorder = new EventRecorder();
  doc = context.mock(Document.class);
  container = context.mock(XulDomContainer.class);

  // need some expectations here as setXulDomContainer calls getDocumentRoot on the container
  context.checking(new Expectations() {
    {
      allowing(container).getDocumentRoot();
      will(returnValue(doc));
      allowing(container).addEventHandler(with(any(XulEventHandler.class)));
      allowing(doc).addOverlay(with(any(String.class)));
      ignoring(container);
      allowing(doc).getElementById(with(aNonNull(String.class)));
      will(returnValue(context.mock(XulComponent.class, Long.toString(System.currentTimeMillis()))));
      allowing(doc).addInitializedBinding(with(any(Binding.class)));
      allowing(doc).invokeLater(with(any(Runnable.class))); //don't care if the controller uses invokeLater or not, this is UI stuff
    }
  });

  controller.setXulDomContainer(container);


  //In order to really make this an integration test, there needs to be a BindingFactory that is injected into the controller
  //so we can mock or stub it out and allow the object->object bindings to actually be bound while the xulcomponent bindings
  //are consumed.  Here we are proxying the BindingFactory to achieve this.
  bindingFactory.setDocument(doc);
  //setup the proxy binding factory that will ignore all XUL stuff
  XulSupressingBindingFactoryProxy proxy = new XulSupressingBindingFactoryProxy();
  proxy.setProxiedBindingFactory(bindingFactory);
  controller.setBindingFactory(proxy);

  for(MondrianFileSchemaProvider provider : mondrianFileSchemaProviders) {
    provider.setXulDomContainer(container);
    provider.setBindingFactory(proxy);
  }
  // this model gets reused across tests.  Revert to default value.
  model.setApplySchemaSourceEnabled( false );
}