From e246a0216600f091eea222b443f9b57293e7a251 Mon Sep 17 00:00:00 2001 From: aayush Date: Thu, 30 Mar 2023 10:32:32 +0530 Subject: [PATCH] IDE-151 Refactor Stopwatch.java to kotlin --- .../catroid/test/utils/StopwatchTest.kt | 39 +++++++++++++++++++ .../utils/{Stopwatch.java => Stopwatch.kt} | 22 +++++------ 2 files changed, 49 insertions(+), 12 deletions(-) create mode 100644 catroid/src/androidTest/java/org/catrobat/catroid/test/utils/StopwatchTest.kt rename catroid/src/main/java/org/catrobat/catroid/utils/{Stopwatch.java => Stopwatch.kt} (76%) diff --git a/catroid/src/androidTest/java/org/catrobat/catroid/test/utils/StopwatchTest.kt b/catroid/src/androidTest/java/org/catrobat/catroid/test/utils/StopwatchTest.kt new file mode 100644 index 00000000000..4c9889f9fe6 --- /dev/null +++ b/catroid/src/androidTest/java/org/catrobat/catroid/test/utils/StopwatchTest.kt @@ -0,0 +1,39 @@ +/* + * Catroid: An on-device visual programming system for Android devices + * Copyright (C) 2010-2023 The Catrobat Team + * () + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * An additional term exception under section 7 of the GNU Affero + * General Public License, version 3, is available at + * http://developer.catrobat.org/license_additional_term + * + * This program 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package org.catrobat.catroid.test.utils + +import junit.framework.TestCase.assertTrue +import org.catrobat.catroid.utils.Stopwatch +import org.junit.Test + +class StopwatchTest { + @Test + fun getElapsedMilliseconds() { + val stopwatch = Stopwatch() + stopwatch.start() + Thread.sleep(100L) + val elapsed = stopwatch.getElapsedMilliseconds() + assertTrue(elapsed in 100L..199) + } +} diff --git a/catroid/src/main/java/org/catrobat/catroid/utils/Stopwatch.java b/catroid/src/main/java/org/catrobat/catroid/utils/Stopwatch.kt similarity index 76% rename from catroid/src/main/java/org/catrobat/catroid/utils/Stopwatch.java rename to catroid/src/main/java/org/catrobat/catroid/utils/Stopwatch.kt index c82c107ebc8..86ecebc77c5 100644 --- a/catroid/src/main/java/org/catrobat/catroid/utils/Stopwatch.java +++ b/catroid/src/main/java/org/catrobat/catroid/utils/Stopwatch.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2023 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -20,17 +20,15 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package org.catrobat.catroid.utils; +package org.catrobat.catroid.utils -public class Stopwatch { +class Stopwatch { + private var start: Long = 0 + fun start() { + start = System.currentTimeMillis() + } - private long start; - - public void start() { - start = System.currentTimeMillis(); - } - - public long getElapsedMilliseconds() { - return (System.currentTimeMillis() - start); - } + fun getElapsedMilliseconds(): Long { + return System.currentTimeMillis() - start + } }