小编Lau*_*ens的帖子

单元测试将ResultSet作为参数的方法

如何对无法实例化的对象进行单元测试?因为目前我有一个将ResultSet转换为对象的方法,但我不确定这是否违反了任何编程原则.

public CItem convert(ResultSet rs) {
    CItem ci = new CItem ();

    try {
        ci.setHinumber(rs.getString("id"));
        ci.setHostname(rs.getString("sysname"));
        ci.setOs(rs.getString("zos"));
        ci.setTenant(rs.getString("customer_name"));
        //ci.setInstallation(rs.getField("installation_name"));
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return ci;
}
Run Code Online (Sandbox Code Playgroud)

我是否需要寻找一种不同的方式来解决这个问题,因为它不能进行单元测试?或者我可以以某种方式伪造ResultSet对象.

任何帮助,将不胜感激.

java junit unit-testing resultset

12
推荐指数
1
解决办法
6609
查看次数

浏览器使用JEditorPane强制蓝色背景

这是我用来在JEditorPane中显示谷歌的代码

String url="http://google.com";    
editorPane.setEditable(false);
    try {
        editorPane.setPage(url);
    } catch (IOException e) {}
Run Code Online (Sandbox Code Playgroud)

但由于某种原因,背景将始终是蓝色,如果我打电话无关紧要

setBackgroundColor(Color.WHITE);
Run Code Online (Sandbox Code Playgroud)

java url swing colors jeditorpane

9
推荐指数
1
解决办法
1088
查看次数

导入以tilde开头的node_modules的Gulp sass问题

我正在通过gulp sass任务将.scss文件转换为.css.问题是基.scss文件包含包含其他导入的导入.这些进口始于

~@angular/material/core/etc/etc
Run Code Online (Sandbox Code Playgroud)

代字号会导致以下错误:

events.js:160
  throw er; // Unhandled 'error' event
  ^
Error: node_modules\@covalent\core\chips\_chips-theme.scss
Error: File to import not found or unreadable: ~@angular/material/core/theming/theming.
Parent style sheet: C:/Users/laurensk/Documents/Playground/node_modules/@covalent/core/chips/_chips-theme.scss
    on line 1 of node_modules/@covalent/core/chips/_chips-theme.scss
>> @import '~@angular/material/core/theming/theming';
   ^
Run Code Online (Sandbox Code Playgroud)

有一个名为node-sass-tilde-importer的自定义导入器,但我不确定是否可以将其实现到我的gulp sass任务中.

我的代码:

var gulp = require("gulp"),
sass = require("gulp-sass");
//var replace = require('gulp-replace');
//var sassGlob = require('gulp-sass-glob');
//var tildeImporter = require('node-sass-tilde-importer');

gulp.task("sass", function () {
  return gulp
    .src('Styles/theme.scss')
    .pipe(sass())
    .pipe(gulp.dest('wwwroot/dist'));
});
Run Code Online (Sandbox Code Playgroud)

我已尝试使用'./node_modules'替换'〜',但它会抛出相同的错误.

任何输入将不胜感激!

sass gulp

8
推荐指数
1
解决办法
2676
查看次数

Maven servlet编译“所有类都是最新的”

我是 maven 和 servlets 的新手,但我绝对不知所措。它拒绝在每一个转弯和转弯处工作,并且由于某种原因它说“没有什么可以编译 - 所有类都是最新的”,尽管我已经改变了所有需要改变的东西。

这是我的 servlet:

@WebServlet("/HelloWorld")
public class HelloWorldServlet extends HttpServlet {

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    response.setContentType("text/html");
    response.setCharacterEncoding("UTF-8");

    String hold = request.getParameter("text");

    try(PrintWriter out = response.getWriter()) {
        out.println("<!DOCTYPE html>");
        out.println("<html>");
        out.println("<body>");
        out.println("<p>"+hold+"</p>");
        out.println("</body>");
        out.println("</html>");
    }
}
Run Code Online (Sandbox Code Playgroud)

}

这是我的 pom.xml:

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>pxl.kits</groupId>
  <artifactId>Webcomponents</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>  

  <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <project.build.sourceEncoding>
    UTF-8
    </project.build.sourceEncoding>
  </properties>

  <build>
      <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.0</version>
        </plugin>

        <plugin>
            <groupId>org.codehaus.cargo</groupId>
            <artifactId>cargo-maven2-plugin</artifactId>
            <version>1.4.12</version>
            <configuration>
                <container>
                <containerId>tomcat8x</containerId> …
Run Code Online (Sandbox Code Playgroud)

java servlets pom.xml maven

