/** Tests {@link ControllerImpl#saveOrUpdate(Object)}. */
  @Test
  public void saveOrUpdate() {

    final String OTHER_OBJECT = "kkkkk";

    // at first, we test with a persistent object
    EasyMock.expect(dao.isPersistent(OBJECT)).andReturn(true);
    EasyMock.expect(dao.update(OBJECT)).andReturn(OTHER_OBJECT);
    EasyMock.replay(dao);

    String returned = controller.saveOrUpdate(OBJECT);
    EasyMock.verify(dao);

    assert returned == OTHER_OBJECT;

    // at last, we test with a non-persistent object
    EasyMock.reset(dao);

    EasyMock.expect(dao.isPersistent(OBJECT)).andReturn(false);
    dao.save(OBJECT);
    EasyMock.replay(dao);

    returned = controller.saveOrUpdate(OBJECT);
    EasyMock.verify(dao);

    assert returned == OBJECT;
  }
示例#2
0
 private void showControlsDialog() {
   final ControlsDialog dialog = new ControlsDialog(this);
   dialog.setVisible(true);
   if (dialog.okClicked()) {
     padController1.setButtons();
     padController2.setButtons();
   }
 }
示例#3
0
 public GUIImpl(NES nes) {
   this.nes = nes;
   screenScaleFactor = PrefsSingleton.get().getInt("screenScaling", 2);
   padController1 = new ControllerImpl(this, 0);
   padController2 = new ControllerImpl(this, 1);
   nes.setControllers(padController1, padController2);
   padController1.startEventQueue();
   padController2.startEventQueue();
 }
  /** Tests {@link ControllerImpl#delete(<K>))}. */
  @Test
  public void delete_id() {

    dao.delete(ID);
    EasyMock.replay(dao);

    controller.delete(ID);
    EasyMock.verify(dao);
  }
  /** Tests {@link ControllerImpl#save(Object)}. */
  @Test
  public void save() {

    dao.save(OBJECT);
    EasyMock.replay(dao);

    controller.save(OBJECT);
    EasyMock.verify(dao);
  }
  /** Tests {@link ControllerImpl#refresh(Object)}. */
  @Test
  public void refresh() {

    EasyMock.expect(dao.refresh(OBJECT)).andReturn(OTHER_OBJECT);
    EasyMock.replay(dao);

    assert OTHER_OBJECT == controller.refresh(OBJECT);
    EasyMock.verify(dao);
  }
  /** Tests {@link ControllerImpl#evict(<T>))}. */
  @Test
  public void evict() {

    dao.evict(OBJECT);
    EasyMock.replay(dao);

    controller.evict(OBJECT);
    EasyMock.verify(dao);
  }
  /** Tests {@link ControllerImpl#delete(<T>))}. */
  @Test
  public void delete() {

    dao.delete(OBJECT);
    EasyMock.replay(dao);

    controller.delete(OBJECT);
    EasyMock.verify(dao);
  }
  /** Tests {@link ControllerImpl#findById(<K>))}. */
  @Test
  public void findById() {

    EasyMock.expect(dao.findById(ID)).andReturn(OBJECT);
    EasyMock.replay(dao);

    final String result = controller.findById(ID);
    EasyMock.verify(dao);

    assert result == OBJECT;
  }
  /** Tests {@link ControllerImpl#findAll(int, int, String, boolean)))}. */
  @Test
  public void findAll_paginated() {

    List<String> list = new ArrayList<String>();
    EasyMock.expect(dao.findAll(1, 1)).andReturn(list);
    EasyMock.replay(dao);

    final List<String> returned = controller.findAll(1, 1);
    EasyMock.verify(dao);

    assert list == returned;
  }
  /** Tests {@link ControllerImpl#findByIds(Object[])}. */
  @Test
  public void findByIds() {

    final ArrayList<String> list = new ArrayList<String>();
    EasyMock.expect(dao.findByIds(ID)).andReturn(list);
    EasyMock.replay(dao);

    final List<String> result = controller.findByIds(ID);
    EasyMock.verify(dao);

    assert result == list;
  }
  /** Tests {@link ControllerImpl#save(Object)}. */
  @Test
  public void update() {

    final String OTHER_OBJECT = "sfasdf";

    EasyMock.expect(dao.update(OBJECT)).andReturn(OTHER_OBJECT);
    EasyMock.replay(dao);

    final String returned = controller.update(OBJECT);
    EasyMock.verify(dao);

    assert OTHER_OBJECT == returned;
  }
 @SuppressWarnings("unchecked")
 @Override
 public void init() {
   if (autoIndexController == null && autoIndex) {
     autoIndexController = new AutoIndexController();
     ((AutoIndexController) autoIndexController).setDocumentRoot(documentRoot);
   }
   if (fileController == null) {
     fileController = new ControllerImpl<StateData>();
     HeaderState headerState = new HeaderState();
     headerState.setDocumentRoot(documentRoot);
     headerState.setMimeTypes(mimeTypes);
     headerState.setProvider(new FileChannelProvider());
     ((ControllerImpl) fileController).setStates(Arrays.asList(headerState, new BodyState()));
   }
 }