Skip to content

Commit

Permalink
fix LOGBACK-1445
Browse files Browse the repository at this point in the history
Signed-off-by: Ceki Gulcu <ceki@qos.ch>
  • Loading branch information
ceki committed May 10, 2024
1 parent f8e4e78 commit 979d76f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public void addBasicProperty(String name, String strValue) {
return;
}
if (arg != null) {
invokeMethodWithSingleParameterOnThisObject(adderMethod, strValue);
invokeMethodWithSingleParameterOnThisObject(adderMethod, arg);
}
}

Expand Down
16 changes: 16 additions & 0 deletions logback-core/src/main/java/ch/qos/logback/core/util/FileSize.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
package ch.qos.logback.core.util;

import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -101,4 +102,19 @@ public String toString() {
return inGB + " GB";

}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
FileSize fileSize = (FileSize) o;
return size == fileSize.size;
}

@Override
public int hashCode() {
return Objects.hashCode(size);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class House {
List<String> adjectiveList = new ArrayList<String>();
List<Window> windowList = new ArrayList<Window>();
List<SwimmingPool> largePoolList = new ArrayList<SwimmingPool>();
List<FileSize> fileSizes = new ArrayList();

Orange orange;

Expand Down Expand Up @@ -109,6 +110,10 @@ public void addWindow(Window w) {
windowList.add(w);
}

public void addFileSize(FileSize fs) {
fileSizes.add(fs);
}

public void addAdjective(String s) {
adjectiveList.add(s);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.nio.charset.Charset;
import java.nio.charset.UnsupportedCharsetException;

import ch.qos.logback.core.util.FileSize;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -134,6 +135,16 @@ public void testPropertyCollection() {
}

@Test
public void addValueOfTest() {
setter.addBasicProperty("fileSize", "1GB");
setter.addBasicProperty("fileSize", "10KB");

assertEquals(2, house.fileSizes.size());
assertEquals(FileSize.valueOf("1GB"), house.fileSizes.get(0));
assertEquals(FileSize.valueOf("10KB"), house.fileSizes.get(1));
}

@Test
public void testComplexCollection() {
Window w1 = new Window();
w1.handle = 10;
Expand Down

0 comments on commit 979d76f

Please sign in to comment.