Java Code Examples for org.powermock.api.easymock.PowerMock#createMock()

The following examples show how to use org.powermock.api.easymock.PowerMock#createMock() . 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: DynamoDBWorkerUtilsTest.java    From aws-dynamodb-mars-json-demo with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetStoredETagExists() {
    AmazonDynamoDB dynamoDB = PowerMock.createMock(AmazonDynamoDB.class);
    Map<String, AttributeValue> resourceKey = new HashMap<String, AttributeValue>();
    resourceKey.put(MarsDynamoDBManager.RESOURCE_TABLE_HASH_KEY, new AttributeValue(resource));
    // Get item
    dynamoDB.getItem(table, resourceKey);
    Map<String, AttributeValue> resourceResult = new HashMap<String, AttributeValue>();
    resourceResult.put(MarsDynamoDBManager.RESOURCE_TABLE_HASH_KEY, new AttributeValue(resource));
    resourceResult.put(DynamoDBWorkerUtils.ETAG_KEY, new AttributeValue(eTag));
    GetItemResult result = new GetItemResult().withItem(resourceResult);
    PowerMock.expectLastCall().andReturn(result);
    PowerMock.replayAll();
    String resultETag = DynamoDBWorkerUtils.getStoredETag(dynamoDB, table, resource);
    assertEquals(eTag, resultETag);
    PowerMock.verifyAll();
}
 
Example 2
Source File: TableCellTest.java    From fastods with GNU General Public License v3.0 6 votes vote down vote up
@Test
public final void testDate() throws IOException {
    final TableCellStyle cs = PowerMock.createMock(TableCellStyle.class);
    final DataStyle dateDataStyle = this.ds.getDateDataStyle();

    PowerMock.resetAll();
    this.playAddStyle(cs, dateDataStyle);

    PowerMock.replayAll();
    final Calendar d = Calendar.getInstance(this.locale);
    d.setTimeInMillis(TIME_IN_MILLIS);
    this.cell.setDateValue(d.getTime());

    PowerMock.verifyAll();
    this.assertCellXMLEquals(
            "<table:table-cell table:style-name=\"name\" office:value-type=\"date\" " +
                    "office:date-value=\"2009-02-13T23:31:31.011Z\"/>");
}
 
Example 3
Source File: RangeRefBuilderTest.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 RangeRef r = 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 RangeRef expectedRef = new RangeRef(tableRef, A1, localCellRef);
    Assert.assertEquals(expectedRef, r);
}
 
Example 4
Source File: AutoFilterTest.java    From fastods with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void test() throws IOException {
    final Table table = PowerMock.createMock(Table.class);
    final Filter filter = PowerMock.createMock(Filter.class);

    PowerMock.resetAll();
    EasyMock.expect(table.getName()).andReturn("t");
    filter.appendXMLContent(EasyMock.isA(XMLUtil.class), EasyMock.isA(Appendable.class));

    PowerMock.replayAll();
    final AutoFilter af =
            AutoFilter.builder("my_range", table, 0, 1, 2, 3).filter(filter).hideButtons()
                    .build();
    TestHelper.assertXMLEquals("<table:database-range table:name=\"my_range\" " +
            "table:display-filter-buttons=\"false\" table:target-range-address=\"t" +
            ".B1:D3\"><table:filter></table:filter></table:database-range>", af);

    PowerMock.verifyAll();
}
 
Example 5
Source File: OdsDocumentTest.java    From fastods with GNU General Public License v3.0 6 votes vote down vote up
@Test
public final void testAddTableDefault() throws IOException {
    final Table t = PowerMock.createMock(Table.class);

    PowerMock.resetAll();
    TestHelper.initMockDocument(this.odsElements);
    EasyMock.expect(this.odsElements
            .createTable(EasyMock.eq("t1"), EasyMock.anyInt(), EasyMock.anyInt())).andReturn(t);
    EasyMock.expect(this.odsElements.addTableToContent(t)).andReturn(true);
    this.odsElements.setActiveTable(t);

    PowerMock.replayAll();
    final E document = this.getDocument();
    final Table ret = document.addTable("t1");

    PowerMock.verifyAll();
    Assert.assertEquals(t, ret);
}
 
Example 6
Source File: ResultSetDataWrapperTest.java    From fastods with GNU General Public License v3.0 6 votes vote down vote up
@Test(expected = RuntimeException.class)
public final void testRSException() throws SQLException, IOException {
    final ResultSet rs = PowerMock.createMock(ResultSet.class);
    final ResultSetDataWrapper wrapper =
            ResultSetDataWrapper.builder("range", rs).logger(this.logger).headerStyle(this.tcls)
                    .max(100).noAutoFilter().build();
    final SQLException e = new SQLException();
    final ResultSetMetaData metaData = PowerMock.createMock(ResultSetMetaData.class);

    PowerMock.resetAll();
    EasyMock.expect(this.walker.rowIndex()).andReturn(0);
    EasyMock.expect(this.walker.colIndex()).andReturn(0);
    EasyMock.expect(rs.getMetaData()).andReturn(metaData);
    EasyMock.expect(metaData.getColumnCount()).andReturn(0).anyTimes();

    EasyMock.expect(rs.next()).andThrow(e);
    this.logger.log(EasyMock.eq(Level.SEVERE), EasyMock.anyString(), EasyMock.eq(e));

    PowerMock.replayAll();
    wrapper.addToTable(this.walker);

    PowerMock.verifyAll();
}
 
