Skip to content

Commit

Permalink
chore: remove unused function in JwtToVerifiableCredentialTransformer
Browse files Browse the repository at this point in the history
  • Loading branch information
bscholtes1A committed Feb 19, 2024
1 parent 6c48818 commit ba6f24b
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@

import org.eclipse.edc.transform.spi.TypeTransformer;

import java.time.Instant;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;

Expand All @@ -29,9 +27,7 @@ abstract class AbstractJwtTransformer<OUTPUT> implements TypeTransformer<String,


protected static final String TYPE_PROPERTY = "type";


private static final String VALUE_PROPERTY = "value";


private final Class<OUTPUT> output;

Expand Down Expand Up @@ -67,15 +63,4 @@ protected <T> List<T> listOrReturn(Object o, Function<Object, T> mapping) {
return List.of(mapping.apply(o));
}

/**
* Convert the provided object into an {@link Instant}.
* Handle the case where the instance if provided as a map.
*/
protected Instant toInstant(Object o) {
var str = o.toString();
if (o instanceof Map) {
str = ((Map) o).get(VALUE_PROPERTY).toString();
}
return Instant.parse(str);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ public JwtToVerifiableCredentialTransformer(Monitor monitor) {

private Optional<Instant> extractDate(@Nullable Object dateObject, Date fallback) {
return ofNullable(dateObject)
.map(this::toInstant)
.map(Object::toString)
.map(Instant::parse)
.or(() -> ofNullable(fallback).map(Date::toInstant));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.time.Instant;
import java.util.List;
import java.util.Map;

import static org.assertj.core.api.Assertions.assertThat;

Expand Down Expand Up @@ -67,22 +65,4 @@ void listOrReturn_return() {
.contains(2);
}

@Test
void toInstant_string() {
Object obj = Instant.now();

var result = transformer.toInstant(obj.toString());

assertThat(result).isEqualTo(obj);
}

@Test
void toInstant_map() {
var now = Instant.now();
var obj = Map.of("value", now.toString());

var result = transformer.toInstant(obj);

assertThat(result).isEqualTo(now);
}
}

0 comments on commit ba6f24b

Please sign in to comment.