Rename methods to be more accurate

pull/2/head
Hammy 3 years ago
parent 71a3720ff5
commit 3735ad5839

@ -88,7 +88,7 @@ class ClipboardUtils {
* @param contents The {@link Transferable} which holds the clipboard contents * @param contents The {@link Transferable} which holds the clipboard contents
* @return {@link GenericClipboardContent} containing clipboard contents * @return {@link GenericClipboardContent} containing clipboard contents
*/ */
GenericClipboardContent<?> getClipboardContents(Transferable contents) { GenericClipboardContent<?> getGenericClipboardContents(Transferable contents) {
GenericClipboardContent<?> genericClipboardContent = null; GenericClipboardContent<?> genericClipboardContent = null;
try { try {
@ -113,7 +113,7 @@ class ClipboardUtils {
* @param oldContents The given {@link Transferable} which holds the clipboard contents * @param oldContents The given {@link Transferable} which holds the clipboard contents
* @return {@link ClipboardContent} containing old clipboard contents * @return {@link ClipboardContent} containing old clipboard contents
*/ */
ClipboardContent getOldClipboardContent(Transferable oldContents) { ClipboardContent getClipboardContent(Transferable oldContents) {
ClipboardContent clipboardContent = null; ClipboardContent clipboardContent = null;
try { try {
@ -137,7 +137,7 @@ class ClipboardUtils {
* @param object The given {@link Object} which holds the clipboard contents * @param object The given {@link Object} which holds the clipboard contents
* @return {@link ClipboardContent} containing old clipboard contents * @return {@link ClipboardContent} containing old clipboard contents
*/ */
ClipboardContent getOldClipboardContent(Object object) { ClipboardContent getClipboardContent(Object object) {
ClipboardContent clipboardContent = null; ClipboardContent clipboardContent = null;
if (object instanceof String) { if (object instanceof String) {

@ -45,7 +45,7 @@ class MacClipboard extends SystemClipboard implements Runnable {
if (isTextMonitored()) { if (isTextMonitored()) {
Object oldContent = genericClipboardContents[0].getOldContent(); Object oldContent = genericClipboardContents[0].getOldContent();
if (!newStringContent.equals(oldContent)) { if (!newStringContent.equals(oldContent)) {
ClipboardContent clipboardContent = clipboardUtils.getOldClipboardContent(oldContent); ClipboardContent clipboardContent = clipboardUtils.getClipboardContent(oldContent);
eventManager.notifyTextEvent(clipboardContent, newStringContent); eventManager.notifyTextEvent(clipboardContent, newStringContent);
} }
} }
@ -67,7 +67,7 @@ class MacClipboard extends SystemClipboard implements Runnable {
if (isImageMonitored()) { if (isImageMonitored()) {
if (!bufferedImageContent.equals(genericClipboardContents[0].getOldContent())) { if (!bufferedImageContent.equals(genericClipboardContents[0].getOldContent())) {
ClipboardContent clipboardContent = clipboardUtils.getOldClipboardContent(genericClipboardContents[0].getOldContent()); ClipboardContent clipboardContent = clipboardUtils.getClipboardContent(genericClipboardContents[0].getOldContent());
eventManager.notifyImageEvent(clipboardContent, bufferedImageContent.getBufferedImage()); eventManager.notifyImageEvent(clipboardContent, bufferedImageContent.getBufferedImage());
} }
} }
@ -90,7 +90,7 @@ class MacClipboard extends SystemClipboard implements Runnable {
if (isFileMonitored()) { if (isFileMonitored()) {
if (!fileListContent.equals(genericClipboardContents[0].getOldContent())) { if (!fileListContent.equals(genericClipboardContents[0].getOldContent())) {
ClipboardContent clipboardContent = clipboardUtils.getOldClipboardContent(genericClipboardContents[0].getOldContent()); ClipboardContent clipboardContent = clipboardUtils.getClipboardContent(genericClipboardContents[0].getOldContent());
eventManager.notifyFilesEvent(clipboardContent, fileListContent); eventManager.notifyFilesEvent(clipboardContent, fileListContent);
} }
} }
@ -190,7 +190,7 @@ class MacClipboard extends SystemClipboard implements Runnable {
@Override @Override
void execute() { void execute() {
Transferable oldClipboardContents = clipboard.getContents(null); Transferable oldClipboardContents = clipboard.getContents(null);
genericClipboardContents = new GenericClipboardContent[] { clipboardUtils.getClipboardContents(oldClipboardContents) }; genericClipboardContents = new GenericClipboardContent[] { clipboardUtils.getGenericClipboardContents(oldClipboardContents) };
scheduledExecutorService.scheduleAtFixedRate(this, 0, 200, TimeUnit.MILLISECONDS); scheduledExecutorService.scheduleAtFixedRate(this, 0, 200, TimeUnit.MILLISECONDS);
} }
} }

@ -118,7 +118,7 @@ abstract class SystemClipboard {
*/ */
ClipboardContent getContents() { ClipboardContent getContents() {
Transferable clipboardContents = clipboard.getContents(null); Transferable clipboardContents = clipboard.getContents(null);
return clipboardContents == null ? null : clipboardUtils.getOldClipboardContent(clipboardContents); return clipboardContents == null ? null : clipboardUtils.getClipboardContent(clipboardContents);
} }
/** /**

@ -51,7 +51,7 @@ class WindowsOrUnixClipboard extends SystemClipboard implements Runnable, Clipbo
* @param newClipboardContents The new contents of the clipboard * @param newClipboardContents The new contents of the clipboard
*/ */
void processContents(Clipboard oldClipboard, Transferable oldClipboardContents, Transferable newClipboardContents) { void processContents(Clipboard oldClipboard, Transferable oldClipboardContents, Transferable newClipboardContents) {
ClipboardContent clipboardContent = clipboardUtils.getOldClipboardContent(oldClipboardContents); ClipboardContent clipboardContent = clipboardUtils.getClipboardContent(oldClipboardContents);
if (isTextMonitored()) { if (isTextMonitored()) {
if (TEXT.isAvailable(oldClipboard) && !FILE.isAvailable(oldClipboard)) { if (TEXT.isAvailable(oldClipboard) && !FILE.isAvailable(oldClipboard)) {

@ -130,12 +130,12 @@ class ClipboardUtilsTest {
} }
@ParameterizedTest @ParameterizedTest
@MethodSource("provideArgumentsForRetrievingClipboardContents") @MethodSource("provideArgumentsForRetrievingGenericClipboardContents")
void successfullyRetrieveOldClipboardContents(GenericClipboardContent<?> expectedGenericClipboardContent, Object expectedContent, DataFlavor dataFlavor) throws IOException, UnsupportedFlavorException { void successfullyRetrieveOldClipboardContents(GenericClipboardContent<?> expectedGenericClipboardContent, Object expectedContent, DataFlavor dataFlavor) throws IOException, UnsupportedFlavorException {
when(transferableMock.isDataFlavorSupported(dataFlavor)).thenReturn(true); when(transferableMock.isDataFlavorSupported(dataFlavor)).thenReturn(true);
when(transferableMock.getTransferData(dataFlavor)).thenReturn(expectedContent); when(transferableMock.getTransferData(dataFlavor)).thenReturn(expectedContent);
GenericClipboardContent<?> actualGenericClipboardContent = sut.getClipboardContents(transferableMock); GenericClipboardContent<?> actualGenericClipboardContent = sut.getGenericClipboardContents(transferableMock);
assertThat(actualGenericClipboardContent.getOldContent(), is(expectedGenericClipboardContent.getOldContent())); assertThat(actualGenericClipboardContent.getOldContent(), is(expectedGenericClipboardContent.getOldContent()));
verifyNoInteractions(logger); verifyNoInteractions(logger);
@ -147,7 +147,7 @@ class ClipboardUtilsTest {
when(transferableMock.isDataFlavorSupported(dataFlavor)).thenReturn(true); when(transferableMock.isDataFlavorSupported(dataFlavor)).thenReturn(true);
when(transferableMock.getTransferData(dataFlavor)).thenReturn(expectedContent); when(transferableMock.getTransferData(dataFlavor)).thenReturn(expectedContent);
ClipboardContent actualClipboardContent = sut.getOldClipboardContent(transferableMock); ClipboardContent actualClipboardContent = sut.getClipboardContent(transferableMock);
assertThat(actualClipboardContent.getText(), is(expectedString)); assertThat(actualClipboardContent.getText(), is(expectedString));
assertThat(actualClipboardContent.getFiles(), is(expectedFiles)); assertThat(actualClipboardContent.getFiles(), is(expectedFiles));
@ -158,7 +158,7 @@ class ClipboardUtilsTest {
@ParameterizedTest @ParameterizedTest
@MethodSource("provideArgumentsForOldClipboardContents") @MethodSource("provideArgumentsForOldClipboardContents")
void successfullyMarshallClipboardContentsIntoOldClipboardContent(Object expectedOldContent, String expectedString, BufferedImage expectedImage, List<File> expectedFiles) { void successfullyMarshallClipboardContentsIntoOldClipboardContent(Object expectedOldContent, String expectedString, BufferedImage expectedImage, List<File> expectedFiles) {
ClipboardContent actualClipboardContent = sut.getOldClipboardContent(expectedOldContent); ClipboardContent actualClipboardContent = sut.getClipboardContent(expectedOldContent);
assertThat(actualClipboardContent.getText(), is(expectedString)); assertThat(actualClipboardContent.getText(), is(expectedString));
assertThat(actualClipboardContent.getImage(), is(expectedImage)); assertThat(actualClipboardContent.getImage(), is(expectedImage));
@ -192,7 +192,7 @@ class ClipboardUtilsTest {
} }
static Stream<Arguments> provideArgumentsForRetrievingClipboardContents() { static Stream<Arguments> provideArgumentsForRetrievingGenericClipboardContents() {
String string = "testString"; String string = "testString";
BufferedImage bufferedImage = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB); BufferedImage bufferedImage = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
MyBufferedImage myBufferedImage = new MyBufferedImage(bufferedImage); MyBufferedImage myBufferedImage = new MyBufferedImage(bufferedImage);

Loading…
Cancel
Save