org.powermock.api.easymock.PowerMock Java Examples

The following examples show how to use org.powermock.api.easymock.PowerMock. 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: TestWBFreeMarkerTemplateEngine.java    From cms with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp()
{
	cloudFileStorageMock = EasyMock.createMock(WPBFileStorage.class);
	Whitebox.setInternalState(WPBFileStorageFactory.class, "instance", cloudFileStorageMock);

	cacheFactoryMock = PowerMock.createMock(WPBCacheFactory.class);
	freeMarkerFactoryMock = PowerMock.createMock(FreeMarkerResourcesFactory.class);
	configurationMock = PowerMock.createMock(Configuration.class);
	templateLoaderMock = PowerMock.createMock(FreeMarkerTemplateLoader.class);
	moduleDirectiveMock = PowerMock.createMock(FreeMarkerModuleDirective.class);
	imageDirectiveMock = PowerMock.createMock(FreeMarkerImageDirective.class);
	articleDirectiveMock = PowerMock.createMock(FreeMarkerArticleDirective.class);
	cloudStorageMock = PowerMock.createMock(WPBFileStorage.class);
	messageCacheMock = PowerMock.createMock(WPBMessagesCache.class);
	cacheInstancesMock = PowerMock.createMock(WPBCacheInstances.class);
	uriDirectiveMock = PowerMock.createMock(FreeMarkerUriDirective.class);
	Logger loggerMock = PowerMock.createMock(Logger.class);
	Whitebox.setInternalState(WPBFreeMarkerTemplateEngine.class, loggerMock);
}
 
Example #2
Source File: TextTest.java    From fastods with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testEmbeddedStyles() {
    final StylesContainer container = PowerMock.createMock(StylesContainerImpl.class);
    final TextStyle ts = TextStyle.builder("s").visible().fontWeightBold().build();
    final Text text =
            Text.builder().parStyledContent("ok", ts).parStyledContent("ok2", ts).build();

    PowerMock.resetAll();
    EasyMock.expect(container.addContentFontFaceContainerStyle(ts)).andReturn(true);
    EasyMock.expect(container.addContentFontFaceContainerStyle(ts)).andReturn(false);

    PowerMock.replayAll();
    text.addEmbeddedStylesFromCell(container);

    PowerMock.verifyAll();
}
 
