Can I wrap text to a given width with Guava?

I would like to be able to wrap a long String to a fixed length. Is there a way to do that in Guava? Apache Commons / Lang has the method WordUtils.wrap(String, length) that does exactly what I need. Does Guava have a simple means to accomplish this? I know I can do a hard wrap using Splitter.fixedLength(int) , but I would like a soft wrap. UPDATE: There is now a bounty for this question.

我可以用番石榴包装文字到一个给定的宽度吗?

我希望能够将长字符串换成固定长度。 在番石榴有没有办法做到这一点? Apache Commons / Lang的方法WordUtils.wrap(String, length)完全符合我的需要。 番石榴有一个简单的方法来完成这个? 我知道我可以使用Splitter.fixedLength(int)做硬包装,但我想要一个软包装。 更新:这个问题现在有了一个赏金。 很明显,Guava并没有提供这种功能,所以赏金将使用Guava中最简洁(或最完整)和Guava式的答案。 没有库存,除了

JUnit android test classinheritance

I have simple Android application with some espresso tests. I want to write some base class so all of my test classes will inherit its @beforeClass and @afterClass methods, but the problem is when I do it like code example below, JUnit doesn't see any tests at al. I got Empty test suite. message. What's the problem? Code example: public class RealmTest { protected static Realm

JUnit android测试classinheritance

我有一些简单的Android应用程序和一些特浓咖啡测试。 我想编写一些基类,这样我的所有测试类都将继承它的@beforeClass和@afterClass方法,但问题是当我像下面的代码示例那样执行时,JUnit没有在al中看到任何测试。 我Empty test suite. 信息。 有什么问题? 代码示例: public class RealmTest { protected static Realm realm; @BeforeClass public static void beforeClass() { realm = Realm.getD

Junit Test Method

I have always a confusion about the Methods in Junit. If someone is asking whether can I make a test method Private/Protected in Junit, So is he talking about the Method which should start with test or any other method like setup() , teardown() in Junit. What is the return type of Junit Method. So I have always seen the return type use to be Void so can we change the return type? Now somet

Junit测试方法

我一直对Junit中的方法感到困惑。 如果有人问我是否可以在Junit中使用Private / Protected测试方法,那么他是在讨论应该从测试还是其他任何方法(如Junit中的setup(),teardown())开始的方法。 什么是Junit方法的返回类型。 所以我总是看到返回类型使用是无效的,所以我们可以改变返回类型吗? 现在有时候问题会出现,就像我可以使用Junit测试私有方法一样。 因此,尽我所知,默认情况下,Junit调用将以test开始的

JUnit testing with multiple test cases in a method

I have a following class A with a constructor that takes two strings as parameters. Class A { String test1; String test2; public(String test1, String test2) { this.test1 = test1; this.test2 = test2; } } I would like to test a constructor with three test cases within a one test case method ie 1. Null test1 2. Null test2 3. Null test1, Null test2 String test1 = "ABC"; String

在一个方法中使用多个测试用例进行JUnit测试

我有一个带有两个字符串作为参数的构造函数的以下类A。 Class A { String test1; String test2; public(String test1, String test2) { this.test1 = test1; this.test2 = test2; } } 我想在一个测试用例方法中测试一个具有三个测试用例的构造函数,即1. Null test1 2. Null test2 3. Null test1,Null test2 String test1 = "ABC"; String test2 = "XYZ"; @Test(expected=NullPointerException.class) p

How to write dynamic Test Case

Suppose, I have a junit test class: class MyComponentTest { private void test(File file) {...} @Test public void test1() {test("test1.txt")} @Test public void test2() {test("test2.txt")} @Test public void test3() {test("test3.txt")} } The test method reads the input data from the file and test the component with the input data. What if I am changing the MyComponentTest ? class MyC

如何编写动态测试用例

假设,我有一个junit测试课: class MyComponentTest { private void test(File file) {...} @Test public void test1() {test("test1.txt")} @Test public void test2() {test("test2.txt")} @Test public void test3() {test("test3.txt")} } test方法从file读取输入数据并用输入数据测试组件。 如果我正在更改MyComponentTest ? class MyComponentTest { private void test(File file) {...} @Test pub

How can i inject servletcontext in spring

I need to write a junit test for a rather complex application which runs in a tomcat. I wrote a class which builds up my spring context. private static ApplicationContext springContext = null; springContext = new ClassPathXmlApplicationContext( new String[] {"beans"....}); In the application there is a call: public class myClass implements ServletContextAware { .... final St

我如何在春季注入servletcontext

我需要为一个在tomcat上运行的相当复杂的应用程序编写junit测试。 我写了一个建立我的春​​天背景的课程。 private static ApplicationContext springContext = null; springContext = new ClassPathXmlApplicationContext(new String [] {“beans”....}); 在应用程序中有一个电话: 公共类myClass实现ServletContextAware { .... final String folder = servletContext.getRealPath (“/ example”); ...} 这打

Junit 4 test suite and individual test classes

I have a JUnit 4 test suite with BeforeClass and AfterClass methods that make a setup/teardown for the following test classes. What I need is to run the test classes also by them selves, but for that I need a setup/teardown scenario (BeforeClass and AfterClass or something like that) for each test class. The thing is that when I run the suite I do not want to execute the setup/teardown before a

Junit 4测试套件和个人测试课程

我有一个带有BeforeClass和AfterClass方法的JUnit 4测试套件,可以为以下测试类进行设置/拆卸。 我需要的是由他们自己运行测试类,但为此我需要为每个测试类设置/拆卸场景(BeforeClass和AfterClass或类似的东西)。 问题是,当我运行套件时,我不想在每个测试课前后执行setup / teardown,我只想执行测试套件中的setup / teardown(一次)。 可能吗 ? 提前致谢。 我不知道任何使用JUnit执行此操作的标准方法。 正如你可

Bad form for JUnit test to throw exception?

I'm pretty new to JUnit, and I don't really know what best practices are for exceptions and exception handling. For example, let's say I'm writing tests for an IPAddress class. It has a constructor IPAddress(String addr) that will throw an InvalidIPAddressException if addr is null. As far as I can tell from googling around, the test for the null parameter will look like this.

JUnit测试抛出异常的错误形式?

我对JUnit相当陌生,而且我不知道最佳做法是什么对于异常和异常处理。 例如,假设我正在编写IPAddress类的测试。 它有一个构造函数IPAddress(String addr),如果addr为null,将引发InvalidIPAddressException。 据我可以从谷歌搜索来看,空参数的测试看起来像这样。 @Test public void testNullParameter() { try { IPAddress addr = new IPAddress(null); assertTrue(addr.getOctets() == null);

How to instantiate a shared resource in JUnit

I noticed that jUnit runs the constructor of my test class for each method being tested. Here's an example: public class TestTest { protected BigUglyResource bur; public TestTest(){ bur=new BigUglyResource(); System.out.println("TestTest()"); } @Test public void test1(){ System.out.printf("test1()n"); } @Test public void test2(){

如何在JUnit中实例化共享资源

我注意到,jUnit为每个正在测试的方法运行我的测试类的构造函数。 这是一个例子: public class TestTest { protected BigUglyResource bur; public TestTest(){ bur=new BigUglyResource(); System.out.println("TestTest()"); } @Test public void test1(){ System.out.printf("test1()n"); } @Test public void test2(){ System.out.printf("test2()n");

Does java FileChannnel.transferTo() work cleverly when files are on network?

http://docs.oracle.com/javase/7/docs/api/java/nio/channels/FileChannel.html says Bytes can be transferred from a file to some other channel, and vice versa, in a way that can be optimized by many operating systems into a very fast transfer directly to or from the filesystem cache. If both files are locally on the computer I can understand how this works. But if the files are on the same n

文件在网络上时,java FileChannnel.transferTo()是否巧妙地工作?

http://docs.oracle.com/javase/7/docs/api/java/nio/channels/FileChannel.html 说 字节可以从一个文件传输到另一个通道,反之亦然,这种方式可以被许多操作系统优化成可以非常快速地直接传入或传出文件系统缓存的方式。 如果这两个文件都在本地计算机上,我可以理解这是如何工作的。 但是,如果这些文件在同一个网络驱动器上,是否也适用? 我的意思是,file2中的字节必须首先传输到本地计算机才能写入第二个文件,