Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CheckBuilder::from #175

wants to merge 1 commit into from
Changes from all commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.


Just for now

@@ -27,6 +27,7 @@ module {
requires 'org.openjdk.skara.test'
requires 'org.junit.jupiter.api'
requires 'jdk.httpserver'
opens '' to 'org.junit.platform.commons'
opens '' to 'org.junit.platform.commons'
opens '' to 'org.junit.platform.commons'
@@ -53,6 +53,28 @@ public static CheckBuilder create(String name, Hash hash) {
return new CheckBuilder(name, hash);

public static CheckBuilder from(Check c) {
var builder = new CheckBuilder(, c.hash());
builder.startedAt = c.startedAt();
builder.status = c.status();
builder.annotations = c.annotations();

if (c.title().isPresent()) {
builder.title = c.title().get();
if (c.summary().isPresent()) {
builder.summary = c.summary().get();
if (c.completedAt().isPresent()) {
builder.completedAt = c.completedAt().get();
if (c.metadata().isPresent()) {
builder.metadata = c.metadata().get();

return builder;

public CheckBuilder metadata(String metadata) {
this.metadata = metadata;
return this;
@@ -0,0 +1,107 @@
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit if you need additional information or have any
* questions.

import org.openjdk.skara.vcs.Hash;

import java.time.ZonedDateTime;
import java.util.List;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;

class CheckBuilderTests {
void testFrom() {
var hash = new Hash("0".repeat(40));
var name = "test";
var title = "title";
var summary = "summary";
var metadata = "metadata";
var annotation = CheckAnnotationBuilder.create("README", 0, 1, CheckAnnotationLevel.NOTICE, "Message")
var startedAt =;
var completedAt =;
var success = true;

var existing = CheckBuilder.create(name, hash)
.complete(success, completedAt)
var dup = CheckBuilder.from(existing)

assertEquals(existing.hash(), dup.hash());
assertEquals(existing.status(), dup.status());
assertEquals(existing.startedAt(), dup.startedAt());
assertEquals(existing.completedAt(), dup.completedAt());
assertEquals(existing.title(), dup.title());
assertEquals(existing.summary(), dup.summary());
assertEquals(existing.metadata(), dup.metadata());
assertEquals(existing.annotations(), dup.annotations());

var newTitle = "new title";
var newSummary = "new summary";
var newMetadata = "new metadata";
var newAnnotation = CheckAnnotationBuilder.create("FILE", 0, 1, CheckAnnotationLevel.NOTICE, "Message")
var newStartedAt =;
var newCompletedAt =;
var newSuccess = false;

var modified = CheckBuilder.from(existing)
.complete(newSuccess, newCompletedAt)

// existing check should not have changed
assertEquals(dup.hash(), existing.hash());
assertEquals(dup.status(), existing.status());
assertEquals(dup.startedAt(), existing.startedAt());
assertEquals(dup.completedAt(), existing.completedAt());
assertEquals(dup.title(), existing.title());
assertEquals(dup.summary(), existing.summary());
assertEquals(dup.metadata(), existing.metadata());
assertEquals(dup.annotations(), existing.annotations());

// modified should have new values except name and hash and inherit annotations
assertEquals(existing.hash(), modified.hash());
assertEquals(newStartedAt, modified.startedAt());
assertEquals(newCompletedAt, modified.completedAt().get());
assertEquals(newTitle, modified.title().get());
assertEquals(newSummary, modified.summary().get());
assertEquals(newMetadata, modified.metadata().get());
assertEquals(List.of(annotation, newAnnotation), modified.annotations());
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.