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

The following examples show how to use org.jmock.integration.junit4.JUnit4Mockery#mock() . 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: EntryParserImplTest.java    From google-sites-liberation with Apache License 2.0 6 votes vote down vote up
@Before
public void before() {
  context = new JUnit4Mockery() {{
    setImposteriser(ClassImposteriser.INSTANCE);
  }};
  authorParser = context.mock(AuthorParser.class);
  contentParser = context.mock(ContentParser.class);
  dataParser = context.mock(DataParser.class);
  fieldParser = context.mock(FieldParser.class);
  summaryParser = context.mock(SummaryParser.class);
  titleParser = context.mock(TitleParser.class);
  updatedParser = context.mock(UpdatedParser.class);
  entryParser = new EntryParserImpl(authorParser, contentParser, dataParser,
      fieldParser, summaryParser, titleParser, 
      updatedParser);
  try {
    document = DocumentBuilderFactory.newInstance()
        .newDocumentBuilder().newDocument();
  } catch (ParserConfigurationException e) {
    fail("Failure to create test document");
  }
}
 
Example 2
Source File: AbstractMondrianSchemaValidatorTestBase.java    From pentaho-aggdesigner with GNU General Public License v2.0 6 votes vote down vote up
public void setUp() throws Exception {
  context = new JUnit4Mockery();
  schema = loadSchema("/FoodMart.xml");
  if (null == schema) {
    // end the test
    throw new RuntimeException("unable to load schema from file");
  }
  conn = context.mock(Connection.class);
  meta = context.mock(DatabaseMetaData.class);
  rsSalesFact1997PrimaryKeys = context.mock(ResultSet.class, "rsSalesFact1997PrimaryKeys"); //$NON-NLS-1$
  rsStorePrimaryKeys = context.mock(ResultSet.class, "rsStorePrimaryKeys"); //$NON-NLS-1$
  rsSalesFact1997ForeignKey = context.mock(ResultSet.class, "rsSalesFact1997ForeignKey"); //$NON-NLS-1$
  stmt = context.mock(Statement.class, "stmt");
  rsCount = context.mock(ResultSet.class, "rsCount");
  v1 = context.mock(MondrianSchemaValidator.class, "v1");
  v2 = context.mock(MondrianSchemaValidator.class, "v2");
  v3 = context.mock(MondrianSchemaValidator.class, "v3");
  v4 = context.mock(MondrianSchemaValidator.class, "v4");
  v5 = context.mock(MondrianSchemaValidator.class, "v5");
}
 
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 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 4
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 5
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 6
Source File: PageExporterImplTest.java    From google-sites-liberation with Apache License 2.0 6 votes vote down vote up
@Before
public void before() {
  context = new JUnit4Mockery();
  ancestorLinksRenderer = context.mock(AncestorLinksRenderer.class);
  announcementsRenderer = context.mock(AnnouncementsRenderer.class);
  attachmentsRenderer = context.mock(AttachmentsRenderer.class);
  commentsRenderer = context.mock(CommentsRenderer.class);
  contentRenderer = context.mock(ContentRenderer.class);
  fileCabinetRenderer = context.mock(FileCabinetRenderer.class);
  listRenderer = context.mock(ListRenderer.class);
  subpageLinksRenderer = context.mock(SubpageLinksRenderer.class);
  titleRenderer = context.mock(TitleRenderer.class);
  exporter = new PageExporterImpl(
      ancestorLinksRenderer,
      announcementsRenderer,
      attachmentsRenderer,
      commentsRenderer,
      contentRenderer,
      fileCabinetRenderer,
      listRenderer,
      subpageLinksRenderer,
      titleRenderer);
  out = new StringBuilder();
  entryStore = new InMemoryEntryStoreFactory().newEntryStore();
}
 
Example 7
Source File: DefaultLineWrapPositionStrategyTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  myStrategy = new DefaultLineWrapPositionStrategy();

  myMockery = new JUnit4Mockery() {{
    setImposteriser(ClassImposteriser.INSTANCE);
  }};
  myProject = myMockery.mock(Project.class);
}
 
Example 8
Source File: JpaEventRepositoryTest.java    From AisAbnormal with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Before
public void init() {
    context = new JUnit4Mockery();

    sessionFactory = context.mock(SessionFactory.class);
    session = context.mock(Session.class);
    query = context.mock(Query.class);

    eventRepository = new JpaEventRepository(sessionFactory, false);
}
 
