File tree Expand file tree Collapse file tree
main/java/io/ipfs/multihash
test/java/io/ipfs/multihash Expand file tree Collapse file tree Original file line number Diff line number Diff line change 7878 <groupId >org.apache.maven.plugins</groupId >
7979 <artifactId >maven-surefire-plugin</artifactId >
8080 <version >2.19.1</version >
81+ <configuration >
82+ <!-- Sets the VM argument line used when unit tests are run. -->
83+ <argLine >${surefireArgLine} </argLine >
84+ </configuration >
8185 </plugin >
8286 <plugin >
8387 <groupId >org.apache.maven.plugins</groupId >
9195 </archive >
9296 </configuration >
9397 </plugin >
98+ <plugin >
99+ <groupId >org.jacoco</groupId >
100+ <artifactId >jacoco-maven-plugin</artifactId >
101+ <version >0.7.8</version >
102+ <executions >
103+ <!--
104+ Prepares the property pointing to the JaCoCo runtime agent which
105+ is passed as VM argument when Maven the Surefire plugin is executed.
106+ -->
107+ <execution >
108+ <id >pre-unit-test</id >
109+ <goals >
110+ <goal >prepare-agent</goal >
111+ </goals >
112+ <configuration >
113+ <!-- Sets the path to the file which contains the execution data. -->
114+ <destFile >${project.build.directory} /coverage-reports/jacoco-ut.exec</destFile >
115+ <!--
116+ Sets the name of the property containing the settings
117+ for JaCoCo runtime agent.
118+ -->
119+ <propertyName >surefireArgLine</propertyName >
120+ </configuration >
121+ </execution >
122+ <!--
123+ Ensures that the code coverage report for unit tests is created after
124+ unit tests have been run.
125+ -->
126+ <execution >
127+ <id >post-unit-test</id >
128+ <phase >test</phase >
129+ <goals >
130+ <goal >report</goal >
131+ </goals >
132+ <configuration >
133+ <!-- Sets the path to the file which contains the execution data. -->
134+ <dataFile >${project.build.directory} /coverage-reports/jacoco-ut.exec</dataFile >
135+ <!-- Sets the output directory for the code coverage report. -->
136+ <outputDirectory >${project.reporting.outputDirectory} /jacoco-ut</outputDirectory >
137+ </configuration >
138+ </execution >
139+ </executions >
140+ </plugin >
94141 </plugins >
95142 </build >
96143</project >
Original file line number Diff line number Diff line change @@ -92,11 +92,17 @@ public int hashCode() {
9292 return Arrays .hashCode (hash ) ^ type .hashCode ();
9393 }
9494
95+ final protected static char [] hexArray = "0123456789ABCDEF" .toCharArray ();
96+
9597 public String toHex () {
96- StringBuilder res = new StringBuilder ();
97- for (byte b : toBytes ())
98- res .append (String .format ("%x" , b &0xff ));
99- return res .toString ();
98+ byte [] bytes = toBytes ();
99+ char [] hexChars = new char [bytes .length * 2 ];
100+ for ( int j = 0 ; j < bytes .length ; j ++ ) {
101+ int v = bytes [j ] & 0xFF ;
102+ hexChars [j * 2 ] = hexArray [v >>> 4 ];
103+ hexChars [j * 2 + 1 ] = hexArray [v & 0x0F ];
104+ }
105+ return new String (hexChars );
100106 }
101107
102108 public String toBase58 () {
Original file line number Diff line number Diff line change 44import io .ipfs .multibase .*;
55import java .util .*;
66import java .security .MessageDigest ;
7+ import java .io .PipedInputStream ;
8+ import java .io .PipedOutputStream ;
79
810public class MultihashTest {
911
@@ -43,9 +45,11 @@ public void multihashTest() {
4345 // Test conversions
4446 assert (m .toBase58 ().equals (m2 .toBase58 ()));
4547 assert (m .toBase58 ().equals ((String )ex [2 ]));
48+ // Test fromHex and toHex
49+ Multihash m3 = Multihash .fromHex (m .toHex ());
50+ assert (m3 .equals (m ));
4651 }
4752 catch (Exception e ){
48- // Usually because a hash function not supported
4953 System .out .println (e .getMessage ());
5054 assert (false );
5155 }
You can’t perform that action at this time.
0 commit comments