小编asm*_*ier的帖子

如何使用JMockit模拟Date类的默认构造函数?

我想模拟默认构造函数,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 jmockit default-constructor

3
推荐指数
2
解决办法
1万
查看次数

是否可以在任何Java IDE中折叠源代码中的类型定义?

最近我经常要读这样的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或插件?

java ide folding

3
推荐指数
1
解决办法
176
查看次数

N-Triples优于CSV存储RDF三元组的优势是什么?

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有什么优势?

csv rdf n-triples

3
推荐指数
1
解决办法
1189
查看次数

解析日期时无法从TemporalAccessor获取ZonedDateTime

使用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)

这次我做错了什么?

java datetime java-8 java-time

3
推荐指数
1
解决办法
7891
查看次数

Python FTPS 在被动模式下挂在目录列表上

我设法使用 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)

python ftp curl ftplib

0
推荐指数
1
解决办法
2369
查看次数

标签 统计

java ×3

csv ×1

curl ×1

datetime ×1

default-constructor ×1

folding ×1

ftp ×1

ftplib ×1

ide ×1

java-8 ×1

java-time ×1

jmockit ×1

n-triples ×1

python ×1

rdf ×1