Example #3
Source File: NGramTokenizationStrategyTest.java    From datawave with Apache License 2.0 6 votes vote down vote up
@Test
public void testTokenize_FilterSizeBasedPruning() throws Exception {
    // Create test input
    final NormalizedContentInterface nci = new NormalizedFieldAndValue("TEST", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
    
    // Calculate the expected number of n-grams
    final String fieldValue = nci.getIndexedFieldValue();
    int expectedNGramCount = BloomFilterUtil.predictNGramCount(fieldValue, AbstractNGramTokenizationStrategy.DEFAULT_MAX_NGRAM_LENGTH);
    
    // Set expectations
    expect(this.filter.apply(isA(String.class))).andReturn(true).times(expectedNGramCount);
    
    // Run the test
    PowerMock.replayAll();
    NGramTokenizationStrategy subject = new NGramTokenizationStrategy(this.filter);
    int result1 = subject.tokenize(nci, AbstractNGramTokenizationStrategy.DEFAULT_MAX_NGRAM_LENGTH);
    PowerMock.verifyAll();
    
    // Verify results
    assertEquals("Should have tokenized and applied " + expectedNGramCount + " n-grams to the bloom filter", expectedNGramCount, result1);
}
 
Example #4
Source File: UnsortedChildrenTesterTest.java    From fastods with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testAttributesEquals2() throws IOException, SAXException {
    PowerMock.resetAll();

    PowerMock.replayAll();
    final Node r = this.getNode("<r a=\"1\"/>");
    final Node s = this.getNode("<s a=\"1\"/>");
    final Node ra0 = r.getAttributes().item(0);
    final Node sa0 = s.getAttributes().item(0);
    Assert.assertNotNull(sa0);
    Assert.assertFalse(this.tester.attributesEquals(r, sa0));
    Assert.assertFalse(this.tester.attributesEquals(ra0, s));
    Assert.assertTrue(this.tester.attributesEquals(ra0, ra0));
    Assert.assertTrue(this.tester.attributesEquals(ra0, sa0));

    PowerMock.replayAll();
}
 
Example #5
Source File: TestWBDefaultContentProvider.java    From cms with Apache License 2.0 6 votes vote down vote up
@Test
public void test_writePageContent_ioexception()
{
	try
	{
		String externalKey = "abc";
		String content = "content";
		OutputStream osMock  = PowerMock.createMock(OutputStream.class);
		WPBPage pageMock = EasyMock.createMock(WPBPage.class);
		InternalModel modelMock = EasyMock.createMock(InternalModel.class);
		EasyMock.expect(pageContentBuilderMock.findWebPage(externalKey)).andReturn(pageMock);
		EasyMock.expect(pageContentBuilderMock.buildPageContent(pageMock, modelMock)).andReturn(content);
		Capture<byte[]> capture = new Capture<byte[]>();
		osMock.write(EasyMock.capture(capture));
		EasyMock.expectLastCall().andThrow(new IOException());
		EasyMock.replay(fileContentBuilderMock, pageContentBuilderMock, pageMock, modelMock, osMock);
		boolean result = contentProvider.writePageContent(externalKey, modelMock, osMock);
		assertTrue (result == false);
		assertTrue ((new String(capture.getValue()).equals(content)));
	} catch (Exception e)
	{
		assertTrue(false);
	}	
}
 
Example #6
Source File: MySqlSourceTaskTest.java    From kafka-mysql-connector with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws IOException, SQLException {
    String mysqlHost = "10.100.172.86";
    connection = DriverManager.getConnection("jdbc:mysql://" + mysqlHost + ":3306/mysql", "root", "passwd");
    
    config = new HashMap<>();
    config.put(MySqlSourceConnector.USER_CONFIG, "maxwell");
    config.put(MySqlSourceConnector.PASSWORD_CONFIG, "XXXXXX");
    config.put(MySqlSourceConnector.PORT_CONFIG, "3306");
    config.put(MySqlSourceConnector.HOST_CONFIG, mysqlHost);
    
    task = new MySqlSourceTask();
    offsetStorageReader = PowerMock.createMock(OffsetStorageReader.class);
    context = PowerMock.createMock(SourceTaskContext.class);
    task.initialize(context);

    runSql("drop table if exists test.users");
    runSql("drop database if exists test");
}
 
Example #7
Source File: TableCellTest.java    From fastods with GNU General Public License v3.0 6 votes vote down vote up
@Test
public final void testSetTimeValueMillisNeg() throws IOException {
    PowerMock.resetAll();
    EasyMock.expect(this.table.findDefaultCellStyle(11))
            .andReturn(TableCellStyle.DEFAULT_CELL_STYLE);
    EasyMock.expect(this.stc.addDataStyle(this.ds.getTimeDataStyle())).andReturn(true);
    EasyMock.expect(this.stc.addChildCellStyle(TableCellStyle.DEFAULT_CELL_STYLE,
            this.ds.getTimeDataStyle())).andReturn(null);

    PowerMock.replayAll();
    this.cell.setTimeValue(-987654);

    PowerMock.verifyAll();
    Assert.assertEquals(
            "<table:table-cell office:value-type=\"time\" office:time-value=\"-PT987.654S\"/>",
            this.getCellXML());
}
 
Example #8
Source File: CellRefBuilderTest.java    From fastods with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testAbsTable() {
    final Table table = PowerMock.createMock(Table.class);

    PowerMock.resetAll();
    EasyMock.expect(table.getName()).andReturn("table");


    PowerMock.replayAll();
    final CellRef c = this.builder.absTable(table).build();

    PowerMock.verifyAll();
    final TableRef tableRef = new TableRef(this.tableNameUtil, null, "table", 4);
    final LocalCellRef localCellRef = new LocalCellRef(0, 0, 0);
    final CellRef expectedRef = new CellRef(tableRef, localCellRef);
    Assert.assertEquals(expectedRef, c);
}
 
Example #9
Source File: DynamoDBJSONRootWorkerTest.java    From aws-dynamodb-mars-json-demo with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetMissionToManifestMap() {
    final URL url = PowerMock.createMock(URL.class);
    PowerMock.mockStatic(JSONUtils.class);
    PowerMock.mockStatic(NetworkUtils.class);
    String manifest = null;
    try {
        manifest = WorkerTestUtils.readFile(ROOT_JSON_FILE);
    } catch (final IOException e1) {
        fail("Could not read file: " + ROOT_JSON_FILE);
    }
    try {
        NetworkUtils.getDataFromURL(url, null, ImageIngester.DEFAULT_CONNECT_TIMEOUT);
        PowerMock.expectLastCall().andReturn(manifest.getBytes());
        PowerMock.replayAll();
        final Map<String, String> missionMap = DynamoDBJSONRootWorker.getMissionToManifestMap(url, ImageIngester.DEFAULT_CONNECT_TIMEOUT);
        assertEquals(EXPECTED_MAP, missionMap);
    } catch (final IOException e) {
        fail(e.getMessage());
    }

}
 
Example #10
Source File: TableCellTest.java    From fastods with GNU General Public License v3.0 6 votes vote down vote up
@Test
public final void testSetTimeValue() throws IOException {
    PowerMock.resetAll();
    EasyMock.expect(this.table.findDefaultCellStyle(11))
            .andReturn(TableCellStyle.DEFAULT_CELL_STYLE);
    EasyMock.expect(this.stc.addDataStyle(this.ds.getTimeDataStyle())).andReturn(true);
    EasyMock.expect(this.stc.addChildCellStyle(TableCellStyle.DEFAULT_CELL_STYLE,
            this.ds.getTimeDataStyle())).andReturn(null);

    PowerMock.replayAll();
    this.cell.setTimeValue(1, 2, 3, 4, 5, 6.7);

    PowerMock.verifyAll();
    Assert.assertEquals("<table:table-cell office:value-type=\"time\" " +
            "office:time-value=\"P1Y2M3DT4H5M6.7S\"/>", this.getCellXML());
}
 
Example #11
Source File: TableAppenderTest.java    From fastods with GNU General Public License v3.0 6 votes vote down vote up
@Test
public final void testName() throws IOException {
    final StringBuilder sb = new StringBuilder();

    PowerMock.resetAll();
    EasyMock.expect(this.tb.getName()).andReturn("tb");
    EasyMock.expect(this.tb.getStyleName()).andReturn("tb-style");
    EasyMock.expect(this.tb.getCustomValueByAttribute()).andReturn(null);
    EasyMock.expect(this.tb.getColumns())
            .andReturn(FastFullList.<TableColumnImpl>builder().build());
    EasyMock.expect(this.tb.getTableRowsUsedSize()).andReturn(0);
    EasyMock.expect(this.tb.getShapes()).andReturn(Collections.<Shape>emptyList());

    PowerMock.replayAll();
    this.tableAppender.appendAllAvailableRows(this.xmlUtil, sb);

    PowerMock.verifyAll();
    sb.append("</table:table>");
    DomTester.assertEquals("<table:table table:name=\"tb\" table:style-name=\"tb-style\" " +
            "table:print=\"false\"><office:forms form:automatic-focus=\"false\" " +
            "form:apply-design-mode=\"false\"/><table:table-column " +
            "table:style-name=\"co1\" " + "table:number-columns-repeated=\"1024\" " +
            "table:default-cell-style-name=\"Default\"/></table:table>", sb.toString());
}
 
Example #12
Source File: ApiGatewayTest.java    From lambadaframework with MIT License 6 votes vote down vote up
@Test
public void testGetPathPartOfResource() throws Exception {
    String functionArn = "testArn";
    String roleArn = "testArn";

    ApiGateway apiGateway = new ApiGateway(getMockDeployment(), functionArn, roleArn);

    final Resource mockResource = PowerMock.createMock(Resource.class);
    expect(mockResource.getPath())
            .andReturn("/resource1")
            .times(1);

    expect(mockResource.getPath())
            .andReturn("/")
            .times(2);

    PowerMock.replay(mockResource);

    assertEquals("resource1", apiGateway.getPathPartOfResource(mockResource));

    assertEquals("", apiGateway.getPathPartOfResource(mockResource));
}
 
Example #13
Source File: TableTest.java    From fastods with GNU General Public License v3.0 6 votes vote down vote up
@Test
public final void testGetRow() throws IOException {
    PowerMock.resetAll();

    PowerMock.replayAll();
    final List<TableRowImpl> rows = Lists.newArrayList();
    for (int r = 0; r < 7; r++) { // 8 times
        rows.add(this.table.getRow(r));
    }

    for (int r = 0; r < 7; r++) { // 8 times
        Assert.assertEquals(rows.get(r), this.table.getRow(r));
    }

    PowerMock.verifyAll();
}
 
Example #14
Source File: TableCellTest.java    From fastods with GNU General Public License v3.0 6 votes vote down vote up
@Test
public final void testTwoDataStyles() throws IOException {
    final TableCellStyle cs = PowerMock.createMock(TableCellStyle.class);
    final DataStyle floatDataStyle = this.ds.getFloatDataStyle();
    final DataStyle percentageDataStyle = this.ds.getPercentageDataStyle();

    PowerMock.resetAll();
    this.playAddStyle(cs, percentageDataStyle);
    EasyMock.expect(this.stc.addDataStyle(floatDataStyle)).andReturn(true);
    EasyMock.expect(this.stc.addChildCellStyle(EasyMock.isA(TableCellStyle.class),
            EasyMock.eq(floatDataStyle))).andReturn(this.tcs);

    PowerMock.replayAll();
    this.cell.setPercentageValue(9.999f);
    this.assertCellXMLEquals(
            "<table:table-cell table:style-name=\"name\" office:value-type=\"percentage\" " +
                    "office:value=\"9.999\"/>");
    this.cell.setFloatValue(9.999f);
    this.assertCellXMLEquals(
            "<table:table-cell table:style-name=\"name\" office:value-type=\"float\" " +
                    "office:value=\"9.999\"/>");

    PowerMock.verifyAll();
}
 
Example #15
Source File: OdsDocumentTest.java    From fastods with GNU General Public License v3.0 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void testGetTables() {
    final List<Table> l = PowerMock.createMock(List.class);

    PowerMock.resetAll();
    TestHelper.initMockDocument(this.odsElements);
    EasyMock.expect(this.odsElements.getTables()).andReturn(l);

    PowerMock.replayAll();
    final E document = this.getDocument();
    final List<Table> tables = document.getTables();

    PowerMock.verifyAll();
    Assert.assertEquals(l, tables);
}
 
Example #16
Source File: MongodbSourceConnectorTest.java    From kafka-connect-mongodb with Apache License 2.0 6 votes vote down vote up
@Test
public void testMultipleTasks() {
    PowerMock.replayAll();
    connector.start(buildSourcePropertiesWithHostAndPort());
    List<Map<String, String>> taskConfigs = connector.taskConfigs(2);
    Assert.assertEquals(2, taskConfigs.size());
    Assert.assertEquals("localhost", taskConfigs.get(0).get("host"));
    Assert.assertEquals("12345", taskConfigs.get(0).get("port"));
    Assert.assertEquals("100", taskConfigs.get(0).get("batch.size"));
    Assert.assertEquals("schema", taskConfigs.get(0).get("schema.name"));
    Assert.assertEquals("prefix", taskConfigs.get(0).get("topic.prefix"));
    Assert.assertEquals("mydb.test1,mydb.test2", taskConfigs.get(0).get("databases"));

    Assert.assertEquals("localhost", taskConfigs.get(1).get("host"));
    Assert.assertEquals("12345", taskConfigs.get(1).get("port"));
    Assert.assertEquals("100", taskConfigs.get(1).get("batch.size"));
    Assert.assertEquals("schema", taskConfigs.get(1).get("schema.name"));
    Assert.assertEquals("prefix", taskConfigs.get(1).get("topic.prefix"));
    Assert.assertEquals("mydb.test3", taskConfigs.get(1).get("databases"));
    PowerMock.verifyAll();
}
 
Example #17
Source File: OdeAuthFilterTest.java    From appinventor-extensions with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
  helper.setUp();
  localUserMock = PowerMock.createMock(LocalUser.class);
  PowerMock.mockStatic(LocalUser.class);
  expect(LocalUser.getInstance()).andReturn(localUserMock).anyTimes();
  localUserMock.set(new User("1", "NonSuch", "NoName", null, 0, false, false, 0, null));
  expectLastCall().times(1);
  expect(localUserMock.getUserEmail()).andReturn("NonSuch").times(1);
  localUserInfo = PowerMock.createMock(OdeAuthFilter.UserInfo.class);
  expect(localUserInfo.buildCookie(false)).andReturn("NoCookie").anyTimes();
  expect(localUserInfo.buildCookie(true)).andReturn("NoCookie").anyTimes();
  mockFilterChain = PowerMock.createNiceMock(FilterChain.class);
  mockServletRequest = PowerMock.createNiceMock(HttpServletRequest.class);
  mockServletResponse = PowerMock.createNiceMock(HttpServletResponse.class);
}
 
