Skip to content

Commit

Permalink
Some Cleanups (#79)
Browse files Browse the repository at this point in the history
* Enforce reloading of snapshots

* Enforce no optionals in parameters & Use u code for symbols
  • Loading branch information
dfuchss authored Nov 21, 2024
1 parent 080cf4d commit 59b5aa4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,7 @@ spotless {
importOrderFile('spotless.importorder')
}
}

configurations.configureEach {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import java.awt.event.ItemEvent;
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;

import javax.swing.JButton;
Expand Down Expand Up @@ -283,25 +282,25 @@ private void handleCourseSelected(ItemEvent e) {
}
}

private void handleConnectionChange(Optional<ArtemisConnection> connection) {
private void handleConnectionChange(ArtemisConnection connection) {
courseSelector.removeAllItems();

if (connection.isPresent()) {
if (connection != null) {
// When a connection is established, update the course selector with the courses of the connection
try {
connectedLabel.setText(" Connected to "
+ connection.get().getClient().getInstance().getDomain() + " as "
+ connection.get().getAssessor().getLogin());
connectedLabel.setText("\u2714 Connected to "
+ connection.getClient().getInstance().getDomain() + " as "
+ connection.getAssessor().getLogin());
connectedLabel.setForeground(JBColor.GREEN);
for (Course course : connection.get().getCourses()) {
for (Course course : connection.getCourses()) {
courseSelector.addItem(course);
}
} catch (ArtemisNetworkException ex) {
LOG.warn(ex);
ArtemisUtils.displayNetworkErrorBalloon("Failed to fetch course info", ex);
}
} else {
connectedLabel.setText(" Not connected");
connectedLabel.setText("\u274C Not connected");
connectedLabel.setForeground(JBColor.RED);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class PluginState {

private static PluginState pluginState;

private final List<Consumer<Optional<ArtemisConnection>>> connectedListeners = new ArrayList<>();
private final List<Consumer<ArtemisConnection>> connectedListeners = new ArrayList<>();
private final List<Consumer<ActiveAssessment>> assessmentStartedListeners = new ArrayList<>();
private final List<Runnable> assessmentClosedListeners = new ArrayList<>();

Expand Down Expand Up @@ -143,9 +143,9 @@ public void connect() {
});
}

public void registerConnectedListener(Consumer<Optional<ArtemisConnection>> listener) {
public void registerConnectedListener(Consumer<ArtemisConnection> listener) {
this.connectedListeners.add(listener);
listener.accept(Optional.ofNullable(this.connection));
listener.accept(this.connection);
}

public boolean isAssessing() {
Expand Down Expand Up @@ -318,8 +318,8 @@ private void verifyLogin() throws ArtemisClientException {

private void notifyConnectedListeners() {
ApplicationManager.getApplication().invokeLater(() -> {
for (Consumer<Optional<ArtemisConnection>> l : this.connectedListeners) {
l.accept(Optional.ofNullable(this.connection));
for (Consumer<ArtemisConnection> l : this.connectedListeners) {
l.accept(this.connection);
}
});
}
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/edu/kit/kastel/ArchitectureTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.*;

import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.stream.Stream;

Expand All @@ -24,4 +25,10 @@ class ArchitectureTest {
.orShould()
.callMethod(List.class, "forEachOrdered", Consumer.class)
.because("Lambdas should be functional. ForEach is typically used for side-effects.");

@ArchTest
static final ArchRule noOptionalAsParameter = noMethods()
.should()
.haveRawParameterTypes(Optional.class)
.because("Optional should be used as return type only.");
}

0 comments on commit 59b5aa4

Please sign in to comment.