Example 9
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 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: 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 12
Source File: GuiProgressListenerTest.java    From google-sites-liberation with Apache License 2.0 5 votes vote down vote up
@Before
public void before() {
  context = new JUnit4Mockery() {{
    setImposteriser(ClassImposteriser.INSTANCE);
  }};
  progressBar = context.mock(JProgressBar.class);
  textComponent = context.mock(JTextComponent.class);
  progressListener = new GuiProgressListener(progressBar, textComponent);
}
 
Example 13
Source File: CourseOverGroundAnalysisTest.java    From AisAbnormal with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Before
public void prepareTest() {
    context = new JUnit4Mockery();

    // Mock dependencies
    trackingService = context.mock(EventEmittingTracker.class);
    statisticsService = context.mock(AppStatisticsService.class);
    statisticsRepository = context.mock(StatisticDataRepository.class);
    eventRepository = context.mock(EventRepository.class);
    behaviourManager = context.mock(BehaviourManager.class);

    configuration = new PropertiesConfiguration();
    configuration.setProperty(CONFKEY_ANALYSIS_COG_CELL_SHIPCOUNT_MIN, 1000);
    configuration.setProperty(CONFKEY_ANALYSIS_COG_PD, 0.001);
}
 
Example 14
Source File: ShipTypeAndSizeAnalysisTest.java    From AisAbnormal with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Before
public void prepareTest() {
    context = new JUnit4Mockery();

    // Mock dependencies
    trackingService = context.mock(EventEmittingTracker.class);
    statisticsService = context.mock(AppStatisticsService.class);
    statisticsRepository = context.mock(StatisticDataRepository.class);
    eventRepository = context.mock(EventRepository.class);
    behaviourManager = context.mock(BehaviourManager.class);

    // Mock shipCount table
    statistics1 = ShipTypeAndSizeStatisticData.create();
    statistics1.setValue((short) 2, (short) 0, "shipCount", 17);
    statistics1.setValue((short) 2, (short) 1, "shipCount", 87);
    statistics1.setValue((short) 2, (short) 2, "shipCount", 2);
    statistics1.setValue((short) 2, (short) 3, "shipCount", 618);
    statistics1.setValue((short) 3, (short) 2, "shipCount", 842);
    statistics1.setValue((short) 3, (short) 3, "shipCount", 954);
    statistics1.setValue((short) 4, (short) 2, "shipCount", 154);
    statistics1.setValue((short) 5, (short) 3, "shipCount", 34);

    // Mock shipCount table
    statistics2 = ShipTypeAndSizeStatisticData.create();
    statistics2.setValue((short) 2, (short) 0, "shipCount", 17);
    statistics2.setValue((short) 2, (short) 1, "shipCount", 87);
    statistics2.setValue((short) 2, (short) 2, "shipCount", 2000);
    statistics2.setValue((short) 2, (short) 3, "shipCount", 618);
    statistics2.setValue((short) 3, (short) 2, "shipCount", 842);
    statistics2.setValue((short) 3, (short) 3, "shipCount", 954);
    statistics2.setValue((short) 4, (short) 2, "shipCount", 154);
    statistics2.setValue((short) 5, (short) 3, "shipCount", 34);

    configuration = new PropertiesConfiguration();
    configuration.setProperty(CONFKEY_ANALYSIS_TYPESIZE_CELL_SHIPCOUNT_MIN, 1000);
    configuration.setProperty(CONFKEY_ANALYSIS_TYPESIZE_PD, 0.001);
}
 
Example 15
Source File: SpeedOverGroundAnalysisTest.java    From AisAbnormal with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Before
public void prepareTest() {
    context = new JUnit4Mockery();

    // Mock dependencies
    trackingService = context.mock(EventEmittingTracker.class);
    statisticsService = context.mock(AppStatisticsService.class);
    statisticsRepository = context.mock(StatisticDataRepository.class);
    eventRepository = context.mock(EventRepository.class);
    behaviourManager = context.mock(BehaviourManager.class);

    configuration = new PropertiesConfiguration();
    configuration.setProperty(CONFKEY_ANALYSIS_SOG_CELL_SHIPCOUNT_MIN, 1000);
    configuration.setProperty(CONFKEY_ANALYSIS_SOG_PD, 0.001);
}
 
