Skip to content

Commit

Permalink
Merge PR #3382 by @ar0ne - game details screen
Browse files Browse the repository at this point in the history
  • Loading branch information
Cervator committed Jun 11, 2018
2 parents ef4655b + ca666da commit c42e530
Show file tree
Hide file tree
Showing 17 changed files with 1,150 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright 2018 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.terasology.utilities.time;

import org.junit.Assert;
import org.junit.Test;

import java.util.Arrays;

public class DateTimeHelperTest {

@Test
public void testGetDeltaBetweenTimestamps() {
Assert.assertEquals("00h 00m 01s", DateTimeHelper.getDeltaBetweenTimestamps(0, 1000));
Assert.assertEquals("00h 00m 10s", DateTimeHelper.getDeltaBetweenTimestamps(0, 10 * 1000));
Assert.assertEquals("00h 01m 00s", DateTimeHelper.getDeltaBetweenTimestamps(0, 60 * 1000));
Assert.assertEquals("00h 11m 00s", DateTimeHelper.getDeltaBetweenTimestamps(0, 60 * 1000 * 11));
Assert.assertEquals("01h 00m 00s", DateTimeHelper.getDeltaBetweenTimestamps(0, 60 * 1000 * 60));
Assert.assertEquals("12h 34m 56s", DateTimeHelper.getDeltaBetweenTimestamps(0, 60 * 1000 * 60 * 12 + 60 * 1000 * 34 + 56 * 1000));

Assert.assertEquals("1 Days 01h 00m 00s", DateTimeHelper.getDeltaBetweenTimestamps(0, 60 * 1000 * 60 * 25));
Assert.assertEquals("1 Days 01h 20m 40s", DateTimeHelper.getDeltaBetweenTimestamps(0, 60 * 1000 * 60 * 24 + 60 * 1000 * 60 + 60 * 1000 * 20 + 40 * 1000));

Assert.assertEquals("00h 00m 00s", DateTimeHelper.getDeltaBetweenTimestamps(1000, 1000));
Assert.assertEquals("00h 00m 00s", DateTimeHelper.getDeltaBetweenTimestamps(50000, 50000));

Assert.assertEquals("11h 01m 01s", DateTimeHelper.getDeltaBetweenTimestamps(1000 * 60 * 25, 1000 * 60 * 25 + 60 * 1000 * 60 * 11 + 60 * 1000 + 1000));
}

@Test
public void testGetDeltaBetweenTimestampsWrongData() {

Integer[][] wrongData = {
{-1, 50000},
{123, -1000},
{-667, -1000},
{123, 0},
{12321321, 1231}
};

Arrays.stream(wrongData).forEach(
data -> {
try {
DateTimeHelper.getDeltaBetweenTimestamps(data[0], data[1]);
Assert.fail("Exception should be thrown!");
} catch (IllegalArgumentException ex) {
Assert.assertEquals("Wrong timestamp values: " + data[0] + " or " + data[1], ex.getMessage());
}
}
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import java.util.Collection;
import java.util.List;
import java.util.Optional;

/**
*/
Expand Down Expand Up @@ -121,6 +122,11 @@ public final <T extends UIWidget> T find(String targetId, Class<T> type) {
return null;
}

@Override
public <T extends UIWidget> Optional<T> tryFind(String id, Class<T> type) {
return Optional.ofNullable(find(id, type));
}

@Override
public final <T extends UIWidget> Collection<T> findAll(Class<T> type) {
List<T> results = Lists.newArrayList();
Expand Down
10 changes: 10 additions & 0 deletions engine/src/main/java/org/terasology/rendering/nui/UIWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.terasology.rendering.nui.skin.UISkin;

import java.util.Collection;
import java.util.Optional;

/**
*/
Expand Down Expand Up @@ -69,6 +70,15 @@ public interface UIWidget extends Iterable<UIWidget> {
*/
<T extends UIWidget> T find(String id, Class<T> type);

/**
* Try to find a widget with the given id and type, within the current widget and its contents.
*
* @param id of widget to search
* @param <T> type of widget to cast
* @return optional widget with the given id and type
*/
<T extends UIWidget> Optional<T> tryFind(String id, Class<T> type);

<T extends UIWidget> Collection<T> findAll(Class<T> type);

void onDraw(Canvas canvas);
Expand Down
Loading

0 comments on commit c42e530

Please sign in to comment.