Skip to content

Commit

Permalink
Merge pull request DevelopersDelicias#27 from DevelopersDelicias/enha…
Browse files Browse the repository at this point in the history
…ncement/26-add-prettier-plugin

🎨 DevelopersDelicias#26 Add prettier plugin and format code for all classes
  • Loading branch information
bcisneros authored Sep 27, 2023
2 parents 9788a72 + 88dd782 commit 1c12f42
Show file tree
Hide file tree
Showing 14 changed files with 141 additions and 62 deletions.
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"printWidth": 80,
"tabWidth": 4,
"useTabs": false,
"endOfLine": "lf"
}
27 changes: 27 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
<maven-failsafe-plugin.version>2.21.0</maven-failsafe-plugin.version>
<maven-jar-plugin.version>3.1.0</maven-jar-plugin.version>
<plugin.prettier.goal>write</plugin.prettier.goal>
</properties>
<name>task-timer</name>
<url>http://maven.apache.org</url>
Expand Down Expand Up @@ -202,6 +203,32 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.hubspot.maven.plugins</groupId>
<artifactId>prettier-maven-plugin</artifactId>
<version>0.16</version>
<configuration>
<prettierJavaVersion>1.5.0</prettierJavaVersion>
<ignoreConfigFile>false</ignoreConfigFile>
<ignoreEditorConfig>true</ignoreEditorConfig>
<fail>true</fail>
<generateDiff>true</generateDiff>
<!-- Use <inputGlobs> to override the default input patterns -->
<inputGlobs>
<!-- These are the default patterns, you can omit <inputGlobs> entirely unless you want to override them -->
<inputGlob>src/main/java/**/*.java</inputGlob>
<inputGlob>src/test/java/**/*.java</inputGlob>
</inputGlobs>
</configuration>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>${plugin.prettier.goal}</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.developersdelicias.tasktimer;

import javax.swing.WindowConstants;

import com.developersdelicias.tasktimer.ui.TaskTimerScreen;
import javax.swing.WindowConstants;

/**
* This class will be the implementation of the application.
Expand All @@ -14,7 +13,7 @@ public final class TaskTimerApplication {
* Can't be instantiated directly.
*/
private TaskTimerApplication() {

// empty constructor
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public final String format(final long milliseconds) {
final long hr = MILLISECONDS.toHours(milliseconds);
final long min = MILLISECONDS.toMinutes(subtract(milliseconds, hr));
final long sec = MILLISECONDS.toSeconds(
subtract(milliseconds, hr) - MINUTES.toMillis(min));
subtract(milliseconds, hr) - MINUTES.toMillis(min)
);
return String.format("%02d:%02d:%02d", hr, min, sec);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* Defines a format for Time elements.
*/
public interface TimeFormat {

/**
* Creates a String representation of the current time given the number of
* milliseconds elapsed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* This class will handle the different task timer states.
*/
public class TaskTimer {

/**
* A reference to TaskTimerView model object.
*/
Expand Down Expand Up @@ -70,13 +71,17 @@ public final void start() {
*/
private void updateView() {
timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
elapsedTime = System.currentTimeMillis() - initialTime;
view.updateTime(elapsedTime);
}
}, TIMER_DELAY, TIMER_PERIOD);
timer.scheduleAtFixedRate(
new TimerTask() {
@Override
public void run() {
elapsedTime = System.currentTimeMillis() - initialTime;
view.updateTime(elapsedTime);
}
},
TIMER_DELAY,
TIMER_PERIOD
);
}

/**
Expand Down Expand Up @@ -133,7 +138,6 @@ final boolean isRunning() {
* @return the actualState as PAUSED.
*/
final boolean isPaused() {

return actualState == PAUSED;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
* Exception for Timer already paused.
*/
class TaskTimerAlreadyPausedException extends RuntimeException {
// empty class
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
* Exception for Timer already started.
*/
class TaskTimerAlreadyStartedException extends RuntimeException {
// empty class
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
* Exception for Timer already stopped.
*/
class TaskTimerAlreadyStoppedException extends RuntimeException {

// empty class
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
* Exception for Timer already paused.
*/
class TaskTimerCannotPlayException extends RuntimeException {
// empty class
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
import com.developersdelicias.tasktimer.format.TimeFormat;
import com.developersdelicias.tasktimer.model.TaskTimer;
import com.developersdelicias.tasktimer.model.TaskTimerView;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.UnsupportedLookAndFeelException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Represents the Main Screen of Task Timer Application.
Expand Down Expand Up @@ -155,18 +156,22 @@ private void createButtons() {
*/
private void lookAndFeel() {
try {
for (UIManager.LookAndFeelInfo info
: UIManager.getInstalledLookAndFeels()) {
if ("Windows".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
for (LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) {
if ("Windows".equals(laf.getName())) {
UIManager.setLookAndFeel(laf.getClassName());
break;
}
}
} catch (ClassNotFoundException | InstantiationException
| IllegalAccessException | UnsupportedLookAndFeelException ex) {
final String msg = "Could not apply look and feel style. "
+ "Native Style will be used";
logger.warn(msg, ex);
} catch (
ClassNotFoundException
| InstantiationException
| IllegalAccessException
| UnsupportedLookAndFeelException ex
) {
logger.warn(
"Can't apply look and feel style. Native Style will be used",
ex
);
}
}

Expand All @@ -188,9 +193,12 @@ public final void startState() {

@Override
public final boolean shouldStop() {
int option = JOptionPane.showConfirmDialog(this,
"Are you sure to stop the timer?", "Task Timer",
JOptionPane.YES_NO_OPTION);
int option = JOptionPane.showConfirmDialog(
this,
"Are you sure to stop the timer?",
"Task Timer",
JOptionPane.YES_NO_OPTION
);
return option == JOptionPane.YES_OPTION;
}

Expand Down Expand Up @@ -246,8 +254,10 @@ public void actionPerformed(final ActionEvent e) {
*/
private String askTaskDescription() {
return JOptionPane.showInputDialog(
null, "Enter task description",
"Create Task", JOptionPane.INFORMATION_MESSAGE
null,
"Enter task description",
"Create Task",
JOptionPane.INFORMATION_MESSAGE
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.developersdelicias.tasktimer.format;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;

import junitparams.JUnitParamsRunner;
import junitparams.Parameters;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;

@RunWith(JUnitParamsRunner.class)
public class BasicTimeFormatTest {
Expand All @@ -20,8 +20,18 @@ public void setUp() {
}

@Test
@Parameters({"1000, 00:00:01", "2000, 00:00:02", "60000, 00:01:00", "3600000, 01:00:00"})
public void should_format_using_hh_mm_ss_format(int milliseconds, String expected) {
@Parameters(
{
"1000, 00:00:01",
"2000, 00:00:02",
"60000, 00:01:00",
"3600000, 01:00:00",
}
)
public void should_format_using_hh_mm_ss_format(
int milliseconds,
String expected
) {
assertThat(format.format(milliseconds), is(expected));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.developersdelicias.tasktimer.model;

import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.anyLong;
Expand All @@ -10,6 +8,9 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import org.junit.Before;
import org.junit.Test;

public class TaskTimerTest {

private TaskTimer taskTimer;
Expand Down Expand Up @@ -102,4 +103,4 @@ public void should_throw_cannot_play_exception() {
public void should_throw_cannot_play_exception_by_default() {
taskTimer.play();
}
}
}
Loading

0 comments on commit 1c12f42

Please sign in to comment.