Java Code Examples for org.easymock.EasyMock#createStrictMock()

The following examples show how to use org.easymock.EasyMock#createStrictMock() . 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: SceneFactoryTest.java    From flashback with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testCreateSceneExistInSequentialRecordMode()
    throws Exception {
  Scene expectedScene = EasyMock.createStrictMock(Scene.class);
  List<RecordedHttpExchange> recordedHttpExchanges = new ArrayList<>();
  Date now = new Date();
  recordedHttpExchanges.add(new RecordedHttpExchange(null, null, now));
  EasyMock.expect(expectedScene.getRecordedHttpExchangeList()).andReturn(recordedHttpExchanges);
  EasyMock.replay(expectedScene);
  Scene result = runTestGetResult(SceneMode.SEQUENTIAL_RECORD, expectedScene);
  Assert.assertNotNull(result);
  Assert.assertEquals(result.getName(), NAME);
  Assert.assertEquals(result.getSceneRoot(), ROOT);
  Assert.assertFalse(result.isReadable());
  // Creating a Scene in sequential record mode should clear the list of exchanges to allow for re-recording
  Assert.assertEquals(result.getRecordedHttpExchangeList().size(), 0);
}
 
Example 2
Source File: SceneAccessLayerTest.java    From flashback with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testCanReplayScene() {
  SceneConfiguration sceneConfiguration1 = new SceneConfiguration(ROOT_PATH, SceneMode.PLAYBACK, SCENE_NAME);
  Scene scene1 = new Scene(sceneConfiguration1);
  SceneAccessLayer sceneAccessLayer = new SceneAccessLayer(scene1, EasyMock.createStrictMock(SceneWriter.class),
      EasyMock.createStrictMock(MatchRule.class));
  Assert.assertTrue(sceneAccessLayer.canPlayback());
  Scene scene2 = new Scene(new SceneConfiguration(ROOT_PATH, SceneMode.RECORD, SCENE_NAME));

  sceneAccessLayer.setScene(scene2);
  Assert.assertFalse(sceneAccessLayer.canPlayback());

  Scene scene3 = new Scene(new SceneConfiguration(ROOT_PATH, SceneMode.SEQUENTIAL_PLAYBACK, SCENE_NAME));
  sceneAccessLayer.setScene(scene3);
  Assert.assertTrue(sceneAccessLayer.canPlayback());

  Scene scene4 = new Scene(new SceneConfiguration(ROOT_PATH, SceneMode.SEQUENTIAL_RECORD, SCENE_NAME));
  sceneAccessLayer.setScene(scene4);
  Assert.assertFalse(sceneAccessLayer.canPlayback());
}
 
