@SuppressWarnings("unchecked") @Test public void testRpcException() { Logger logger = EasyMock.createMock(Logger.class); RpcContext.getContext().setRemoteAddress("127.0.0.1", 1234); RpcException exception = new RpcException("TestRpcException"); logger.error( EasyMock.eq( "Got unchecked and undeclared exception which called by 127.0.0.1. service: " + DemoService.class.getName() + ", method: sayHello, exception: " + RpcException.class.getName() + ": TestRpcException"), EasyMock.eq(exception)); ExceptionFilter exceptionFilter = new ExceptionFilter(logger); RpcInvocation invocation = new RpcInvocation("sayHello", new Class<?>[] {String.class}, new Object[] {"world"}); Invoker<DemoService> invoker = EasyMock.createMock(Invoker.class); EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class); EasyMock.expect(invoker.invoke(EasyMock.eq(invocation))).andThrow(exception); EasyMock.replay(logger, invoker); try { exceptionFilter.invoke(invoker, invocation); } catch (RpcException e) { assertEquals("TestRpcException", e.getMessage()); } EasyMock.verify(logger, invoker); RpcContext.removeContext(); }
@Test public void testDeployProcess() throws PluginException { HashSet<RequestParameterType<?>> mandatoryProperties = new HashSet<>(); RequestParameterType<String> prop = new RequestParameterType<>("test", "test"); mandatoryProperties.add(prop); CanonicalProcessType cpf = new CanonicalProcessType(); AnnotationsType anf = new AnnotationsType(); expect(mockDeploymentPlugin.getNativeType()).andReturn("test"); expect(mockDeploymentPlugin.getName()).andReturn("test"); expect(mockDeploymentPlugin.getVersion()).andReturn("1.0"); PluginResultImpl result = new PluginResultImpl(); result.addPluginMessage("test"); expect( mockDeploymentPlugin.deployProcess( EasyMock.eq(cpf), EasyMock.eq(anf), EasyMock.anyObject(PluginRequest.class))) .andReturn(result); replay(mockDeploymentPlugin); List<PluginMessage> messages = myService.deployProcess("test", cpf, anf, mandatoryProperties); assertTrue(messages.size() == 1); verify(mockDeploymentPlugin); }
@Test public void testSimpleGetVersion() throws ServiceException, IOException { String bucket = "bucket"; String keyPrefix = "prefix/dir/0"; RestS3Service s3Client = EasyMock.createStrictMock(RestS3Service.class); S3Object object0 = new S3Object(); object0.setBucketName(bucket); object0.setKey(keyPrefix + "/renames-0.gz"); object0.setLastModifiedDate(new Date(0)); EasyMock.expect(s3Client.getObjectDetails(EasyMock.eq(bucket), EasyMock.eq(object0.getKey()))) .andReturn(object0) .once(); S3DataSegmentPuller puller = new S3DataSegmentPuller(s3Client); EasyMock.replay(s3Client); String version = puller.getVersion(URI.create(String.format("s3://%s/%s", bucket, object0.getKey()))); EasyMock.verify(s3Client); Assert.assertEquals(String.format("%d", new Date(0).getTime()), version); }
@SuppressWarnings("unchecked") @Test public void testFindCustomersWithConnection() throws Exception { CustomerDAO dao = EasyMock.createMockBuilder(CustomerDAO.class) .addMockedMethod("readNextCustomer") .addMockedMethod("getCustomerQuery") .createStrictMock(); ResultSet resultSet = EasyMock.createStrictMock(ResultSet.class); Connection connection = EasyMock.createStrictMock(Connection.class); Statement statement = EasyMock.createStrictMock(Statement.class); List<SearchConstraint> constraints = new LinkedList<SearchConstraint>(); EasyMock.expect(dao.getCustomerQuery(constraints)).andReturn("aQuery"); EasyMock.expect(connection.createStatement()).andReturn(statement); EasyMock.expect(statement.executeQuery("aQuery")).andReturn(resultSet); EasyMock.expect(resultSet.next()).andReturn(true); EasyMock.expect(dao.readNextCustomer(EasyMock.eq(resultSet), EasyMock.isA(List.class))) .andReturn(true); EasyMock.expect(dao.readNextCustomer(EasyMock.eq(resultSet), EasyMock.isA(List.class))) .andReturn(true); EasyMock.expect(dao.readNextCustomer(EasyMock.eq(resultSet), EasyMock.isA(List.class))) .andReturn(false); resultSet.close(); EasyMock.expectLastCall(); statement.close(); }
@Test @SuppressWarnings("unchecked") public void testWithOrdering() throws IOException { URL url1 = new URL("file://jar1.jar"); URL sci1 = new URL("jar:file://jar1.jar!/" + CONFIG_FILE); URL url2 = new URL("file://dir/"); URL sci2 = new URL("file://dir/" + CONFIG_FILE); loader = EasyMock.createMockBuilder(WebappServiceLoader.class) .addMockedMethod("parseConfigFile", LinkedHashSet.class, URL.class) .withConstructor(context) .createMock(control); List<String> jars = Arrays.asList("jar1.jar", "dir/"); EasyMock.expect(servletContext.getAttribute(ServletContext.ORDERED_LIBS)).andReturn(jars); EasyMock.expect(servletContext.getResource("/WEB-INF/lib/jar1.jar")).andReturn(url1); loader.parseConfigFile(EasyMock.isA(LinkedHashSet.class), EasyMock.eq(sci1)); EasyMock.expect(servletContext.getResource("/WEB-INF/lib/dir/")).andReturn(url2); loader.parseConfigFile(EasyMock.isA(LinkedHashSet.class), EasyMock.eq(sci2)); EasyMock.expect(parent.getResources(CONFIG_FILE)) .andReturn(Collections.<URL>emptyEnumeration()); control.replay(); Assert.assertTrue(loader.load(ServletContainerInitializer.class).isEmpty()); control.verify(); }
@Test public void testGZUncompressRetries() throws ServiceException, IOException, SegmentLoadingException { final String bucket = "bucket"; final String keyPrefix = "prefix/dir/0"; final RestS3Service s3Client = EasyMock.createStrictMock(RestS3Service.class); final byte[] value = bucket.getBytes("utf8"); final File tmpFile = temporaryFolder.newFile("gzTest.gz"); try (OutputStream outputStream = new GZIPOutputStream(new FileOutputStream(tmpFile))) { outputStream.write(value); } S3Object object0 = new S3Object(); object0.setBucketName(bucket); object0.setKey(keyPrefix + "/renames-0.gz"); object0.setLastModifiedDate(new Date(0)); object0.setDataInputStream(new FileInputStream(tmpFile)); File tmpDir = temporaryFolder.newFolder("gzTestDir"); S3ServiceException exception = new S3ServiceException(); exception.setErrorCode("NoSuchKey"); exception.setResponseCode(404); EasyMock.expect( s3Client.getObjectDetails( EasyMock.eq(object0.getBucketName()), EasyMock.eq(object0.getKey()))) .andReturn(null) .once(); EasyMock.expect( s3Client.getObjectDetails( EasyMock.eq(object0.getBucketName()), EasyMock.eq(object0.getKey()))) .andReturn(object0) .once(); EasyMock.expect(s3Client.getObject(EasyMock.eq(bucket), EasyMock.eq(object0.getKey()))) .andThrow(exception) .once(); EasyMock.expect( s3Client.getObjectDetails( EasyMock.eq(object0.getBucketName()), EasyMock.eq(object0.getKey()))) .andReturn(object0) .once(); EasyMock.expect(s3Client.getObject(EasyMock.eq(bucket), EasyMock.eq(object0.getKey()))) .andReturn(object0) .once(); S3DataSegmentPuller puller = new S3DataSegmentPuller(s3Client); EasyMock.replay(s3Client); FileUtils.FileCopyResult result = puller.getSegmentFiles(new S3DataSegmentPuller.S3Coords(bucket, object0.getKey()), tmpDir); EasyMock.verify(s3Client); Assert.assertEquals(value.length, result.size()); File expected = new File(tmpDir, "renames-0"); Assert.assertTrue(expected.exists()); Assert.assertEquals(value.length, expected.length()); }
/** * Tests run of zipalign with correct parameters as well adding aligned file to artifacts * * @throws Exception */ public void testDefaultRun() throws Exception { ZipalignMojo mojo = createMojo("zipalign-config-project3"); MavenProject project = Whitebox.getInternalState(mojo, "project"); project.setPackaging(AndroidExtension.APK); MavenProjectHelper projectHelper = EasyMock.createNiceMock(MavenProjectHelper.class); Capture<File> capturedParameter = new Capture<File>(); projectHelper.attachArtifact( EasyMock.eq(project), EasyMock.eq(AndroidExtension.APK), EasyMock.eq("aligned"), EasyMock.capture(capturedParameter)); Whitebox.setInternalState(mojo, "projectHelper", projectHelper); final CommandExecutor mockExecutor = PowerMock.createMock(CommandExecutor.class); PowerMock.replace( CommandExecutor.Factory.class.getDeclaredMethod("createDefaultCommmandExecutor")) .with( new InvocationHandler() { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { return mockExecutor; } }); Capture<List<String>> capturedFile = new Capture<List<String>>(); mockExecutor.setLogger(EasyMock.anyObject(Log.class)); mockExecutor.executeCommand(EasyMock.anyObject(String.class), EasyMock.capture(capturedFile)); PowerMock.mockStatic(FileUtils.class); EasyMock.expect(FileUtils.fileExists("app-updated.apk")).andReturn(true); EasyMock.replay(projectHelper); PowerMock.replay(mockExecutor); PowerMock.replay(FileUtils.class); mojo.execute(); PowerMock.verify(mockExecutor); List<String> parameters = capturedFile.getValue(); List<String> parametersExpected = new ArrayList<String>(); parametersExpected.add("-v"); parametersExpected.add("-f"); parametersExpected.add("4"); parametersExpected.add("app.apk"); parametersExpected.add("app-updated.apk"); assertEquals("Zipalign arguments aren't as expected", parametersExpected, parameters); PowerMock.verify(projectHelper); assertEquals( "File should be same as expected", new File("app-updated.apk"), capturedParameter.getValue()); // verify that all method were invoked PowerMock.verify(FileUtils.class); }
protected void insertPublisherInfoBehavior() { loader = new DataLoader(configLocation, executableLocation); // configure IExecutableAdvice LauncherData launcherData = loader.getLauncherData(); LaunchingAdvice launchingAdvice = new LaunchingAdvice(launcherData, configSpec); ArrayList launchingList = new ArrayList(); launchingList.add(launchingAdvice); ProductFileAdvice productAdvice = null; try { String productFileLocation = TestData.getFile("ProductActionTest", "productFileActionTest.product") .toString(); //$NON-NLS-1$ //$NON-NLS-2$ productAdvice = new ProductFileAdvice(new ProductFile(productFileLocation), configSpec); launchingList.add(productAdvice); } catch (Exception e) { fail("Unable to create product file advice", e); // $NON-NLS-1$ } expect( publisherInfo.getAdvice( EasyMock.matches(configSpec), EasyMock.eq(false), (String) EasyMock.anyObject(), (Version) EasyMock.anyObject(), EasyMock.eq(IExecutableAdvice.class))) .andReturn(launchingList) .anyTimes(); // configure IConfigAdvice ConfigData configData = loader.getConfigData(); ConfigAdvice configAdvice = new ConfigAdvice(configData, configSpec); ArrayList configList = new ArrayList(); configList.add(configAdvice); configList.add(productAdvice); expect( publisherInfo.getAdvice( EasyMock.matches(configSpec), EasyMock.eq(false), (String) EasyMock.anyObject(), (Version) EasyMock.anyObject(), EasyMock.eq(IConfigAdvice.class))) .andReturn(configList) .anyTimes(); // setup metadata repository IInstallableUnit[] ius = { mockIU("foo", null), mockIU("bar", null) }; //$NON-NLS-1$ //$NON-NLS-2$ metadataRepo = new TestMetadataRepository(getAgent(), ius); expect(publisherInfo.getMetadataRepository()).andReturn(metadataRepo).anyTimes(); expect(publisherInfo.getContextMetadataRepository()).andReturn(null).anyTimes(); }
@Test public void testStartInvalidDBSchema() throws Exception { EasyMock.expect(engineController.isEngineRunning()).andReturn(false); serverConfigurator.configure(); EasyMock.expect(embeddedDatabaseController.shouldUse()).andReturn(true); EasyMock.expect(embeddedDatabaseController.startBuiltInDB()).andReturn(true); EasyMock.expect( processManager.executeProcess( EasyMock.aryEq( new String[] { System.getProperty("java.home") + "/bin/java", "-cp", serverHome + "/lib/ant-launcher-1.7.1.jar", "-Dserver.home=" + serverHome, "-Dant.home=" + serverHome, "-Dtomcat.home=" + engineHome + "/hq-server", "-Dlog4j.configuration=" + new File(serverHome + "/conf/log4j.xml").toURI().toURL().toString(), "org.apache.tools.ant.launch.Launcher", "-q", "-lib", serverHome + "/lib", "-listener", "org.apache.tools.ant.listener.Log4jListener", "-buildfile", serverHome + "/data/db-upgrade.xml", "upgrade" }), EasyMock.eq(serverHome), EasyMock.eq(true), EasyMock.eq(HQServer.DB_UPGRADE_PROCESS_TIMEOUT))) .andReturn(0); EasyMock.expect(dataSource.getConnection()).andReturn(connection); EasyMock.expect(connection.createStatement()).andReturn(statement); EasyMock.expect( statement.executeQuery( "select propvalue from EAM_CONFIG_PROPS " + "WHERE propkey = '" + HQConstants.SchemaVersion + "'")) .andReturn(resultSet); EasyMock.expect(resultSet.next()).andReturn(true); EasyMock.expect(resultSet.getString("propvalue")).andReturn(HQConstants.SCHEMA_MOD_IN_PROGRESS); connection.close(); resultSet.close(); statement.close(); replay(); server.start(); verify(); // Ensure that the embeddedDatabaseController mock expects the stopBuiltInDb during JVM // shutdown. this.teardownCallback = shutdownHookConfiguratorCallback; }
@Test public void testStartErrorVerifyingSchema() throws Exception { EasyMock.expect(engineController.isEngineRunning()).andReturn(false); serverConfigurator.configure(); EasyMock.expect(embeddedDatabaseController.shouldUse()).andReturn(true); EasyMock.expect(embeddedDatabaseController.startBuiltInDB()).andReturn(true); EasyMock.expect( processManager.executeProcess( EasyMock.aryEq( new String[] { System.getProperty("java.home") + "/bin/java", "-cp", serverHome + "/lib/ant-launcher-1.7.1.jar", "-Dserver.home=" + serverHome, "-Dant.home=" + serverHome, "-Dtomcat.home=" + engineHome + "/hq-server", "-Dlog4j.configuration=" + new File(serverHome + "/conf/log4j.xml").toURI().toURL().toString(), "org.apache.tools.ant.launch.Launcher", "-q", "-lib", serverHome + "/lib", "-listener", "org.apache.tools.ant.listener.Log4jListener", "-buildfile", serverHome + "/data/db-upgrade.xml", "upgrade" }), EasyMock.eq(serverHome), EasyMock.eq(true), EasyMock.eq(HQServer.DB_UPGRADE_PROCESS_TIMEOUT))) .andReturn(0); EasyMock.expect(dataSource.getConnection()).andThrow(new SQLException(EXPECTED_EXCEPTION_MSG)); /*Properties testProps = new Properties(); testProps.put("server.java.opts", "-XX:MaxPermSize=192m -Xmx512m -Xms512m -XX:+HeapDumpOnOutOfMemoryError"); testProps.put("server.webapp.port", "7080"); final List<String> expectedOpts = new ArrayList<String>(); expectedOpts.add("-XX:MaxPermSize=192m"); expectedOpts.add("-Xmx512m"); expectedOpts.add("-Xms512m"); expectedOpts.add("-XX:+HeapDumpOnOutOfMemoryError"); expectedOpts.add("-Dserver.home=" + serverHome); EasyMock.expect(serverConfigurator.getServerProps()).andReturn(testProps); org.easymock.classextension.EasyMock.expect(osInfo.getName()).andReturn("Mac OS X"); EasyMock.expect(engineController.start(expectedOpts)).andReturn(0);*/ replay(); server.start(); verify(); // Ensure that the embeddedDatabaseController mock expects the stopBuiltInDb during JVM // shutdown. this.teardownCallback = shutdownHookConfiguratorCallback; }
@Test public void open() { // Arrange mockedHandler.open(EasyMock.eq("url"), EasyMock.eq("name"), EasyMock.eq("features")); EasyMock.expectLastCall(); EasyMock.replay(mockedHandler); // Act Window.open("url", "name", "features"); // Assert EasyMock.verify(mockedHandler); }
@Test public void prompt() { // Arrange mockedHandler.prompt(EasyMock.eq("prompt message"), EasyMock.eq("initial value")); EasyMock.expectLastCall().andReturn("mocked message"); EasyMock.replay(mockedHandler); // Act String result = Window.prompt("prompt message", "initial value"); // Assert EasyMock.verify(mockedHandler); assertEquals("mocked message", result); }
@Test @SuppressWarnings("unchecked") public void addStringIntTMemcacheTranscoderOfT() throws TimeoutException, CacheException { CacheTranscoder transcoder = EasyMock.createMock(CacheTranscoder.class); EasyMock.expect( client.add( EasyMock.eq("test"), EasyMock.eq(1000), EasyMock.eq("value"), EasyMock.anyObject(Transcoder.class))) .andReturn(getFuture(true)); EasyMock.replay(client, transcoder); assertTrue(clientWrapper.add("test", 1000, "value", transcoder)); EasyMock.verify(client, transcoder); }
@SuppressWarnings("unchecked") @Test public void checkRPCCallSuccess() { // Setup Button button = GwtReflectionUtils.getPrivateFieldValue(composite, "button"); Label label = GwtReflectionUtils.getPrivateFieldValue(composite, "label"); service.createBean(EasyMock.eq("OCTO"), EasyMock.isA(AsyncCallback.class)); FooBean expected = new FooBean(); expected.setName("mocked"); expectServiceAndCallbackOnSuccess(expected); // replay all @Mock objects replay(); Assert.assertEquals("", label.getText()); // Test Browser.click(button); // Assert // verify all @Mock objects verify(); Assert.assertEquals("Bean \"mocked\" has been created", label.getText()); }
@Test public void testSetIsInFields_first_ok_second_null_isInAlreadyFilled() { OpenStreetMapSimpleImporter openStreetMapSimpleImporter = new OpenStreetMapSimpleImporter(); final String cityName = "cityName"; final Integer population = 123; final String adm2name = "adm2name"; final City city = new City(); city.setPopulation(population); city.setAdm2Name(adm2name); city.setName(cityName); city.setMunicipality(false); city.setFeatureId(1L); city.setId(123L); final Set<ZipCode> zipCodes = new HashSet<ZipCode>(); zipCodes.add(new ZipCode("zip1")); city.addZipCodes(zipCodes); Point location = GeolocHelper.createPoint(2F, 3F); String countryCode = "FR"; AlternateName an1 = new AlternateName("an1", AlternateNameSource.OPENSTREETMAP); AlternateName an2 = new AlternateName("an2", AlternateNameSource.OPENSTREETMAP); city.addAlternateName(an1); city.addAlternateName(an2); ICityDao cityDao = EasyMock.createMock(ICityDao.class); EasyMock.expect( cityDao.getByShape( EasyMock.anyObject(Point.class), EasyMock.anyObject(String.class), EasyMock.eq(true))) .andReturn(null); EasyMock.expect( cityDao.getNearest(location, countryCode, true, OpenStreetMapSimpleImporter.DISTANCE)) .andReturn(city); EasyMock.expect( cityDao.getNearest(location, countryCode, false, OpenStreetMapSimpleImporter.DISTANCE)) .andReturn(null); EasyMock.replay(cityDao); openStreetMapSimpleImporter.setCityDao(cityDao); OpenStreetMap street = new OpenStreetMap(); street.setCountryCode(countryCode); street.setLocation(location); street.setIsIn("AlreadyFilled"); street.setCityId(456L); openStreetMapSimpleImporter.setIsInFields(street); Set<String> expectedZip = new HashSet<String>(); expectedZip.add("ZIP1"); Assert.assertEquals(expectedZip, street.getIsInZip()); Assert.assertEquals("adm2name", street.getIsInAdm()); Assert.assertEquals("AlreadyFilled", street.getIsIn()); Assert.assertEquals(456L, street.getCityId()); Assert.assertEquals(null, street.getIsInPlace()); Assert.assertTrue(street.getIsInCityAlternateNames().size() == 2); EasyMock.verify(cityDao); }
// @Test public void testStopErrorDeterminingIfStopped() throws Exception { EasyMock.expect(processManager.getPidFromPidFile(serverHome + "/hqdb/data/postmaster.pid")) .andReturn(123l); EasyMock.expect(osInfo.getName()).andReturn("Mac OS X"); EasyMock.expect( processManager.executeProcess( EasyMock.aryEq(new String[] {serverHome + "/bin/db-stop.sh"}), EasyMock.eq(serverHome), EasyMock.eq(false), EasyMock.eq(PostgresEmbeddedDatabaseController.DB_PROCESS_TIMEOUT))) .andReturn(0); EasyMock.expect(processManager.isPortInUse(5432l, 1)).andThrow(new NullPointerException()); replay(); boolean dbStopped = embeddedDBController.stopBuiltInDB(); verify(); assertFalse(dbStopped); }
@Test public void testStopOnWindows() throws Exception { EasyMock.expect(processManager.getPidFromPidFile(serverHome + "/hqdb/data/postmaster.pid")) .andReturn(1l); EasyMock.expect(osInfo.getName()).andReturn("Win32"); EasyMock.expect( processManager.executeProcess( EasyMock.aryEq(new String[] {serverHome + "/bin/db-stop.bat"}), EasyMock.eq(serverHome), EasyMock.eq(false), EasyMock.eq(PostgresEmbeddedDatabaseController.DB_PROCESS_TIMEOUT))) .andReturn(0); replay(); boolean dbStopped = embeddedDBController.stopBuiltInDB(); verify(); assertTrue(dbStopped); }
@Test(expectedExceptions = IllegalStateException.class) void registerMBeanFailed2() throws NotCompliantMBeanException, InstanceAlreadyExistsException, MBeanException, MalformedObjectNameException, AttributeNotFoundException, ReflectionException, InstanceNotFoundException { MBeanServer server = EasyMock.createMock(MBeanServer.class); ObjectName oName = new ObjectName(JolokiaMBeanServerHolderMBean.OBJECT_NAME); EasyMock.expect(server.registerMBean(EasyMock.anyObject(), EasyMock.eq(oName))) .andThrow(new InstanceAlreadyExistsException()); EasyMock.expect( server.getAttribute( EasyMock.eq(oName), eq(JolokiaMBeanServerUtil.JOLOKIA_MBEAN_SERVER_ATTRIBUTE))) .andThrow(new AttributeNotFoundException()); EasyMock.replay(server); MBeanServer m = JolokiaMBeanServerUtil.registerJolokiaMBeanServerHolderMBean(server); }
@Test public void testNext() { boolean expected = true; EasyMock.expect(peekIterator.hasNext()).andReturn(expected).times(4); String defaultString = "S1"; String resString = "S2"; EasyMock.expect(peekIterator.next()).andReturn(defaultString); EasyMock.expect(binaryFn.apply(EasyMock.eq(defaultString), EasyMock.isNull())) .andReturn(resString); EasyMock.expect(peekIterator.next()).andReturn(defaultString); EasyMock.expect(comparator.compare(EasyMock.eq(resString), EasyMock.eq(defaultString))) .andReturn(0); EasyMock.expect(peekIterator.next()).andReturn(defaultString); EasyMock.expect(binaryFn.apply(EasyMock.eq(resString), EasyMock.eq(defaultString))) .andReturn(resString); EasyMock.expect(comparator.compare(EasyMock.eq(resString), EasyMock.eq(defaultString))) .andReturn(1); EasyMock.replay(peekIterator); EasyMock.replay(binaryFn); EasyMock.replay(comparator); String actual = testingIterator.next(); Assert.assertEquals(resString, actual); EasyMock.verify(peekIterator); EasyMock.verify(comparator); EasyMock.verify(binaryFn); }
/** Verify that {@link AbiFormatter#getDefaultAbi} works as expected. */ public void testGetDefaultAbi() throws Exception { ITestDevice device = EasyMock.createMock(ITestDevice.class); EasyMock.expect(device.getProperty("ro.product.cpu.abilist32")).andReturn(null); EasyMock.replay(device); assertEquals(null, AbiFormatter.getDefaultAbi(device, "32")); EasyMock.reset(device); EasyMock.expect(device.getProperty(EasyMock.eq("ro.product.cpu.abilist32"))) .andReturn("abi,abi2,abi3"); EasyMock.replay(device); assertEquals("abi", AbiFormatter.getDefaultAbi(device, "32")); EasyMock.reset(device); EasyMock.expect(device.getProperty(EasyMock.eq("ro.product.cpu.abilist64"))).andReturn(""); EasyMock.replay(device); assertEquals(null, AbiFormatter.getDefaultAbi(device, "64")); }
@Test(groups = "unit", expectedExceptions = RuntimeException.class) public void getMetadatasException() throws RemoteException { EasyMock.expect( authorizationProvider.canDownloadAll( EasyMock.aryEq(new String[] {fileId, fileId2}), EasyMock.eq(gridId))) .andReturn(false); mockObjects.replay(); service.getFileMetadata(Lists.newArrayList(fileId, fileId2), gridId); }
@Test public void testStartPortNotBound() throws Exception { EasyMock.expect(processManager.getPidFromPidFile(serverHome + "/hqdb/data/postmaster.pid")) .andReturn(-1l); EasyMock.expect(osInfo.getName()).andReturn("Mac OS X"); EasyMock.expect( processManager.executeProcess( EasyMock.aryEq(new String[] {serverHome + "/bin/db-start.sh"}), EasyMock.eq(serverHome), EasyMock.eq(false), EasyMock.eq(PostgresEmbeddedDatabaseController.DB_PROCESS_TIMEOUT))) .andReturn(0); EasyMock.expect(processManager.isPortInUse(5432l, 10)).andReturn(false); replay(); boolean dbStarted = embeddedDBController.startBuiltInDB(); verify(); assertFalse(dbStarted); }
@Test @SuppressWarnings("unchecked") public void getStringMemcacheTranscoderOfTLong() throws TimeoutException, CacheException { CacheTranscoder transcoder = EasyMock.createMock(CacheTranscoder.class); EasyMock.expect(client.asyncGet(EasyMock.eq("key1"), EasyMock.anyObject(Transcoder.class))) .andReturn(getFuture("test-value")); EasyMock.replay(client); assertEquals("test-value", clientWrapper.get("key1", transcoder, 100)); EasyMock.verify(client); }
@Test public void testGetCustomerWithConnection() throws Exception { CustomerDAO dao = EasyMock.createMockBuilder(CustomerDAO.class) .addMockedMethod("findCustomers", List.class, Connection.class) .createStrictMock(); Customer customer = EasyMock.createStrictMock(Customer.class); Connection connection = EasyMock.createStrictMock(Connection.class); int custId = 322; List<ICustomer> customerList = new LinkedList<ICustomer>(); customerList.add(customer); Capture<List<SearchConstraint>> capture = new Capture<List<SearchConstraint>>(); EasyMock.expect(dao.findCustomers(EasyMock.capture(capture), EasyMock.eq(connection))) .andReturn(customerList); EasyMock.replay(dao, customer, connection); assertEquals("Wrong customer returned.", customer, dao.getCustomer(custId, connection)); EasyMock.verify(dao, customer, connection); assertEquals("Wrong # of constraints.", 1, capture.getValue().size()); SearchConstraint constraint = capture.getValue().get(0); assertEquals( "Wrong property in constraint.", ICustomerService.PROP_CUSTOMER_ID, constraint.getProperty()); assertEquals( "Wrong operator in constraint.", SearchConstraintOperator.CONSTRAINT_EQUALS, constraint.getOperator()); assertEquals("Wrong value in constraint.", custId, constraint.getValue()); // no customers customerList.clear(); EasyMock.reset(dao, customer, connection); capture = new Capture<List<SearchConstraint>>(); EasyMock.expect(dao.findCustomers(EasyMock.capture(capture), EasyMock.eq(connection))) .andReturn(customerList); EasyMock.replay(dao, customer, connection); assertEquals( "Should not have found a customer returned.", null, dao.getCustomer(custId, connection)); EasyMock.verify(dao, customer, connection); }
@Test void registerMBean2() throws NotCompliantMBeanException, InstanceAlreadyExistsException, MBeanException, MalformedObjectNameException, AttributeNotFoundException, ReflectionException, InstanceNotFoundException { MBeanServer server = EasyMock.createMock(MBeanServer.class); MBeanServer ret = MBeanServerFactory.newMBeanServer(); ObjectName oName = new ObjectName(JolokiaMBeanServerHolderMBean.OBJECT_NAME); EasyMock.expect(server.registerMBean(EasyMock.anyObject(), EasyMock.eq(oName))) .andThrow(new InstanceAlreadyExistsException()); EasyMock.expect( server.getAttribute( EasyMock.eq(oName), eq(JolokiaMBeanServerUtil.JOLOKIA_MBEAN_SERVER_ATTRIBUTE))) .andReturn(ret); EasyMock.replay(server); MBeanServer m = JolokiaMBeanServerUtil.registerJolokiaMBeanServerHolderMBean(server); Assert.assertEquals(ret, m); }
@Test(groups = "unit") public void getCredentials() { CredentialProvider credentialProvider = EasyMock.createMock(CredentialProvider.class); Credential credential = Credentials.getMock(); CredentialCreationOptions options = new CredentialCreationOptions(); EasyMock.expect( credentialProvider.getGlobusCredential( EasyMock.eq("moo"), EasyMock.eq("cow"), EasyMock.same(options))) .andReturn(credential); EasyMock.replay(credentialProvider); final StaticGlobusCredentialSupplierImpl supplier = new StaticGlobusCredentialSupplierImpl(); supplier.setGlobusCredentialProvider(credentialProvider); supplier.setUserName("moo"); supplier.setPassword("cow"); supplier.setOptions(options); assert credential == supplier.get(); EasyMock.verify(credentialProvider); }
protected final MetaDataLocator neverWhitelistProtected() { MetaDataLocator l = mockMetaDataLocator(); expect( l.findMeta( EasyMock.anyObject(String.class), EasyMock.anyObject(String.class), EasyMock.eq(boolean.class))) .andReturn(false); return l; }
public void testGetAssetsZipFileBadAssets() throws Exception { String userId = "1"; long projectId = 2; byte[] data = {0}; List<String> sourceFiles = new ArrayList<String>(); sourceFiles.add("assets/badkitty.png"); sourceFiles.add("assets/meow.mp3"); sourceFiles.add("src/appinventor/ai_user/HelloPurr/Screen1.blk"); sourceFiles.add("src/appinventor/ai_user/HelloPurr/Screen1.scm"); sourceFiles.add("youngandroidproject/project.properties"); EasyMock.expect(storageIo.getProjectSourceFiles(userId, projectId)).andReturn(sourceFiles); EasyMock.expect( storageIo.downloadRawFile( EasyMock.eq(userId), EasyMock.eq(projectId), EasyMock.eq("assets/badkitty.png"))) .andThrow(new RuntimeException()); EasyMock.expect( storageIo.downloadRawFile( EasyMock.eq(userId), EasyMock.eq(projectId), EasyMock.eq("assets/meow.mp3"))) .andReturn(data); control.replay(); List<String> zipEntries = getZipEntries(yaWebStart.getAssetsZipFile(userId, projectId)); ListAssert.assertContains(zipEntries, "assets/meow.mp3"); ListAssert.assertContains(zipEntries, "badassets/badkitty.png"); }
@Test public void alert() { // Arrange mockedHandler.alert(EasyMock.eq("this is an alert")); EasyMock.expectLastCall(); EasyMock.replay(mockedHandler); // Act Window.alert("this is an alert"); // Assert EasyMock.verify(mockedHandler); }
@Test(groups = "unit") public void createQuantificationTraining() { final ITraqQuantitationTrainingService service = EasyMock.createMock(ITraqQuantitationTrainingService.class); getDescription() .setRunIdList( IdList.forIterable( Lists.newArrayList(UUID.randomUUID().toString(), UUID.randomUUID().toString()))); service.createQuantitationTraining( matchId(), matchDestinationId(), captureObject(), EasyMock.eq(getDescription().getReportFileId()), EasyMock.aryEq(getDescription().getRunIdList().toList().toArray(new String[2])), EasyMock.eq(getDescription().getOutputFileId())); returnInitializedObject(); EasyMock.replay(service); runAndVerify( new CreateITraqQuantitationTrainingActivityFactoryImpl(service, getFactorySupport())); EasyMock.verify(service); }