Example 7
Source File: LinkTest.java    From fastods with GNU General Public License v3.0 5 votes vote down vote up
@Test
public final void testStyleTable() throws IOException {
    final Table table = PowerMock.createMock(Table.class);

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

    PowerMock.replayAll();
    final Link link = Link.builder("table").style(this.ts).to(table).build();
    TestHelper.assertXMLEquals("<text:a text:style-name=\"test\" xlink:href=\"#t\" " +
            "xlink:type=\"simple\">table</text:a>", link);

    PowerMock.verifyAll();
}
 
Example 8
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 9
Source File: TableCellTest.java    From fastods with GNU General Public License v3.0 5 votes vote down vote up
private void playAndReplayPercentage() {
    final TableCellStyle cs = PowerMock.createMock(TableCellStyle.class);
    final DataStyle percentageDataStyle = this.ds.getPercentageDataStyle();

    PowerMock.resetAll();
    this.playAddStyle(cs, percentageDataStyle);

    PowerMock.replayAll();
}
 
Example 10
Source File: SettingsTest.java    From fastods with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testAddTable() throws IOException {
    final Table table = PowerMock.createMock(Table.class);

    final ConfigItem item = new ConfigItem("n", "t", "v");
    final ConfigItemMapEntrySingleton singleton =
            ConfigItemMapEntrySingleton.createSingleton("singleton", item);

    // play
    EasyMock.expect(table.getConfigEntry()).andReturn(singleton);

    PowerMock.replayAll();
    final Settings s = this.createVoidSettings();
    s.addTable(table);
    final ConfigBlock block = s.getRootBlocks().get(0);
    TestHelper.assertXMLUnsortedEquals(
            "<config:config-item-set config:name=\"ooo:view-settings\">" +
                    "<config:config-item-map-indexed " + "config:name=\"Views\">" +
                    "<config:config-item-map-entry>" + "<config:config-item " +
                    "config:name=\"ViewId\" config:type=\"string\">View1</config:config-item>" +
                    "<config:config-item-map-named config:name=\"Tables\">" +
                    "<config:config-item-map-entry " + "config:name=\"singleton\">" +
                    "<config:config-item config:name=\"n\" " +
                    "config:type=\"t\">v</config:config-item>" +
                    "</config:config-item-map-entry>" + "</config:config-item-map-named>" +
                    "</config:config-item-map-entry>" + "</config:config-item-map-indexed>" +
                    "</config:config-item-set>", block);
}
 
Example 11
Source File: TableCellWalkerTest.java    From fastods with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testSetFormat() throws IOException {
    final DataStyles rf = PowerMock.createMock(DataStyles.class);

    PowerMock.resetAll();
    this.initWalker(0);
    this.row.setRowFormat(rf);

    PowerMock.replayAll();
    this.cellWalker = new TableCellWalker(this.table);
    this.cellWalker.setRowFormat(rf);

    PowerMock.verifyAll();
}
 
Example 12
Source File: CurrencyValueTest.java    From fastods with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testSetFromDouble() throws FastOdsException {
    PowerMock.resetAll();
    final TableCell cell = PowerMock.createMock(TableCell.class);
    cell.setCurrencyValue(18.7, "€");

    PowerMock.replayAll();
    final CurrencyValue cv = CurrencyValue.from(18.7, "€");
    cv.setToCell(cell);

    PowerMock.verifyAll();
}
 
Example 13
Source File: NamedOdsDocumentTest.java    From fastods with GNU General Public License v3.0 5 votes vote down vote up
@Before
public final void setUp() {
    this.logger = PowerMock.createNiceMock(Logger.class);
    this.xmlUtil = XMLUtil.create();
    this.odsElements = PowerMock.createMock(OdsElements.class);
    this.aDataStyle = new BooleanStyleBuilder("o", Locale.US).build();
    this.aStyle = TableCellStyle.builder("a").dataStyle(this.aDataStyle).build();
}
 
Example 14
Source File: OdsDocumentTest.java    From fastods with GNU General Public License v3.0 5 votes vote down vote up
@Test
public final void testAddAutoFilter() {
    final AutoFilter af = PowerMock.createMock(AutoFilter.class);

    PowerMock.resetAll();
    TestHelper.initMockDocument(this.odsElements);
    this.odsElements.addAutoFilter(af);

    PowerMock.replayAll();
    final E document = this.getDocument();
    document.addAutoFilter(af);

    PowerMock.verifyAll();
}
 
