-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
192 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 5 additions & 10 deletions
15
src/main/java/com/github/kunai/source/factories/DataSourceFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.github.kunai.util; | ||
|
||
import java.util.Optional; | ||
|
||
public class Exceptions { | ||
public static <T> boolean isThrowed(T argument, ThrowableConsumer<T, Exception> consumer){ | ||
try{ consumer.apply(argument); } | ||
catch(Exception e){ return false; } | ||
return true; | ||
} | ||
|
||
public static <T, S> boolean isThrowed(T argument1, S argument2, | ||
ThrowableBiConsumer<T, S, Exception> consumer){ | ||
try{ consumer.apply(argument1, argument2); } | ||
catch(Exception e){ return false; } | ||
return true; | ||
} | ||
|
||
public static <T> boolean isThrowedCondition(T argument, | ||
ThrowablePredicate<T, Exception> predicate){ | ||
try{ return predicate.test(argument); } | ||
catch(Exception e){ return false; } | ||
} | ||
|
||
public static <T, S> boolean isThrowedCondition(T argument1, S argument2, | ||
ThrowableBiPredicate<T, S, Exception> predicate){ | ||
try{ return predicate.test(argument1, argument2); } | ||
catch(Exception e){ return false; } | ||
} | ||
|
||
public static <A1, A2, R> Optional<R> map(A1 argument1, A2 argument2, | ||
ThrowableBiFunction<A1, A2, R, Exception> func){ | ||
try{ return Optional.of(func.apply(argument1, argument2)); } | ||
catch(Exception e){ } | ||
return Optional.empty(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.github.kunai.util; | ||
|
||
import java.nio.file.Path; | ||
|
||
public class PathHelper { | ||
public static boolean endsWith(Path path, String suffix){ | ||
String name = path.toString(); | ||
return name.endsWith(suffix); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.github.kunai.util; | ||
|
||
public interface ThrowableBiConsumer<S1, S2, E extends Exception> { | ||
void apply(S1 s1, S2 s2) throws E; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.github.kunai.util; | ||
|
||
public interface ThrowableBiFunction<A1, A2, R, E extends Exception> { | ||
R apply(A1 argument1, A2 argument) throws E; | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/com/github/kunai/util/ThrowableBiPredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.github.kunai.util; | ||
|
||
@FunctionalInterface | ||
public interface ThrowableBiPredicate<S1, S2, E extends Exception> { | ||
boolean test(S1 s1, S2 s2) throws E; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.github.kunai.util; | ||
|
||
@FunctionalInterface | ||
public interface ThrowableConsumer<S, E extends Exception> { | ||
void apply(S argument) throws E; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.github.kunai.util; | ||
|
||
@FunctionalInterface | ||
public interface ThrowablePredicate<S, E extends Exception> { | ||
boolean test(S argument) throws E; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/test/java/com/github/kunai/source/factories/DataSourceFactoriesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.github.kunai.source.factories; | ||
|
||
import static org.hamcrest.CoreMatchers.instanceOf; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.junit.Assert.assertThat; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.FileSystems; | ||
import java.nio.file.Paths; | ||
import java.util.Optional; | ||
|
||
import org.junit.Test; | ||
|
||
import com.github.kunai.util.Assert; | ||
|
||
public class DataSourceFactoriesTest { | ||
private DataSourceFactories factories = new DataSourceFactories(); | ||
|
||
@Test | ||
public void testDirectory() throws Exception{ | ||
Optional<DataSourceFactory> factory = factories.find(Paths.get("target/classes"), FileSystems.getDefault()); | ||
|
||
assertThat(factory.isPresent(), is(true)); | ||
assertThat(factory.get(), is(instanceOf(DirectoryDataSourceFactory.class))); | ||
} | ||
|
||
@Test | ||
public void testJar() throws Exception{ | ||
Optional<DataSourceFactory> factory = factories.find(Paths.get("target/test-classes/hello/target/hello-1.0-SNAPSHOT.jar"), FileSystems.getDefault()); | ||
|
||
assertThat(factory.isPresent(), is(true)); | ||
assertThat(factory.get(), is(instanceOf(JarFileDataSourceFactory.class))); | ||
} | ||
|
||
@Test | ||
public void testNotExistsJar() throws Exception{ | ||
Assert.assertThrows(IOException.class, | ||
() -> factories.find(Paths.get("not/exists/jar"))); | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/test/java/com/github/kunai/source/factories/DefaultDataSourceFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.github.kunai.source.factories; | ||
|
||
import org.junit.Test; | ||
|
||
public class DefaultDataSourceFactoryTest { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.github.kunai.util; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
public class Assert { | ||
public static <E extends Exception> void assertThrows(Class<E> exceptionClass, ThrowableProcessor<E> processor){ | ||
boolean thrown = false; | ||
try { processor.perform(); } | ||
catch (Exception ex) { | ||
thrown = exceptionClass.isInstance(ex); | ||
} | ||
assertTrue(thrown); | ||
} | ||
} |
Oops, something went wrong.