Example #18
Source File: MapReduceStatePersisterTest.java    From datawave with Apache License 2.0 6 votes vote down vote up
@Test
public void testDontFindSomeoneElsesJob() throws Exception {
    
    // create some entries
    testPersistentCreate();
    PowerMock.resetAll();
    DatawaveUser user = new DatawaveUser(SubjectIssuerDNPair.of("CN=Gal Some Other sogal, OU=acme", "CN=ca, OU=acme"), UserType.USER, Arrays.asList(auths),
                    null, null, 0L);
    principal = new DatawavePrincipal(Collections.singletonList(user));
    EasyMock.expect(ctx.getCallerPrincipal()).andReturn(principal);
    HashMap<String,String> trackingMap = new HashMap<>();
    expect(connectionFactory.getTrackingMap(EasyMock.anyObject())).andReturn(trackingMap);
    expect(connectionFactory.getConnection(EasyMock.eq(AccumuloConnectionFactory.Priority.ADMIN), EasyMock.eq(trackingMap))).andReturn(connection);
    connectionFactory.returnConnection(connection);
    replayAll();
    
    MapReduceInfoResponseList result = bean.findById(id);
    verifyAll();
    
    assertEquals(0, result.getResults().size());
}
 
Example #19
Source File: KafkaSourceTaskTest.java    From MirrorTool-for-Kafka-Connect with Apache License 2.0 6 votes vote down vote up
@Test
public void testStartNoStoredPartitionsStartEnd() throws Exception {
  TopicPartition firstTopicPartition = new TopicPartition(FIRST_TOPIC, FIRST_PARTITION);
  Collection<TopicPartition> topicPartitions = new ArrayList<>();
  topicPartitions.add(firstTopicPartition);
  Map<TopicPartition, Long> endOffsets = Collections.singletonMap(firstTopicPartition, FIRST_OFFSET);

  EasyMock.expect(context.offsetStorageReader()).andReturn(offsetStorageReader);
  EasyMock.expect(offsetStorageReader.offsets(EasyMock.<List<Map<String, String>>>anyObject()))
      .andReturn(new HashMap<>());
  PowerMock.expectNew(KafkaConsumer.class, new Class[] { Properties.class }, config.getKafkaConsumerProperties())
      .andReturn(consumer);
  EasyMock.expect(consumer.endOffsets(topicPartitions)).andReturn(endOffsets);
  consumer.assign(topicPartitions);
  EasyMock.expectLastCall();
  consumer.seek(firstTopicPartition, FIRST_OFFSET);
  EasyMock.expectLastCall();
  replayAll();

  objectUnderTest.start(opts);

  verifyAll();
}
 
