我想模拟默认构造函数,java.util.date因此它不会构造一个Date表示创建时间的对象,但始终是相同的Date对象(在我2010年12月31日的示例中).我尝试用JMockit和执行此操作JUnit,但在执行下面的测试时,输出始终是Thu Jan 01 01:00:00 CET 1970.那我的模拟有Date()什么问题?
import java.util.Date;
import org.junit.*;
import mockit.*;
public class AppTest {
@Before
public void setUp() {
Mockit.setUpMocks(MockedDate.class);
}
@After
public void tearDown() {
Mockit.tearDownMocks();
}
@Test
public void testDate() {
Date today=new Date();
System.out.println(today.toString());
}
@MockClass(realClass=Date.class)
public static class MockedDate {
@Mock
public void $init() {
// Now should be always 31.12.2010!
new Date(110,11,31); //110 = 2010! 11 = December! This …Run Code Online (Sandbox Code Playgroud) 最近我经常要读这样的Java代码:
LinkedHashMap<String, Integer> totals = new LinkedHashMap<String, Integer>(listOfRows.get(0))
for (LinkedHashMap<String, Integer> row : (ArrayList<LinkedHashMap<String,Integer>>) table.getValue()) {
for(Entry<String, Integer> elem : row.entrySet()) {
String colName=elem.getKey();
int Value=elem.getValue();
int oldValue=totals.get(colName);
int sum = Value + oldValue;
totals.put(colName, sum);
}
}
Run Code Online (Sandbox Code Playgroud)
由于长和嵌套的类型定义,简单的算法变得非常模糊.所以我希望我可以使用我的IDE删除或折叠类型定义,以查看没有类型的Java代码:
totals = new (listOfRows.get(0))
for (row : table.getValue()) {
for(elem : row.entrySet()) {
colName=elem.getKey();
Value=elem.getValue();
oldValue=totals.get(colName);
sum = Value + oldValue;
totals.put(colName, sum);
}
}
Run Code Online (Sandbox Code Playgroud)
当然,最好的方法是折叠类型定义,但是当将鼠标移到变量上时,将类型显示为工具提示.是否有可以执行此操作的IDE的IDE IDE或插件?
N-Triples是RDF图的基于行的序列化格式.每行代表RDF Triple的主题,谓词和对象,由空格分隔,并以点结束,如:
<http://one.example/subject1> <http://one.example/predicate1> <http://one.example/object1> .
Run Code Online (Sandbox Code Playgroud)
更多细节可以在这里找到:http://www.w3.org/TR/n-triples/
但是为什么有必要定义这样的格式,如果可以简单地使用CSV来序列化RDF Triples
http://one.example/subject1, http://one.example/predicate1, http://one.example/object1
Run Code Online (Sandbox Code Playgroud)
我甚至可以使用CSV轻松扩展以支持N-Quads,N-Quints ...... 对于序列化RDF三元组,N-Triples比CSV有什么优势?
使用Java 1.8.0_51以下代码(取自Unable从TemporalAccessor获取OffsetDateTime)
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd").withZone(ZoneId.of("Europe/Berlin"));
OffsetDateTime offsetDateTime = ZonedDateTime.parse("20151113", formatter).toOffsetDateTime();
System.out.println(offsetDateTime.format(DateTimeFormatter.ISO_DATE));
Run Code Online (Sandbox Code Playgroud)
抛出异常:
java.time.format.DateTimeParseException: Text '20151113' could not be parsed: Unable to obtain ZonedDateTime from TemporalAccessor: {},ISO,Europe/Berlin resolved to 2015-11-13 of type java.time.format.Parsed
at java.time.format.DateTimeFormatter.createError(DateTimeFormatter.java:1918)
at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1853)
at java.time.ZonedDateTime.parse(ZonedDateTime.java:597)
Run Code Online (Sandbox Code Playgroud)
这次我做错了什么?
我设法使用 curl 连接到 FTP 服务器并列出目录的内容out:
$ curl -v --insecure --ftp-ssl --user xxx:yyy blabla:990/out/
> AUTH SSL
< 234 Proceed with negotiation.
...
> USER xxx
< 331 Please specify the password.
> PASS yyy
< 230 Login successful.
> PBSZ 0
< 200 PBSZ set to 0.
> PROT P
< 200 PROT now Private.
> PWD
< 257 "/"
> CWD out
< 250 Directory successfully changed.
> EPSV
< 229 Entering Extended Passive Mode (|||51042|).
* …Run Code Online (Sandbox Code Playgroud)