Example 3
Source File: UserManagerImplTest.java    From ankush with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Password encryption test method for
 * {@link com.impetus.ankush.service.impl.UserManagerImpl#saveUser(com.impetus.ankush.common.domain.model.User)}
 * .
 * @throws UserExistsException 
 */
@Test
public void testSaveUserPasswordEncryptionUnchanged() throws UserExistsException {
	user.setVersion(1);
	user.setUsername(user.getUsername().toLowerCase());
	
	String encryptedPassword = "ENCRYPTED"+user.getPassword();
	user.setPassword(encryptedPassword);
	
	PasswordEncoder passwordEncoder = EasyMock.createStrictMock(PasswordEncoder.class);
	((UserManagerImpl)userManager).setPasswordEncoder(passwordEncoder);
	
	EasyMock.expect(userDao.getUserPassword(user.getUsername())).andReturn(encryptedPassword);
	EasyMock.expect(userDao.saveUser(user)).andReturn(user);
	EasyMock.replay(userDao, passwordEncoder);
	
	userManager.saveUser(user);
	assertEquals("password not encrypted", encryptedPassword, user.getPassword());
}
 
Example 4
Source File: PropertyUtilsTest.java    From krazo with Apache License 2.0 5 votes vote down vote up
@Test
public void getProperty() {
	Configuration config = EasyMock.createStrictMock(Configuration.class);
	expect(config.getProperty(eq("host"))).andReturn("java.net");
	expect(config.getProperty(eq("port"))).andReturn(null);
	replay(config);
	assertThat(PropertyUtils.getProperty(config, "host", "oracle.com"), is("java.net"));
	assertThat(PropertyUtils.getProperty(config, "port", 8080), is(8080));
	verify(config);
}
 
Example 5
Source File: SceneFactoryTest.java    From flashback with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Scene runTestGetResult(SceneMode scenMode, Scene expectedScene)
    throws IOException {
  _sceneReader = EasyMock.createStrictMock(SceneReader.class);
  SceneConfiguration sceneConfiguration = new SceneConfiguration(ROOT, scenMode, NAME);
  EasyMock.expect(_sceneReader.readScene(EasyMock.anyString(), EasyMock.anyString())).andReturn(expectedScene);

  EasyMock.replay(_sceneReader);
  Scene result = SceneFactory.create(sceneConfiguration, _sceneReader);
  return result;
}
 
Example 6
Source File: StackedDownloaderTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldIterativelyCheckEachDownloaderToSeeIfItWillReturnAnyFiles()
    throws URISyntaxException, IOException {
  Downloader noMatch = EasyMock.createNiceMock("noMatch", Downloader.class);
  Downloader exceptional = EasyMock.createNiceMock("exceptional", Downloader.class);
  Downloader works = EasyMock.createNiceMock("works", Downloader.class);
  Downloader neverCalled = EasyMock.createStrictMock("neverCalled", Downloader.class);

  BuckEventBus eventBus = BuckEventBusForTests.newInstance();
  URI uri = new URI("http://example.com/cheese/peas");
  Path output = Paths.get("never used");

  EasyMock.expect(noMatch.fetch(eventBus, uri, output)).andReturn(false);
  EasyMock.expect(exceptional.fetch(eventBus, uri, output)).andThrow(new IOException(""));
  EasyMock.expect(works.fetch(eventBus, uri, output)).andReturn(true);
  // neverCalled is never called, and so needs no expectations.

  EasyMock.replay(noMatch, exceptional, works, neverCalled);

  StackedDownloader downloader =
      new StackedDownloader(ImmutableList.of(noMatch, exceptional, works, neverCalled));
  boolean result = downloader.fetch(eventBus, uri, output);

  assertTrue(result);

  EasyMock.verify(noMatch, exceptional, works, neverCalled);
}
 
Example 7
Source File: PropertyUtilsTest.java    From ozark with Apache License 2.0 5 votes vote down vote up
@Test
public void getProperty() {
	Configuration config = EasyMock.createStrictMock(Configuration.class);
	expect(config.getProperty(eq("host"))).andReturn("java.net");
	expect(config.getProperty(eq("port"))).andReturn(null);
	replay(config);
	assertThat(PropertyUtils.getProperty(config, "host", "oracle.com"), is("java.net"));
	assertThat(PropertyUtils.getProperty(config, "port", 8080), is(8080));
	verify(config);
}
 
Example 8
Source File: SceneAccessLayerTest.java    From flashback with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testHasNoMatchRequest()
    throws URISyntaxException, IOException {
  Scene scene = EasyMock.createStrictMock(Scene.class);
  EasyMock.expect(scene.isSequential()).andReturn(false);
  SceneWriter sceneWriter = EasyMock.createStrictMock(SceneWriter.class);

  RecordedHttpExchange recordedHttpExchange1 = EasyMock.createStrictMock(RecordedHttpExchange.class);
  RecordedHttpExchange recordedHttpExchange2 = EasyMock.createStrictMock(RecordedHttpExchange.class);
  RecordedHttpRequest recordedHttpRequest1 = EasyMock.createStrictMock(RecordedHttpRequest.class);
  RecordedHttpRequest recordedHttpRequest2 = EasyMock.createStrictMock(RecordedHttpRequest.class);
  EasyMock.expect(recordedHttpExchange1.getRecordedHttpRequest()).andReturn(recordedHttpRequest1);
  EasyMock.expect(recordedHttpExchange2.getRecordedHttpRequest()).andReturn(recordedHttpRequest2);
  RecordedHttpRequest incomingHttpRequest = EasyMock.createStrictMock(RecordedHttpRequest.class);

  ArrayList<RecordedHttpExchange> recordedHttpExchangeArrayList = new ArrayList<>();
  recordedHttpExchangeArrayList.add(recordedHttpExchange1);
  recordedHttpExchangeArrayList.add(recordedHttpExchange2);
  EasyMock.expect(scene.getRecordedHttpExchangeList()).andReturn(recordedHttpExchangeArrayList);

  MatchRule matchRule = EasyMock.createStrictMock(MatchRule.class);
  EasyMock.expect(matchRule.test(incomingHttpRequest, recordedHttpRequest1)).andReturn(false);
  EasyMock.expect(matchRule.test(incomingHttpRequest, recordedHttpRequest2)).andReturn(false);

  EasyMock.replay(scene, recordedHttpExchange1, recordedHttpExchange2, recordedHttpRequest1, recordedHttpRequest2,
      incomingHttpRequest, matchRule);

  SceneAccessLayer sceneAccessLayer = new SceneAccessLayer(scene, sceneWriter, matchRule);

  Assert.assertFalse(sceneAccessLayer.hasMatchRequest(incomingHttpRequest));
  EasyMock.verify(scene, recordedHttpExchange1, recordedHttpExchange2, recordedHttpRequest1, recordedHttpRequest2,
      incomingHttpRequest, matchRule);
}
 
Example 9
Source File: MessagesTest.java    From ozark with Apache License 2.0 5 votes vote down vote up
/**
 * Test get method.
 *
 * @throws Exception when an error occurs.
 */
@Test
public void testGet2() throws Exception {
    HttpServletRequest request = EasyMock.createStrictMock(HttpServletRequest.class);
    Field field = messages.getClass().getDeclaredField("request");
    field.setAccessible(true);
    field.set(messages, request);
    ArrayList<Locale> locales = new ArrayList<>();
    locales.add(Locale.FRENCH);
    locales.add(Locale.ENGLISH);
    expect(request.getLocales()).andReturn(Collections.enumeration(locales));
    replay(request);
    assertEquals("Validation of CSRF failed due to {0}", messages.get("CsrfFailed", new Object[] {}));
    verify(request);
}
 
Example 10
Source File: SceneAccessLayerTest.java    From flashback with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testRecordUpdate()
    throws IOException {
  Scene scene = EasyMock.createMock(Scene.class);
  EasyMock.expect(scene.isSequential()).andReturn(false).anyTimes();
  RecordedHttpExchange recordedHttpExchange1 = EasyMock.createStrictMock(RecordedHttpExchange.class);
  RecordedHttpExchange recordedHttpExchange2 = EasyMock.createStrictMock(RecordedHttpExchange.class);
  RecordedHttpRequest recordedHttpRequest1 = EasyMock.createStrictMock(RecordedHttpRequest.class);
  EasyMock.expect(recordedHttpExchange1.getRecordedHttpRequest()).andReturn(recordedHttpRequest1);
  RecordedHttpRequest incomingHttpRequest = EasyMock.createStrictMock(RecordedHttpRequest.class);
  RecordedHttpResponse incomingHttpResponse = EasyMock.createStrictMock(RecordedHttpResponse.class);

  ArrayList<RecordedHttpExchange> recordedHttpExchangeArrayList = new ArrayList<>();
  recordedHttpExchangeArrayList.add(recordedHttpExchange1);
  recordedHttpExchangeArrayList.add(recordedHttpExchange2);
  EasyMock.expect(scene.getRecordedHttpExchangeList()).andReturn(recordedHttpExchangeArrayList).times(3);
  SceneWriter sceneWriter = EasyMock.createStrictMock(SceneWriter.class);

  MatchRule matchRule = EasyMock.createStrictMock(MatchRule.class);
  EasyMock.expect(matchRule.test(incomingHttpRequest, recordedHttpRequest1)).andReturn(true);
  sceneWriter.writeScene(scene);
  EasyMock.expectLastCall();

  EasyMock.replay(scene, sceneWriter, recordedHttpExchange1, matchRule);
  SceneAccessLayer sceneAccessLayer = new SceneAccessLayer(scene, sceneWriter, matchRule);
  sceneAccessLayer.record(incomingHttpRequest, incomingHttpResponse);
  sceneAccessLayer.flush();
  List<RecordedHttpExchange> recordedHttpExchangeList = scene.getRecordedHttpExchangeList();
  Assert.assertEquals(recordedHttpExchangeList.size(), 2);
  Assert.assertEquals(recordedHttpExchangeList.get(0).getRecordedHttpRequest(), incomingHttpRequest);
  Assert.assertEquals(recordedHttpExchangeList.get(0).getRecordedHttpResponse(), incomingHttpResponse);
  EasyMock.verify(scene, sceneWriter, recordedHttpExchange1, matchRule);
}
 
Example 11
Source File: SceneAccessLayerTest.java    From flashback with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testHasMatchRequest()
    throws URISyntaxException, IOException {
  Scene scene = EasyMock.createStrictMock(Scene.class);
  SceneWriter sceneWriter = EasyMock.createStrictMock(SceneWriter.class);
  EasyMock.expect(scene.isSequential()).andReturn(false);

  RecordedHttpExchange recordedHttpExchange1 = EasyMock.createStrictMock(RecordedHttpExchange.class);
  RecordedHttpExchange recordedHttpExchange2 = EasyMock.createStrictMock(RecordedHttpExchange.class);
  RecordedHttpRequest recordedHttpRequest1 = EasyMock.createStrictMock(RecordedHttpRequest.class);
  EasyMock.expect(recordedHttpExchange1.getRecordedHttpRequest()).andReturn(recordedHttpRequest1);
  RecordedHttpRequest incomingHttpRequest = EasyMock.createStrictMock(RecordedHttpRequest.class);

  ArrayList<RecordedHttpExchange> recordedHttpExchangeArrayList = new ArrayList<>();
  recordedHttpExchangeArrayList.add(recordedHttpExchange1);
  recordedHttpExchangeArrayList.add(recordedHttpExchange2);
  EasyMock.expect(scene.getRecordedHttpExchangeList()).andReturn(recordedHttpExchangeArrayList);

  MatchRule matchRule = EasyMock.createStrictMock(MatchRule.class);
  EasyMock.expect(matchRule.test(incomingHttpRequest, recordedHttpRequest1)).andReturn(true);
  EasyMock.replay(scene, recordedHttpExchange1, recordedHttpRequest1, incomingHttpRequest, matchRule);

  SceneAccessLayer sceneAccessLayer = new SceneAccessLayer(scene, sceneWriter, matchRule);

  Assert.assertTrue(sceneAccessLayer.hasMatchRequest(incomingHttpRequest));
  EasyMock.verify(scene, recordedHttpExchange1, recordedHttpRequest1, incomingHttpRequest, matchRule);
}
 
Example 12
Source File: SceneAccessLayerTest.java    From flashback with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testRecordAddChangeSceneWithoutExplicitFlush()
    throws IOException {
  Scene scene = EasyMock.createMock(Scene.class);
  EasyMock.expect(scene.isSequential()).andReturn(false).anyTimes();
  RecordedHttpExchange recordedHttpExchange1 = EasyMock.createStrictMock(RecordedHttpExchange.class);
  RecordedHttpExchange recordedHttpExchange2 = EasyMock.createStrictMock(RecordedHttpExchange.class);
  RecordedHttpRequest recordedHttpRequest1 = EasyMock.createStrictMock(RecordedHttpRequest.class);
  RecordedHttpRequest recordedHttpRequest2 = EasyMock.createStrictMock(RecordedHttpRequest.class);
  EasyMock.expect(recordedHttpExchange1.getRecordedHttpRequest()).andReturn(recordedHttpRequest1);
  EasyMock.expect(recordedHttpExchange2.getRecordedHttpRequest()).andReturn(recordedHttpRequest2);
  RecordedHttpRequest incomingHttpRequest = EasyMock.createStrictMock(RecordedHttpRequest.class);
  RecordedHttpResponse incomingHttpResponse = EasyMock.createStrictMock(RecordedHttpResponse.class);

  ArrayList<RecordedHttpExchange> recordedHttpExchangeArrayList = new ArrayList<>();
  recordedHttpExchangeArrayList.add(recordedHttpExchange1);
  recordedHttpExchangeArrayList.add(recordedHttpExchange2);
  EasyMock.expect(scene.getRecordedHttpExchangeList()).andReturn(recordedHttpExchangeArrayList).times(3);
  SceneWriter sceneWriter = EasyMock.createStrictMock(SceneWriter.class);

  MatchRule matchRule = EasyMock.createStrictMock(MatchRule.class);
  EasyMock.expect(matchRule.test(incomingHttpRequest, recordedHttpRequest1)).andReturn(false);
  EasyMock.expect(matchRule.test(incomingHttpRequest, recordedHttpRequest2)).andReturn(false);
  sceneWriter.writeScene(scene);
  EasyMock.expectLastCall();

  EasyMock.replay(scene, sceneWriter, recordedHttpExchange1, recordedHttpExchange2, matchRule);
  SceneAccessLayer sceneAccessLayer = new SceneAccessLayer(scene, sceneWriter, matchRule);
  sceneAccessLayer.record(incomingHttpRequest, incomingHttpResponse);

  List<RecordedHttpExchange> recordedHttpExchangeList = scene.getRecordedHttpExchangeList();
  Assert.assertEquals(recordedHttpExchangeList.size(), 3);
  Assert.assertEquals(recordedHttpExchangeList.get(2).getRecordedHttpRequest(), incomingHttpRequest);
  Assert.assertEquals(recordedHttpExchangeList.get(2).getRecordedHttpResponse(), incomingHttpResponse);

  Scene scene2 = EasyMock.createMock(Scene.class);
  sceneAccessLayer.setScene(scene2);

  EasyMock.verify(scene, sceneWriter, recordedHttpExchange1, recordedHttpExchange2, matchRule);
}
 
Example 13
Source File: ConfigurationParserTestMocks.java    From c2mon with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Bean
public EquipmentDAO equipmentDAO() {
  return EasyMock.createStrictMock(EquipmentDAO.class);
}
 
Example 14
Source File: ConfigurationParserTestMocks.java    From c2mon with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Bean
public SubEquipmentDAO subEquipmentDAO() {
  return EasyMock.createStrictMock(SubEquipmentDAO.class);
}
 
Example 15
Source File: TestAbstractPasswordPrompter.java    From java-license-manager with Apache License 2.0 4 votes vote down vote up
@Test
public void testPromptForValidPassword03()
{
    OutputDevice device = EasyMock.createStrictMock(OutputDevice.class);

    char[] password1 = "another03".toCharArray();
    EasyMock.expect(this.prompter.readPassword("Enter pass phrase to encrypt the public key: ")).
        andReturn(password1);

    char[] password2 = "testPassword01".toCharArray();
    EasyMock.expect(this.prompter.readPassword("Verifying - Reenter pass phrase to encrypt the public key: ")).
        andReturn(password2);
    device.outputErrorMessage("ERROR: Passwords do not match. Please try again, or press Ctrl+C to cancel.");
    EasyMock.expectLastCall();

    EasyMock.expect(this.prompter.readPassword("Enter pass phrase to encrypt the public key: ")).
        andReturn(password1);

    password2 = "another03".toCharArray();
    EasyMock.expect(this.prompter.readPassword("Verifying - Reenter pass phrase to encrypt the public key: ")).
        andReturn(password2);

    EasyMock.replay(this.prompter, device);

    char[] password = this.prompter.promptForValidPassword(
        6,
        32,
        "Enter pass phrase to encrypt the public key: ",
        "Verifying - Reenter pass phrase to encrypt the public" +
        " key: ",
        "The password must be at least six characters and no " +
        "more than 32 characters long.",
        "ERROR: Passwords do not match. Please try again, or " +
        "press Ctrl+C to cancel.",
        device
    );

    assertArrayEquals("The password is not correct.", "another03".toCharArray(), password);
    assertNotSame("The arrays should be different objects (1).", password1, password);
    assertNotSame("The arrays should be different objects (2).", password2, password);
    assertNotEquals("The arrays should not equal each other (1).", new String(password1), new String(password));
    assertNotEquals("The arrays should not equal each other (2).", new String(password2), new String(password));

    EasyMock.verify(device);
}
 
Example 16
Source File: ConfigurationParserTestMocks.java    From c2mon with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Bean
public TagFacadeGateway tagFacadeGateway() {
  return EasyMock.createStrictMock(TagFacadeGateway.class);
}
 
Example 17
Source File: ConfigurationParserTestMocks.java    From c2mon with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Bean
public DataTagCache dataTagCache() {
  return EasyMock.createStrictMock(DataTagCache.class);
}
 
Example 18
Source File: ConfigurationParserTestMocks.java    From c2mon with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Bean
public CommFaultTagCache commFaultTagCache() {
  return EasyMock.createStrictMock(CommFaultTagCache.class);
}
 
Example 19
Source File: ConfigurationParserTestMocks.java    From c2mon with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Bean
public EquipmentCache equipmentCache() {
  return EasyMock.createStrictMock(EquipmentCache.class);
}
 
Example 20
Source File: ConfigurationParserTestMocks.java    From c2mon with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Bean
public ProcessCache processCache() {
  return EasyMock.createStrictMock(ProcessCache.class);
}