Example #20
Source File: KafkaSourceTaskTest.java    From MirrorTool-for-Kafka-Connect with Apache License 2.0 6 votes vote down vote up
@Test
public void testStartAllStoredPartitions() throws Exception {
  TopicPartition firstTopicPartition = new TopicPartition(FIRST_TOPIC, FIRST_PARTITION);
  Collection<TopicPartition> topicPartitions = new ArrayList<>();
  topicPartitions.add(firstTopicPartition);
  Map<Map<String, String>, Map<String, Object>> storedOffsets = Collections.singletonMap(
      Collections.singletonMap(TOPIC_PARTITION_KEY, String.format("%s:%d", FIRST_TOPIC, FIRST_PARTITION)),
      Collections.singletonMap(OFFSET_KEY, FIRST_OFFSET));

  EasyMock.expect(context.offsetStorageReader()).andReturn(offsetStorageReader);
  EasyMock.expect(offsetStorageReader.offsets(EasyMock.<List<Map<String, String>>>anyObject()))
      .andReturn(storedOffsets);
  PowerMock.expectNew(KafkaConsumer.class, new Class[] { Properties.class }, config.getKafkaConsumerProperties())
      .andReturn(consumer);
  consumer.assign(topicPartitions);
  EasyMock.expectLastCall();
  consumer.seek(firstTopicPartition, FIRST_OFFSET);
  EasyMock.expectLastCall();
  replayAll();

  objectUnderTest.start(opts);

  verifyAll();
}
 
