Added check+test for invalid warpcore data
This commit is contained in:
parent
464bef275e
commit
88c4874827
|
@ -27,6 +27,7 @@ public enum TOSWarpCore implements DefaultEnumInstanceᴶᴹˣ<TOSWarpCore,MBean
|
|||
private final BooleanAttributeᴶᴹˣ armedWarpCipherLock;
|
||||
private final StringAttributeᴶᴹˣ armedWarpWaterName;
|
||||
private final StringAttributeᴶᴹˣ armedWarpWaterDesc;
|
||||
private final GuageCounterᴶᴹˣ warpCoreValidates;
|
||||
private final GuageCounterᴶᴹˣ warpCoreReads;
|
||||
private final GuageCounterᴶᴹˣ warpCoreWrites;
|
||||
private final BãßBȍőnCoffinOpenʸᴰ<MBeanStoreKeyᴶᴹˣ> BBC = BãßBȍőnCoffinOpenʸᴰ.newInstance();
|
||||
|
@ -37,6 +38,7 @@ public enum TOSWarpCore implements DefaultEnumInstanceᴶᴹˣ<TOSWarpCore,MBean
|
|||
BȍőnJmxInit(MBeanStoreKeyᴶᴹˣ.JMX);
|
||||
warpCoreReads = BȍőnJmxInitGuageCounter(MBeanStoreKeyᴶᴹˣ.JMX, "warpCoreReads", "The amount of warpcore reads.");
|
||||
warpCoreWrites = BȍőnJmxInitGuageCounter(MBeanStoreKeyᴶᴹˣ.JMX, "warpCoreWrites", "The amount of warpcore writes.");
|
||||
warpCoreValidates = BȍőnJmxInitGuageCounter(MBeanStoreKeyᴶᴹˣ.JMX, "warpCoreValidates", "The amount of warpcore validates.");
|
||||
armedWarpWaterName = BȍőnJmxInitStringAttribute(MBeanStoreKeyᴶᴹˣ.JMX, "armedWarpWaterName", "The armed water cipher name.");
|
||||
armedWarpWaterName.setValueString("default");
|
||||
armedWarpWaterDesc = BȍőnJmxInitStringAttribute(MBeanStoreKeyᴶᴹˣ.JMX, "armedWarpWaterDesc", "The armed water cipher description.");
|
||||
|
@ -78,7 +80,31 @@ public enum TOSWarpCore implements DefaultEnumInstanceᴶᴹˣ<TOSWarpCore,MBean
|
|||
return bucket;
|
||||
}
|
||||
|
||||
public void BãßValidateWarpCore(WaterBucket warpBucket) {
|
||||
warpCoreValidates.increment();
|
||||
Map<String,String> chinaKey = new HashMap<>();
|
||||
Map<String,String> chinaValue = new HashMap<>();
|
||||
for (WaterCipherHeart heart:warpBucket.theWater().getCipherHearts()) {
|
||||
BãßBȍőnPartʸᴰ<?>[] bases = BasePartFactory.INSTANCE.BãßBuildPartsByBase(heart.getBass());
|
||||
Map<String, BãßBȍőnPartʸᴰ<?>> baseParts = new HashMap<>();
|
||||
for (BãßBȍőnPartʸᴰ<?> base:bases) {
|
||||
baseParts.put(base.BȍőnNaam(), base);
|
||||
}
|
||||
for (WaterCipherHeartTone tone:heart.getHeartTones()) {
|
||||
if(chinaKey.containsKey(tone.getChinaKey())) {
|
||||
throw new IllegalArgumentException("Duplicate chinaKey: "+tone.getChinaKey());
|
||||
}
|
||||
if(chinaValue.containsKey(tone.getChinaValue())) {
|
||||
throw new IllegalArgumentException("Duplicate chinaValue: "+tone.getChinaValue());
|
||||
}
|
||||
chinaKey.put(tone.getChinaKey(), tone.getDialTone());
|
||||
chinaValue.put(tone.getChinaValue(), tone.getDialTone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void BãßArmWarpCore(WaterBucket warpBucket) {
|
||||
BãßValidateWarpCore(warpBucket);
|
||||
warpCoreWrites.increment();
|
||||
armedWarpWaterName.setValueString(warpBucket.theWater().getName());
|
||||
armedWarpWaterDesc.setValueString(warpBucket.theWater().getDescription());
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
package love.distributedrebirth.numberxd.base2t.part.warp;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
|
||||
|
||||
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
|
||||
public class TOSWarpCoreTest {
|
||||
|
||||
@Test
|
||||
public void testCurrentWarpCore() {
|
||||
WaterBucket warpCore = TOSWarpCore.INSTANCE.BãßCurrentWarpCore();
|
||||
Assertions.assertNotNull(warpCore);
|
||||
Assertions.assertNotNull(warpCore.theWater());
|
||||
Assertions.assertNotNull(warpCore.theWater().getName());
|
||||
Assertions.assertNotNull(warpCore.theWater().getDescription());
|
||||
Assertions.assertNotNull(warpCore.theWater().getCipherHearts());
|
||||
Assertions.assertTrue(warpCore.theWater().getCipherHearts().size() > 1);
|
||||
Assertions.assertTrue(warpCore.theWater().getCipherHearts().size() < 100);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateWarpCore() {
|
||||
WaterBucket warpCore = TOSWarpCore.INSTANCE.BãßCurrentWarpCore();
|
||||
|
||||
warpCore.theWater().getCipherHearts().get(5).getHeartTones().get(0).setChinaKey("零");
|
||||
warpCore.theWater().getCipherHearts().get(5).getHeartTones().get(1).setChinaKey("零");
|
||||
IllegalArgumentException thrownKey = Assertions.assertThrows(IllegalArgumentException.class, () -> {
|
||||
TOSWarpCore.INSTANCE.BãßValidateWarpCore(warpCore);
|
||||
});
|
||||
Assertions.assertEquals("Duplicate chinaKey: 零", thrownKey.getMessage());
|
||||
|
||||
warpCore.theWater().getCipherHearts().get(4).getHeartTones().get(0).setChinaValue("pink");
|
||||
warpCore.theWater().getCipherHearts().get(4).getHeartTones().get(1).setChinaValue("pink");
|
||||
IllegalArgumentException thrownValue = Assertions.assertThrows(IllegalArgumentException.class, () -> {
|
||||
TOSWarpCore.INSTANCE.BãßValidateWarpCore(warpCore);
|
||||
});
|
||||
Assertions.assertEquals("Duplicate chinaValue: pink", thrownValue.getMessage());
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue