@@ -69,7 +69,7 @@ public T withTitle(String title) {
6969 * @return instance of type Snapshot
7070 */
7171 public T withThumbnail (String path , String name , double scale ) {
72- File thumbnailFile = new File (path . toString () , name );
72+ File thumbnailFile = new File (path , name );
7373 if (!Files .exists (Paths .get (path ))) {
7474 thumbnailFile .mkdirs ();
7575 }
@@ -90,10 +90,7 @@ public T withThumbnail(String path, String name, double scale) {
9090 * @return instance of type Snapshot
9191 */
9292 public T withCroppedThumbnail (String path , String name , double scale , double cropWidth , double cropHeight ) {
93- File thumbnailFile = new File (path .toString (), name );
94- if (!Files .exists (Paths .get (path ))) {
95- thumbnailFile .mkdirs ();
96- }
93+ File thumbnailFile = getFile (path , name );
9794 thumbnailImage =ImageProcessor .cropAndScale (image ,scale , cropWidth , cropHeight );
9895 FileUtil .writeImage (thumbnailImage , EXTENSION , thumbnailFile );
9996 return self ();
@@ -111,15 +108,27 @@ public T withCroppedThumbnail(String path, String name, double scale, double cr
111108 * @return instance of type Snapshot
112109 */
113110 public T withCroppedThumbnail (String path , String name , double scale , int maxWidth , int maxHeight ) {
114- File thumbnailFile = new File (path .toString (), name );
115- if (!Files .exists (Paths .get (path ))) {
116- thumbnailFile .mkdirs ();
117- }
111+ File thumbnailFile = getFile (path , name );
118112 thumbnailImage =ImageProcessor .cropAndScale (image ,scale , maxWidth , maxHeight );
119113 FileUtil .writeImage (thumbnailImage , EXTENSION , thumbnailFile );
120114 return self ();
121115 }
122-
116+
117+ /**
118+ * Generate file for cropped thumbnail of the original screenshot.
119+ *
120+ * @param path to save thumbnail image to
121+ * @param name of the resulting image
122+ * @return instance of type File
123+ */
124+ private File getFile (String path , String name ) {
125+ File thumbnailFile = new File (path , name );
126+ if (!Files .exists (Paths .get (path ))) {
127+ thumbnailFile .mkdirs ();
128+ }
129+ return thumbnailFile ;
130+ }
131+
123132 /**
124133 * Generate cropped thumbnail of the original screenshot.
125134 * Will save different thumbnails depends on when it was called in the chain.
0 commit comments