Example #21
Source File: BooleanValueTest.java    From fastods with GNU General Public License v3.0 5 votes vote down vote up
@Test
public final void testSetConstructor() {
    PowerMock.resetAll();
    final TableCell cell = PowerMock.createMock(TableCell.class);
    cell.setBooleanValue(true);

    PowerMock.replayAll();
    final CellValue cv = new BooleanValue(true);
    cv.setToCell(cell);

    PowerMock.verifyAll();
}
 
Example #22
Source File: RowCellWalkerImplTest.java    From fastods with GNU General Public License v3.0 5 votes vote down vote up
@Test
public final void testColumnsSpanned() {
    PowerMock.resetAll();
    this.row.setColumnsSpanned(10, 8);

    PowerMock.replayAll();
    this.cellWalker.to(10);
    this.cellWalker.setColumnsSpanned(8);

    PowerMock.verifyAll();
}
 
Example #23
Source File: SQLToCellValueConverterTest.java    From fastods with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testFromTimestamp() {
    PowerMock.resetAll();
    PowerMock.replayAll();
    Assert.assertEquals(new DateValue(UTIL_DATE), this.converter.from(SQL_TS));

    PowerMock.verifyAll();
}
 
Example #24
Source File: OdsFileWriterAdapterTest.java    From fastods with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testWaitForData() {
    this.flushers.add(this.f);
    PowerMock.resetAll();
    PowerMock.replayAll();
    this.wa.waitForData();
    PowerMock.verifyAll();
}
 
