|
1 | 1 | /* |
2 | | - * Copyright 2002-2023 the original author or authors. |
| 2 | + * Copyright 2002-2024 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
31 | 31 | * @author Chris Beams |
32 | 32 | * @author Juergen Hoeller |
33 | 33 | */ |
34 | | -public class FileEditorTests { |
| 34 | +class FileEditorTests { |
35 | 35 |
|
36 | 36 | @Test |
37 | | - public void testClasspathFileName() { |
| 37 | + void testClasspathFileName() { |
38 | 38 | PropertyEditor fileEditor = new FileEditor(); |
39 | 39 | fileEditor.setAsText("classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) + "/" + |
40 | 40 | ClassUtils.getShortName(getClass()) + ".class"); |
41 | 41 | Object value = fileEditor.getValue(); |
42 | | - assertThat(value instanceof File).isTrue(); |
| 42 | + assertThat(value).isInstanceOf(File.class); |
43 | 43 | File file = (File) value; |
44 | 44 | assertThat(file).exists(); |
45 | 45 | } |
46 | 46 |
|
47 | 47 | @Test |
48 | | - public void testWithNonExistentResource() { |
49 | | - PropertyEditor propertyEditor = new FileEditor(); |
| 48 | + void testWithNonExistentResource() { |
| 49 | + PropertyEditor fileEditor = new FileEditor(); |
50 | 50 | assertThatIllegalArgumentException().isThrownBy(() -> |
51 | | - propertyEditor.setAsText("classpath:no_way_this_file_is_found.doc")); |
| 51 | + fileEditor.setAsText("classpath:no_way_this_file_is_found.doc")); |
52 | 52 | } |
53 | 53 |
|
54 | 54 | @Test |
55 | | - public void testWithNonExistentFile() { |
| 55 | + void testWithNonExistentFile() { |
56 | 56 | PropertyEditor fileEditor = new FileEditor(); |
57 | 57 | fileEditor.setAsText("file:no_way_this_file_is_found.doc"); |
58 | 58 | Object value = fileEditor.getValue(); |
59 | | - assertThat(value instanceof File).isTrue(); |
| 59 | + assertThat(value).isInstanceOf(File.class); |
60 | 60 | File file = (File) value; |
61 | 61 | assertThat(file).doesNotExist(); |
62 | 62 | } |
63 | 63 |
|
64 | 64 | @Test |
65 | | - public void testAbsoluteFileName() { |
| 65 | + void testAbsoluteFileName() { |
66 | 66 | PropertyEditor fileEditor = new FileEditor(); |
67 | 67 | fileEditor.setAsText("/no_way_this_file_is_found.doc"); |
68 | 68 | Object value = fileEditor.getValue(); |
69 | | - assertThat(value instanceof File).isTrue(); |
| 69 | + assertThat(value).isInstanceOf(File.class); |
70 | 70 | File file = (File) value; |
71 | 71 | assertThat(file).doesNotExist(); |
72 | 72 | } |
73 | 73 |
|
74 | 74 | @Test |
75 | | - public void testUnqualifiedFileNameFound() { |
| 75 | + void testCurrentDirectory() { |
| 76 | + PropertyEditor fileEditor = new FileEditor(); |
| 77 | + fileEditor.setAsText("file:."); |
| 78 | + Object value = fileEditor.getValue(); |
| 79 | + assertThat(value).isInstanceOf(File.class); |
| 80 | + File file = (File) value; |
| 81 | + assertThat(file).isEqualTo(new File(".")); |
| 82 | + } |
| 83 | + |
| 84 | + @Test |
| 85 | + void testUnqualifiedFileNameFound() { |
76 | 86 | PropertyEditor fileEditor = new FileEditor(); |
77 | 87 | String fileName = ClassUtils.classPackageAsResourcePath(getClass()) + "/" + |
78 | 88 | ClassUtils.getShortName(getClass()) + ".class"; |
79 | 89 | fileEditor.setAsText(fileName); |
80 | 90 | Object value = fileEditor.getValue(); |
81 | | - assertThat(value instanceof File).isTrue(); |
| 91 | + assertThat(value).isInstanceOf(File.class); |
82 | 92 | File file = (File) value; |
83 | 93 | assertThat(file).exists(); |
84 | 94 | String absolutePath = file.getAbsolutePath().replace('\\', '/'); |
85 | 95 | assertThat(absolutePath).endsWith(fileName); |
86 | 96 | } |
87 | 97 |
|
88 | 98 | @Test |
89 | | - public void testUnqualifiedFileNameNotFound() { |
| 99 | + void testUnqualifiedFileNameNotFound() { |
90 | 100 | PropertyEditor fileEditor = new FileEditor(); |
91 | 101 | String fileName = ClassUtils.classPackageAsResourcePath(getClass()) + "/" + |
92 | 102 | ClassUtils.getShortName(getClass()) + ".clazz"; |
93 | 103 | fileEditor.setAsText(fileName); |
94 | 104 | Object value = fileEditor.getValue(); |
95 | | - assertThat(value instanceof File).isTrue(); |
| 105 | + assertThat(value).isInstanceOf(File.class); |
96 | 106 | File file = (File) value; |
97 | 107 | assertThat(file).doesNotExist(); |
98 | 108 | String absolutePath = file.getAbsolutePath().replace('\\', '/'); |
|
0 commit comments