6
推荐指数
0
解决办法
4476
查看次数

通过RethinkDB中的Horizo​​nIO查找记录而不返回结果

我有一个MeetingService,通过Horizo​​nIO从我的RethinkDB中获取数据.当尝试通过其ID获取会议时,我将始终获得null值作为响应.此服务中的其他方法无问题.

meeting.service.ts:

getMeetingById(passedId: string): Observable<Meeting[]> {
    return this.table.find({meetingId: passedId}).fetch();
}
Run Code Online (Sandbox Code Playgroud)

会议-detail.component.ts:

currentMeeting: Meeting;

getCurrentMeeting(): void {
    this._meetingsService.getMeetingById(this.passedId).subscribe(
        (returnMeetings: Meeting[]) => {
            this.currentMeeting = returnMeetings[0];
        }
    );
}
Run Code Online (Sandbox Code Playgroud)

即使我将passId更改为我直接从我的数据库(通过管理面板)获取的ID,该方法仍然返回null.

如果我更改代码以返回表中的第一个值,一切都会起作用.

getMeetingById(passedId: string): Observable<Meeting[]> {
    return this.table.order("meetingId", "descending").limit(1).fetch();
}
Run Code Online (Sandbox Code Playgroud)

最终结果是在我的视图中currentMeeting var上未定义错误:

EXCEPTION: Error in ./MeetingDetailComponent class MeetingDetailComponent - inline template:1:4 caused by: 
Cannot read property 'meetingId' of undefined
Run Code Online (Sandbox Code Playgroud)

编辑:显示不同实现的附加代码:

load() {
    if(this.passedId != null) {
      this._feedService.GetFeedById(this.passedId).subscribe(
          (returnFeed: Feed[]) => {
            this.currentFeed = returnFeed[0];
          }
      );
    } else {
      this._feedService.GetFirstFeed().subscribe(
          (returnFeed: Feed[]) => …
Run Code Online (Sandbox Code Playgroud)

typescript rethinkdb horizon angular

6
推荐指数
1
解决办法
97
查看次数

预检的响应具有无效的HTTP状态代码:401 angular

使用angular和Spring Boot,我们正在尝试为我们的服务添加身份验证,但出于某种原因,我们无法"打开"并从我们知道工作的URL中获取数据

角度:

this.getMismatches = function () {
    return $http({
            "async": true,
            "crossDomain": true,
            "url": GLOBALS.mismatchUrl,
            "method": "GET",
            "headers": {
                "authorization": "Basic YWRtaW46USNROawdNmY3UWhxQDlQA1VoKzU="
        }
    });
}
Run Code Online (Sandbox Code Playgroud)

(目前登录令牌是硬编码的,用于测试目的)

休息服务:

@CrossOrigin(origins = "*")
@RequestMapping("/api/mismatch")
public List<Mismatch> home() {
    return service.getAll();
}
Run Code Online (Sandbox Code Playgroud)

CrossOrigin =*应该处理CORS问题,但这个失败的URL调用真的很奇怪.

我们尝试过的额外的东西:

'Access-Control-Allow-Methods', 'GET, POST, OPTIONS'
'Access-Control-Allow-Origin', '*'
'Content-Type', json plaintext jsonp etc

App.js:
    $httpProvider.defaults.headers.common = {};
    $httpProvider.defaults.headers.post = {};
    $httpProvider.defaults.headers.put = {};
    $httpProvider.defaults.headers.patch = {};
Run Code Online (Sandbox Code Playgroud)

javascript java angularjs spring-boot

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

从谷歌地图api中的地址获取latlng

我将如何从地址获取纬度和经度?

我目前的方法是将地址传递给 google maps api:

getLocationJson(term: string) {
    var term = "Mechelsesteenweg+64";
   return this._http.get('https://maps.googleapis.com/maps/api/geocode/json?address=Someroad+64&key=AIzkeystuffjXDm6eU5mPP9Nczg')
   .subscribe((json: any) => {
        var obj = JSON.parse(json);
        var jsonParsed = obj["results"];
    });
}
Run Code Online (Sandbox Code Playgroud)

但我觉得这不是正确的方法。我可以为此使用地理编码器吗?就像是:

getGeoLocation(address: string) {
    let geocoder = new google.maps.Geocoder();
    geocoder.geocode({ 'address': address }, function (results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
          var latlng = google.maps.location.LatLng();
        } else {
            alert('Geocode was not successful for the following reason: ' + status);
        }
    });
}
Run Code Online (Sandbox Code Playgroud)

提前致谢。(基本上是这个问题,但反过来了)

google-maps-api-3 typescript angular

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