Example #25
Source File: TestHttpServletToolbox.java    From cms with Apache License 2.0 5 votes vote down vote up
@Test
public void testWriteBodyResponseAsJson_json_fail()
{
	try
	{
		HashMap<String, String> errors = new HashMap<String, String>();
		errors.put("key","value");
		String data = "data";
		HttpServletResponse responseMock = EasyMock.createMock(HttpServletResponse.class);
		ServletOutputStream outputStream = PowerMock.createMock(ServletOutputStream.class);
		EasyMock.expect(responseMock.getOutputStream()).andReturn(outputStream);
		responseMock.setContentType("application/json");
		responseMock.setCharacterEncoding("UTF-8");
		Capture<byte[]> captureContent = new Capture<byte[]>();
		Capture<Integer> captureInt = new Capture<Integer>();
		responseMock.setContentLength(EasyMock.captureInt(captureInt));
		outputStream.write(EasyMock.capture(captureContent));
		outputStream.flush();
		
		EasyMock.replay(responseMock, outputStream);
		httpServletToolbox.writeBodyResponseAsJson(responseMock, data, errors);
		
		EasyMock.verify(responseMock, outputStream);
		org.json.JSONObject json = new org.json.JSONObject(new String(captureContent.getValue()));
		Integer captureContentLen = json.toString().length();
		assertTrue (json.getString("status").compareTo("FAIL") == 0);
		assertTrue (json.getString("payload").compareTo(data) == 0);
		assertTrue (json.getJSONObject("errors").toString().compareTo("{\"key\":\"value\"}") == 0);
		assertTrue (captureInt.getValue().compareTo(captureContentLen) == 0);
	} catch (Exception e)
	{
		assertTrue(false);
	}
}
 
Example #26
Source File: TableHelperTest.java    From fastods with GNU General Public License v3.0 5 votes vote down vote up
@Test
public final void testSetCellValueByAddress() throws IOException, ParseException {
    final CellValue value = new StringValue("@");

    PowerMock.resetAll();
    EasyMock.expect(this.table.getWalker()).andReturn(this.walker);
    this.walker.toRow(6);
    this.walker.to(2);
    this.walker.setCellValue(value);

    PowerMock.replayAll();
    this.tableHelper.setCellValue(this.table, "C7", value);

    PowerMock.verifyAll();
}
 
