|
1 | 1 | package com.securenative.utils; |
2 | 2 |
|
| 3 | +import com.securenative.ResourceStreamImpl; |
| 4 | +import com.securenative.config.ConfigurationManager; |
3 | 5 | import org.junit.jupiter.api.Test; |
| 6 | +import org.mockito.Mockito; |
4 | 7 |
|
| 8 | +import java.io.ByteArrayInputStream; |
5 | 9 | import java.io.IOException; |
6 | | -import java.net.JarURLConnection; |
7 | | -import java.net.URL; |
8 | | -import java.util.Enumeration; |
9 | | -import java.util.jar.Attributes; |
10 | | -import java.util.jar.Manifest; |
| 10 | +import java.io.InputStream; |
| 11 | + |
| 12 | +import static org.assertj.core.api.Assertions.assertThat; |
11 | 13 |
|
12 | 14 | public class VersionTest { |
13 | 15 |
|
14 | 16 | @Test |
15 | | - public void testManifest() throws IOException { |
16 | | - URL res = org.junit.Assert.class.getResource(org.junit.Assert.class.getSimpleName() + ".class"); |
17 | | - JarURLConnection conn = (JarURLConnection) res.openConnection(); |
18 | | - Manifest mf = conn.getManifest(); |
19 | | - |
20 | | - Attributes atts = mf.getMainAttributes(); |
21 | | - for (Object v : atts.values()) { |
22 | | - System.out.println(v); |
23 | | - } |
| 17 | + public void testVersionExtraction() throws IOException { |
| 18 | + |
| 19 | + String props = String.join(System.getProperty("line.separator"), |
| 20 | + "version=1.0.0", |
| 21 | + "groupId=com.securenative.java", |
| 22 | + "artifactId=securenative-java"); |
| 23 | + |
| 24 | + InputStream inputStream = new ByteArrayInputStream(props.getBytes()); |
| 25 | + ResourceStreamImpl resourceStream = Mockito.spy(new ResourceStreamImpl()); |
| 26 | + Mockito.when(resourceStream.getInputStream("/META-INF/maven/com.securenative.java/securenative-java/pom.properties")).thenReturn(inputStream); |
| 27 | + |
| 28 | + VersionUtils.setResourceStream(resourceStream); |
| 29 | + |
| 30 | + assertThat(VersionUtils.getVersion()).isEqualTo("1.0.0"); |
| 31 | + |
| 32 | + // restore resource stream |
| 33 | + VersionUtils.setResourceStream(new ResourceStreamImpl()); |
24 | 34 | } |
25 | 35 | } |
0 commit comments