Example 15
Source File: SimplePageSectionTest.java    From fastods with GNU General Public License v3.0 5 votes vote down vote up
@Test
public final void testAddEmbbeded() {
    final StylesContainer sc = PowerMock.createMock(StylesContainerImpl.class);
    PowerMock.resetAll();

    PowerMock.replayAll();

    final PageSection footer = PageSection.simpleBuilder().content("text").build();
    footer.addEmbeddedStyles(sc);
    footer.addEmbeddedStyles(sc);
    PowerMock.verifyAll();
}
 
Example 16
Source File: TestHttpServletToolbox.java    From cms with Apache License 2.0 5 votes vote down vote up
@Test
public void testWriteBodyResponseAsJson_exception()
{
	try
	{
		HashMap<String, String> errors = new HashMap<String, String>();
		String data = "data";
		HttpServletResponse responseMock = EasyMock.createMock(HttpServletResponse.class);
		ServletOutputStream outputStream = PowerMock.createMock(ServletOutputStream.class);
		EasyMock.expect(responseMock.getOutputStream()).andThrow(new IOException());
		responseMock.setContentType("application/json");
		responseMock.setContentType("application/json");
		responseMock.setCharacterEncoding("UTF-8");
		Capture<byte[]> captureContent = new Capture<byte[]>();
		Capture<Integer> captureInt = new Capture<Integer>();
		EasyMock.expect(responseMock.getOutputStream()).andReturn(outputStream);
		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("{}") == 0);
		assertTrue (json.getJSONObject("errors").toString().compareTo("{\"reason\":\"WB_UNKNOWN_ERROR\"}") == 0);
		assertTrue (captureInt.getValue().compareTo(captureContentLen) == 0);
	} catch (Exception e)
	{
		assertTrue(false);
	}
}
 
Example 17
Source File: DynamoDBWorkerUtilsTest.java    From aws-dynamodb-mars-json-demo with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetStoredETagDoesNotExist() {
    AmazonDynamoDB dynamoDB = PowerMock.createMock(AmazonDynamoDB.class);
    Map<String, AttributeValue> resourceKey = new HashMap<String, AttributeValue>();
    resourceKey.put(MarsDynamoDBManager.RESOURCE_TABLE_HASH_KEY, new AttributeValue(resource));
    // Get item
    dynamoDB.getItem(table, resourceKey);
    GetItemResult result = new GetItemResult();
    PowerMock.expectLastCall().andReturn(result);
    PowerMock.replayAll();
    String resultETag = DynamoDBWorkerUtils.getStoredETag(dynamoDB, table, resource);
    assertEquals(null, resultETag);
    PowerMock.verifyAll();
}
 
Example 18
Source File: OdsDocumentHelperTest.java    From fastods with GNU General Public License v3.0 5 votes vote down vote up
@Before
public void setUp() {
    this.positionUtil = new PositionUtil(new TableNameUtil());
    this.odsDocument = PowerMock.createMock(NamedOdsDocument.class);
    this.tableHelper = PowerMock.createMock(TableHelper.class);
    this.t1 = PowerMock.createMock(Table.class);
    this.t2 = PowerMock.createMock(Table.class);
    this.t3 = PowerMock.createMock(Table.class);
    this.l = Arrays.asList(this.t1, this.t2, this.t3);
    this.helper = new OdsFileHelper(this.odsDocument, this.tableHelper, this.positionUtil);
    PowerMock.resetAll();
}
 
Example 19
Source File: AnonymousOdsDocumentTest.java    From fastods with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testSave() throws IOException {
    final ZipUTF8Writer writer = PowerMock.createMock(ZipUTF8Writer.class);

    PowerMock.resetAll();
    TestHelper.initMockDocument(this.odsElements);
    this.odsElements.createEmptyElements(this.xmlUtil, writer);
    this.odsElements.writeMimeType(this.xmlUtil, writer);
    this.odsElements.writeMeta(this.xmlUtil, writer);
    this.odsElements.writeStyles(this.xmlUtil, writer);
    this.odsElements.writeContent(this.xmlUtil, writer);
    this.odsElements.writeSettings(this.xmlUtil, writer);
    this.odsElements.writeExtras(this.xmlUtil, writer);
    this.logger.log(Level.FINE, "file saved");
    writer.finish();
    writer.close();

    PowerMock.replayAll();
    try {
        this.document = this.getDocument();
        this.document.save(writer);
    } finally {
        writer.finish();
        writer.close();
    }

    PowerMock.verifyAll();
}
 
Example 20
Source File: PreprocessedRowsFlusherTest.java    From fastods with GNU General Public License v3.0 4 votes vote down vote up
@Before
public void setUp() {
    this.util = XMLUtil.create();
    this.w = PowerMock.createMock(ZipUTF8Writer.class);
    this.sb = new StringBuilder(1024 * 32);
}