Closed JulianotCosta closed 4 years ago
Hi @JulianotCosta. When do you have this issue? When compiling FastODS (which version?) or when you are writing your own tests? Or is this a EasyMock version conflict in a maven project?
1) If this is a FastODS compilation issue, current code is different from what you wrote:
@Test
public void testAdd() throws IOException {
final OdsDocument document = PowerMock.createMock(OdsDocument.class);
final MacroLibrary lib = new MacroLibrary("ml", false, Arrays.asList(this.module));
final Capture<StringBuilder> sb1 = Capture.newInstance();
final Capture<byte[]> bs = Capture.newInstance();
...
}
You should update to FastODS 7.2.
2) If you are writing your own tests, this seems an issue with EasyMock usage. Capture
constructors are now private.
3) If this is a maven project conflict, I just updated the pom to use the version 4.1 of EasyMock. You can clone the last snapshot.
Hello, @jferard !
Julien, first of all, thank you for answering my message. Just to brief you, I am trying to create a code in Java to create and write spreadsheet in OpenOffice format (.ods). So, this spreadsheet should have some data in different tabs.
My first step is trying to create an .ods file with this java code:
`package com.github.jferard.fastods.util;
import com.github.jferard.fastods.OdsDocument; import com.github.jferard.fastods.testlib.DomTester; import org.easymock.Capture; import org.easymock.*; import org.easymock.EasyMock; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.powermock.api.easymock.PowerMock;
import java.io.IOException; import java.util.Arrays;
public class MacroLibraryTest { private MacroModule module; private XMLUtil util;
@Before public void setUp() {
this.module = PowerMock.createMock(MacroModule.class);
this.util = XMLUtil.create();
}
@Test public void testIndexLine() throws IOException {
final MacroLibrary lib = MacroLibrary.builder().name("ml").modules(this.module).readOnly().build();
final StringBuilder sb = new StringBuilder();
lib.appendIndexLine(XMLUtil.create(), sb);
DomTester.assertEquals("<library:library library:name=\"ml\" library:link=\"false\"/>",
sb.toString());
}
@Test public void testAdd() throws IOException {
final OdsDocument document = PowerMock.createMock(OdsDocument.class);
final MacroLibrary lib = new MacroLibrary("ml", false, Arrays.asList(this.module));
final Capture <StringBuilder> sb1 = new Capture <StringBuilder>();
final Capture<CharSequence> sb2 = new Capture<CharSequence>();
PowerMock.resetAll();
document.addExtraDir("Basic/ml/");
this.module.appendIndexLine(EasyMock.eq(this.util), EasyMock.capture(sb1));
document.addExtraFile(EasyMock.eq("Basic/ml/script-lb.xml"), EasyMock.eq("text/xml"),
EasyMock.capture(sb2));
this.module.add(this.util, document, "Basic/ml/");
PowerMock.replayAll();
lib.add(this.util, document);
PowerMock.verifyAll();
Assert.assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE library:library " +
"PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\" \"library" +
".dtd\"><library:library xmlns:library=\"http://openoffice.org/2000/library\" " +
"library:name=\"ml\" library:readonly=\"false\" " +
"library:passwordprotected=\"false\"></library:library>", sb1.toString());
Assert.assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE library:library " +
"PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\" \"library" +
".dtd\"><library:library xmlns:library=\"http://openoffice.org/2000/library\" " +
"library:name=\"ml\" library:readonly=\"false\" " +
"library:passwordprotected=\"false\"></library:library>", sb2.toString());
}
}`
During build, these errors happens
Information:java: Multiple encodings set for module chunk RFMAutomation "windows-1252" will be used by compiler
Information:java: Errors occurred while compiling module 'RFMAutomation'
Information:javac 1.8.0_211 was used to compile java sources
Information:Module "RFMAutomation" was fully rebuilt due to project configuration/dependencies changes
Information:30/12/2019 14:46 - Build completed with 5 errors and 100 warnings in 28 s 553 ms
D:\GIT_REP\RFMAutomation\fastods-fastods-parent-0.7.0\fastods\src\test\java\com\github\jferard\fastods\it\DataStyleExampleIT.java
D:\GIT_REP\RFMAutomation\fastods-fastods-parent-0.7.0\fastods\src\test\java\com\github\jferard\fastods\it\MergeExampleIT.java
D:\GIT_REP\RFMAutomation\fastods-fastods-parent-0.7.0\fastods\src\test\java\com\github\jferard\fastods\it\ReadmeExampleIT.java
D:\GIT_REP\RFMAutomation\fastods-fastods-parent-0.7.0\fastods\src\test\java\com\github\jferard\fastods\it\StyleExampleIT.java
D:\GIT_REP\RFMAutomation\fastods-fastods-parent-0.7.0\fastods-examples\src\main\java\com\github\jferard\fastods\examples\B_AccessingTablesRowsAndCells.java
D:\GIT_REP\RFMAutomation\fastods-fastods-parent-0.7.0\fastods\src\main\java\com\github\jferard\fastods\AnonymousOdsDocument.java
D:\GIT_REP\RFMAutomation\fastods-fastods-parent-0.7.0\fastods\src\main\java\com\github\jferard\fastods\CommonOdsDocument.java
D:\GIT_REP\RFMAutomation\fastods-fastods-parent-0.7.0\fastods\src\main\java\com\github\jferard\fastods\TableCellWalker.java
D:\GIT_REP\RFMAutomation\fastods-fastods-parent-0.7.0\fastods\src\main\java\com\github\jferard\fastods\NamedOdsDocument.java
D:\GIT_REP\RFMAutomation\fastods-fastods-parent-0.7.0\fastods\src\main\java\com\github\jferard\fastods\tool\OdsFileHelper.java
D:\GIT_REP\RFMAutomation\fastods-fastods-parent-0.7.0\fastods\src\test\java\com\github\jferard\fastods\OdsDocumentTest.java
D:\GIT_REP\RFMAutomation\fastods-fastods-parent-0.7.0\fastods\src\test\java\com\github\jferard\fastods\AnonymousOdsFileWriterTest.java
D:\GIT_REP\RFMAutomation\fastods-fastods-parent-0.7.0\fastods\src\test\java\com\github\jferard\fastods\it\OdsFileCreationIT.java
D:\GIT_REP\RFMAutomation\fastods-fastods-parent-0.7.0\fastods\src\test\java\com\github\jferard\fastods\LinkTest.java
D:\GIT_REP\RFMAutomation\fastods-fastods-parent-0.7.0\fastods\src\test\java\com\github\jferard\fastods\NamedOdsDocumentTest.java
D:\GIT_REP\RFMAutomation\fastods-fastods-parent-0.7.0\fastods\src\test\java\com\github\jferard\fastods\ref\CellAddressParserTest.java
D:\GIT_REP\RFMAutomation\fastods-fastods-parent-0.7.0\fastods\src\test\java\com\github\jferard\fastods\ref\LocalCellAddressParserTest.java
D:\GIT_REP\RFMAutomation\fastods-fastods-parent-0.7.0\fastods\src\test\java\com\github\jferard\fastods\ref\RangeAddressParserTest.java
D:\GIT_REP\RFMAutomation\fastods-fastods-parent-0.7.0\fastods\src\test\java\com\github\jferard\fastods\ref\TableNameUtilTest.java
D:\GIT_REP\RFMAutomation\fastods-fastods-parent-0.7.0\fastods\src\test\java\com\github\jferard\fastods\RowCellWalkerImplTest.java
D:\GIT_REP\RFMAutomation\fastods-fastods-parent-0.7.0\fastods\src\test\java\com\github\jferard\fastods\RowsFlusherTest.java
D:\GIT_REP\RFMAutomation\fastods-fastods-parent-0.7.0\fastods\src\test\java\com\github\jferard\fastods\style\TableColumnStyleTest.java
D:\GIT_REP\RFMAutomation\fastods-fastods-parent-0.7.0\fastods\src\test\java\com\github\jferard\fastods\style\TableRowStyleTest.java
D:\GIT_REP\RFMAutomation\fastods-fastods-parent-0.7.0\fastods\src\test\java\com\github\jferard\fastods\TableBuilderTest.java
D:\GIT_REP\RFMAutomation\fastods-fastods-parent-0.7.0\fastods\src\test\java\com\github\jferard\fastods\TableCellWalkerTest.java
D:\GIT_REP\RFMAutomation\fastods-fastods-parent-0.7.0\fastods\src\test\java\com\github\jferard\fastods\TableTest.java
D:\GIT_REP\RFMAutomation\fastods-fastods-parent-0.7.0\fastods\src\test\java\com\github\jferard\fastods\tool\OdsDocumentHelperTest.java
D:\GIT_REP\RFMAutomation\fastods-fastods-parent-0.7.0\fastods\src\test\java\com\github\jferard\fastods\util\FileOpenResultTest.java
D:\GIT_REP\RFMAutomation\fastods-fastods-parent-0.7.0\fastods\src\test\java\com\github\jferard\fastods\util\MacroLibraryContainerTest.java
Error:(19, 44) java: constructor Capture in class org.easymock.Capture
Okay. You took the code of a unit test. That's not the best start!
Have a look at the tutorial. All the examples come from the fastods-examples module so you can easily copy paste what you need.
Start with the "hello world" example and then try to add new data, tabs, styles...
note: EasyMock is a testing framework, but is not needed to compile a project (FastODS does not have any external dependency). Your pom should look like:
<dependencies>
<dependency>
<groupId>com.github.jferard</groupId>
<artifactId>fastods</artifactId>
<version>0.7.2</version>
</dependency>
...
Hello, There is some issue I am not able to fix.
Error:(35, 44) java: constructor Capture in class org.easymock.Capture cannot be applied to given types;
required: org.easymock.CaptureType
found: no arguments
reason: actual and formal argument lists differ in length
my pom.xml file is
looks like this piece of code is work
@Test public void testAdd() throws IOException { final OdsDocument document = PowerMock.createMock(OdsDocument.class); final MacroLibrary lib = new MacroLibrary("ml", false, Arrays.asList(this.module)); final Capture sb1 = new Capture ();
final Capture sb2 = new Capture();
Is there something I need to do to work?
Thank you