Example #27
Source File: TableCellWalkerTest.java    From fastods with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testAddData() throws IOException {
    final DataWrapper dw = PowerMock.createMock(DataWrapper.class);

    PowerMock.resetAll();
    this.initWalker(0);
    EasyMock.expect(dw.addToTable(EasyMock.isA(TableCellWalker.class))).andReturn(true);

    PowerMock.replayAll();
    this.cellWalker = new TableCellWalker(this.table);
    this.cellWalker.addData(dw);

    PowerMock.verifyAll();
}
 
Example #28
Source File: ParamUtilsTest.java    From turin-programming-language with Apache License 2.0 5 votes vote down vote up
@Test
public void testDesugarizeAsteriskParamWithOnlyNonDefaultAvailable() {
    List<FormalParameterNode> formalParameters = ImmutableList.of(fn1, fn2, fd1, fd2);
    Expression value = createMock(Expression.class);
    value.setParent(EasyMock.anyObject());
    value.setParent(EasyMock.anyObject());
    value.setParent(EasyMock.anyObject());
    value.setParent(EasyMock.anyObject());
    SymbolResolver resolver = createMock(SymbolResolver.class);
    ReferenceTypeUsage typeUsageOfAsteriskParam = createMock(ReferenceTypeUsage.class);
    expect(value.calcType()).andReturn(typeUsageOfAsteriskParam);
    expect(typeUsageOfAsteriskParam.isReference()).andReturn(true);
    expect(typeUsageOfAsteriskParam.asReferenceTypeUsage()).andReturn(typeUsageOfAsteriskParam);
    TypeDefinition typeOfAsteriskParam = PowerMock.createMock(TypeDefinitionNode.class);
    expect(typeUsageOfAsteriskParam.getTypeDefinition()).andReturn(typeOfAsteriskParam);
    expect(typeOfAsteriskParam.hasMethodFor("getFn1", Collections.emptyList(), false)).andReturn(true);
    expect(typeOfAsteriskParam.hasMethodFor("getFn2", Collections.emptyList(), false)).andReturn(true);
    expect(typeOfAsteriskParam.hasMethodFor("getFd1", Collections.emptyList(), false)).andReturn(false);
    expect(typeOfAsteriskParam.hasMethodFor("getFd2", Collections.emptyList(), false)).andReturn(false);
    Node parent = new IntLiteral(3); // it does not really matter

    replay(value, resolver, typeUsageOfAsteriskParam);
    PowerMock.replay(typeOfAsteriskParam);
    Either<String, List<ActualParam>> res = desugarizeAsteriskParam(formalParameters, value, resolver, parent);
    assertEquals(true, res.isRight());
    // 2 + the map for default params
    assertEquals(3, res.getRight().size());
    verify(value, resolver, typeUsageOfAsteriskParam);
    PowerMock.verify(typeOfAsteriskParam);
}
 
Example #29
Source File: TestWBPageModuleController.java    From cms with Apache License 2.0 5 votes vote down vote up
@Test
public void test_notify_ok()
{
	try
	{
	WPBPageModule pageModuleMock = PowerMock.createMock(WPBPageModule.class);
	pageModuleCacheMock.Refresh();
	EasyMock.replay(httpServletToolboxMock, requestMock, responseMock, pageModuleCacheMock, pageModuleMock, jsonObjectConverterMock, validatorMock, adminStorageMock, objectForControllerMock);	
	controllerForTest.notify(pageModuleMock, WPBAdminDataStorageListener.AdminDataStorageOperation.CREATE_RECORD, WPBPageModule.class);
	} catch (Exception e)
	{
		assertTrue (false);
	}
}
 
Example #30
Source File: ContentElementTest.java    From fastods with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testAddChildCellStyle() {
    final TableCellStyle style = PowerMock.createNiceMock(TableCellStyle.class);

    PowerMock.resetAll();
    EasyMock.expect(this.container.addChildCellStyle(TableCellStyle.DEFAULT_CELL_STYLE,
            this.format.getBooleanDataStyle())).andReturn(style);

    PowerMock.replayAll();
    final TableCellStyle actual =
            this.content.addChildCellStyle(TableCellStyle.DEFAULT_CELL_STYLE, CellType.BOOLEAN);

    PowerMock.verifyAll();
    Assert.assertEquals(style, actual);
}