FileResource.java

1
package fr.sii.ogham.core.resource;
2
3
import java.io.File;
4
import java.io.FileInputStream;
5
import java.io.IOException;
6
import java.io.InputStream;
7
8
import fr.sii.ogham.core.util.EqualsBuilder;
9
import fr.sii.ogham.core.util.HashCodeBuilder;
10
11
/**
12
 * Resource that provide access to a file.
13
 * 
14
 * @author Aurélien Baudet
15
 *
16
 */
17
public class FileResource implements NamedResource {
18
	/**
19
	 * The file to attach
20
	 */
21
	private File file;
22
23
	/**
24
	 * The name for the attachment
25
	 */
26
	private String name;
27
28
	/**
29
	 * Initialize the resource with the provided file and name. The file is the
30
	 * content of the resource. Use the provided name for the resource name
31
	 * instead of the name of the file.
32
	 * 
33
	 * @param file
34
	 *            the content of the resource
35
	 * @param name
36
	 *            the name for the resource
37
	 */
38
	public FileResource(File file, String name) {
39
		super();
40
		this.file = file;
41
		this.name = name;
42
	}
43
44
	/**
45
	 * Initialize the resource with the provided file. The file is the content
46
	 * of the resource. Use the name of the file for the name of the resource.
47
	 * 
48
	 * @param file
49
	 *            the content of the resource
50
	 */
51
	public FileResource(File file) {
52
		this(file, file.getName());
53
	}
54
55
	/**
56
	 * Initialize the resource with the provided file. The file is the content
57
	 * of the resource. Use the name of the file for the name of the resource.
58
	 * 
59
	 * @param fileName
60
	 *            the content of the resource
61
	 */
62
	public FileResource(String fileName) {
63
		this(new File(fileName));
64
	}
65
66
	@Override
67
	public InputStream getInputStream() throws IOException {
68 1 1. getInputStream : replaced return value with null for fr/sii/ogham/core/resource/FileResource::getInputStream → NO_COVERAGE
		return new FileInputStream(file);
69
	}
70
71
	public File getFile() {
72 1 1. getFile : replaced return value with null for fr/sii/ogham/core/resource/FileResource::getFile → RUN_ERROR
		return file;
73
	}
74
75
	public String getName() {
76 1 1. getName : replaced return value with "" for fr/sii/ogham/core/resource/FileResource::getName → RUN_ERROR
		return name;
77
	}
78
79
	@Override
80
	public int hashCode() {
81 1 1. hashCode : replaced int return with 0 for fr/sii/ogham/core/resource/FileResource::hashCode → RUN_ERROR
		return new HashCodeBuilder().append(name, file).hashCode();
82
	}
83
84
	@Override
85
	public boolean equals(Object obj) {
86 2 1. equals : replaced boolean return with false for fr/sii/ogham/core/resource/FileResource::equals → RUN_ERROR
2. equals : replaced boolean return with true for fr/sii/ogham/core/resource/FileResource::equals → RUN_ERROR
		return new EqualsBuilder(this, obj).appendFields("name", "file").isEqual();
87
	}
88
}

Mutations

68

1.1
Location : getInputStream
Killed by :
replaced return value with null for fr/sii/ogham/core/resource/FileResource::getInputStream → NO_COVERAGE

72

1.1
Location : getFile
Killed by :
replaced return value with null for fr/sii/ogham/core/resource/FileResource::getFile → RUN_ERROR

76

1.1
Location : getName
Killed by :
replaced return value with "" for fr/sii/ogham/core/resource/FileResource::getName → RUN_ERROR

81

1.1
Location : hashCode
Killed by :
replaced int return with 0 for fr/sii/ogham/core/resource/FileResource::hashCode → RUN_ERROR

86

1.1
Location : equals
Killed by :
replaced boolean return with false for fr/sii/ogham/core/resource/FileResource::equals → RUN_ERROR

2.2
Location : equals
Killed by :
replaced boolean return with true for fr/sii/ogham/core/resource/FileResource::equals → RUN_ERROR

Active mutators

Tests examined


Report generated by PIT 1.13.1