Example 16
Source File: EntryUploaderImplTest.java    From google-sites-liberation with Apache License 2.0 5 votes vote down vote up
@Before
public void before() throws MalformedURLException {
  context = new JUnit4Mockery() {{
    setImposteriser(ClassImposteriser.INSTANCE);
  }};
  sitesService = context.mock(SitesService.class);
  entryInserter = context.mock(EntryInserter.class);
  entryProvider = context.mock(EntryProvider.class);
  entryUpdater = context.mock(EntryUpdater.class);
  feedUrl = new URL("http://sites.google.com/feeds/content/site/test");
  entryUploader = new EntryUploaderImpl(entryInserter, entryProvider, 
      entryUpdater);
}
 
Example 17
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 18
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 19
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 );
}
 
Example 20
Source File: CloseEncounterAnalysisTest.java    From AisAbnormal with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Before
public void setUp() throws Exception {
    PropertiesConfiguration configuration = new PropertiesConfiguration();
    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);

    context = new JUnit4Mockery();
    trackingService = context.mock(EventEmittingTracker.class);
    statisticsService = context.mock(AppStatisticsService.class);
    eventRepository = context.mock(EventRepository.class);
    safetyZoneService = new SafetyZoneService(configuration);
    analysis = new CloseEncounterAnalysis(new PropertiesConfiguration(), statisticsService, trackingService, eventRepository, safetyZoneService);

    long timestamp = System.currentTimeMillis();
    long tooOld = timestamp - maxTimestampDeviationMillis - 1;
    long old = timestamp - maxTimestampDeviationMillis + 1;
    long tooNew = timestamp + maxTimestampDeviationMillis + 1;
    long nyw = timestamp + maxTimestampDeviationMillis - 1;

    Position position = Position.create(56, 12);
    Position tooFarAway = Position.create(56.1, 12.1);
    assertTrue(position.distanceTo(tooFarAway, CoordinateSystem.CARTESIAN) > maxDistanceDeviationMeters);
    Position farAway = Position.create(56.014, 12.014);
    assertTrue(position.distanceTo(farAway, CoordinateSystem.CARTESIAN) < maxDistanceDeviationMeters);

    track = new Track(219000606);
    track.update(vessel1StaticPacket);
    track.update(timestamp, position, 90.0f, 10.0f, 90.0f);

    closeTrack = new Track(219002827);
    closeTrack.update(vessel2StaticPacket);
    closeTrack.update(timestamp - 40000, Position.create(56.1000, 12.0010), 180.0f, 10.0f, 180.0f);
    closeTrack.update(timestamp - 30000, Position.create(56.0800, 12.0010), 180.0f, 10.0f, 180.0f);
    closeTrack.update(timestamp - 20000, Position.create(56.0600, 12.0010), 180.0f, 10.0f, 180.0f);
    closeTrack.update(timestamp - 10000, Position.create(56.0400, 12.0010), 180.0f, 10.0f, 180.0f);
    closeTrack.update(timestamp,         Position.create(56.00001, 12.0000), 180.0f, 10.0f, 180.0f);
    closeTrack.getTrackingReports().forEach( tr -> { tr.setProperty("event-certainty-CloseEncounterEvent", EventCertainty.LOWERED);});
    assertTrue(closeTrack.getPosition().equals(Position.create(56.00001, 12.0000)));
    assertTrue(track.getPosition().distanceTo(closeTrack.getPosition(), CoordinateSystem.CARTESIAN) < 200);

    distantTrack = new Track(219000606);
    distantTrack.update(vessel1StaticPacket);
    distantTrack.update(timestamp, Position.create(57, 13), 90.0f, 10.0f, 90.0f);

    Track track1 = new Track(1);
    track1.update(tooOld, position, 90.0f, 10.0f, 90.0f);

    oldNearbyTrack = new Track(2);
    oldNearbyTrack.update(old, position, 90.0f, 10.0f, 90.0f);

    Track track3 = new Track(3);
    track3.update(tooNew, position, 90.0f, 10.0f, 90.0f);

    newNearbyTrack = new Track(3);
    newNearbyTrack.update(nyw, position, 90.0f, 10.0f, 90.0f);

    Track track4 = new Track(4);
    track4.update(timestamp, tooFarAway, 90.0f, 10.0f, 90.0f);

    distantNearbyTrack = new Track(5);
    distantNearbyTrack.update(timestamp, farAway, 90.0f, 10.0f, 90.0f);

    tracks = new HashSet<>();
    tracks.add(track);
    tracks.add(track1);
    tracks.add(oldNearbyTrack);
    tracks.add(track3);
    tracks.add(track4);
    tracks.add(distantNearbyTrack);
    tracks.add(newNearbyTrack);
}