我该如何解析网址?
site.com:8080/someFile.txt?attr=100
Run Code Online (Sandbox Code Playgroud)
要么
site.com:8080/someFile.txt/?attr=100
Run Code Online (Sandbox Code Playgroud)
我需要得到someFile.txt,我自己设置的文件名在哪里作为格式(txt或其他).
UPDATE
我试过了
var path = url.parse(req.url).path;
Run Code Online (Sandbox Code Playgroud)
但我仍然无法获得路径(someFile.txt).
我正在尝试模拟私有静态方法anotherMethod().见下面的代码
public class Util {
public static String method(){
return anotherMethod();
}
private static String anotherMethod() {
throw new RuntimeException(); // logic was replaced with exception.
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的测试代码
@PrepareForTest(Util.class)
public class UtilTest extends PowerMockTestCase {
@Test
public void should_prevent_invoking_of_private_method_but_return_result_of_it() throws Exception {
PowerMockito.mockStatic(Util.class);
PowerMockito.when(Util.class, "anotherMethod").thenReturn("abc");
String retrieved = Util.method();
assertNotNull(retrieved);
assertEquals(retrieved, "abc");
}
}
Run Code Online (Sandbox Code Playgroud)
但是我运行它的每个瓷砖都得到了这个例外
java.lang.AssertionError: expected object to not be null
Run Code Online (Sandbox Code Playgroud)
我想我在做嘲弄事情时做错了.任何想法我该如何解决?
我有三个非常简单的课程.其中一个扩展了父类.
public class Parent{
protected String print() {
// some code
}
}
Run Code Online (Sandbox Code Playgroud)
这是一个儿童班.
public class Child extends Parent {
/**
* Shouldn't invoke protected Parent.print() of parent class.
*/
@Override
protected String print() {
// some additional behavior
return super.print();
}
}
Run Code Online (Sandbox Code Playgroud)
和测试班.
public class ChildTest {
@Test
public void should_mock_invocation_of_protected_method_of_parent_class() throws Exception {
// Given
Child child = PowerMockito.mock(Child.class);
Method method = PowerMockito.method(Parent.class, "print");
PowerMockito.when(child, method).withNoArguments().thenReturn("abc");
// When
String retrieved = child.print();
// Than
Mockito.verify(child, times(1)).print(); // verification …Run Code Online (Sandbox Code Playgroud) 我正在尝试测试JAXB解组器/编组器。这是我的代码
JAXBContext context = JAXBContext.newInstance(ClientUser.class.getPackage().getName());
Run Code Online (Sandbox Code Playgroud)
还有我实体的代码
@XmlRootElement(name = "user")
public class ClientUser {
private String name;
public ClientUser() {}
public ClientUser(String name) {
this.name = name;
}
@XmlElement(name = "name")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Run Code Online (Sandbox Code Playgroud)
即使我将实体类添加到实体类
@XmlRegistry
class ObjectFactory {
ClientUser createPerson() {
return new ClientUser();
}
}
Run Code Online (Sandbox Code Playgroud)
我仍然不断收到这个例外
Exception in thread "main" javax.xml.bind.JAXBException: Provider com.sun.xml.bind.v2.ContextFactory could not be instantiated: javax.xml.bind.JAXBException: "com.example.ws.poc.entity" doesnt contain ObjectFactory.class or jaxb.index
- …Run Code Online (Sandbox Code Playgroud) 通常的想法是,如果这个结构不是Iterable,我就不能用forEach迭代一些结构.但为什么我可以在Java中迭代数组呢?数组不是Iterable.
MyClass[] array = {new MyClass("a"), new MyClass("b")};
for (MyClass c : array) {
System.out.println(c);
}
Run Code Online (Sandbox Code Playgroud) 我有一个简单的bash脚本来运行我的java程序.就这个:
run.sh
#!/bin/sh
java -jar target/my-jar-arch.jar
Run Code Online (Sandbox Code Playgroud)
我想将参数传递给此脚本,该脚本必须将它们传递给java程序:
bash run.sh myArg -key 100
Run Code Online (Sandbox Code Playgroud)
当我尝试执行此行时,我的应用程序没有获得任何参数.我该如何解决?
我想用html文件替换我的代码内模板.我该怎么做?
Greeting.annotations = [
new angular.ComponentAnnotation({
selector: 'greeting'
}),
new angular.ViewAnnotation({
template: '<h1>Hello!</h1>'
})
];
Run Code Online (Sandbox Code Playgroud)
我想要这样的东西
template: 'path/to/my/template.html'
Run Code Online (Sandbox Code Playgroud)
我使用Angular2和ES5.
java ×4
javascript ×2
mockito ×2
unit-testing ×2
angular ×1
bash ×1
iterator ×1
jaxb ×1
marshalling ×1
node.js ×1
powermock ×1